docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.42k stars 562 forks source link

Error: Invalid character at v6.6.0. #1204

Closed tsukaby closed 3 months ago

tsukaby commented 3 months ago

Contributing guidelines

I've found a bug, and:

Description

Version 6.6.0 is probably broken. Since this version was released I have observed an error in GitHub Action.

It seems to be pushed to my docker repository(AWS ECR), so the build and push are successful, but it is an error for my workflow.

Run docker/setup-buildx-action@v3

Booting builder
  /usr/bin/docker buildx inspect --bootstrap --builder builder-8b7d88ad-78c7-4a77-a3ed-8aa5b647861a
  #1 [internal] booting buildkit
  #1 pulling image moby/buildkit:buildx-stable-1
  #1 pulling image moby/buildkit:buildx-stable-1 0.7s done
  #1 creating container buildx_buildkit_builder-8b7d88ad-78c7-4a77-a3ed-8aa5b647861a0
  #1 creating container buildx_buildkit_builder-8b7d88ad-78c7-4a77-a3ed-8aa5b647861a0 30.9s done
  #1 DONE 31.6s
  Name:          builder-8b7d88ad-78c7-4a77-a3ed-8aa5b647861a
  Driver:        docker-container
  Last Activity: 2024-08-07 12:13:30 +0000 UTC

  Nodes:
  Name:     builder-8b7d88ad-78c7-4a77-a3ed-8aa5b647861a0
  Endpoint: unix:///var/run/docker.sock
  Error:    Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.46/containers/buildx_buildkit_builder-8b7d88ad-78c7-4a77-a3ed-8aa5b647861a0/json": context deadline exceeded

Run docker/build-push-action@v6


Error: Invalid character

Expected behaviour

Successful build and push without an error.

Actual behaviour

Build and push failed.

Repository URL

No response

Workflow run URL

No response

YAML workflow

- name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v3

    - name: Set Docker tags
      uses: docker/metadata-action@v5
      id: meta
      with:
        images: |
          ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY_WEB }}
        tags: |
          type=sha,prefix=

    - uses: docker/build-push-action@v6
      with:
        context: .
        file: docker/rails/Dockerfile
        push: true
        tags: ${{ steps.meta.outputs.tags }}
        cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY_WEB }}:cache,scope=${{ github.ref }}-web
        cache-to: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY_WEB }}:cache,mode=max,image-manifest=true,oci-mediatypes=true,scope=${{ github.ref }}-web

Workflow logs

No response

BuildKit logs

No response

Additional info

No response

crazy-max commented 3 months ago

Thanks for reporting, can you re-run failed job in debug and give full logs or a link to your repo please? That would help figure out your issue. Thanks

crazy-max commented 3 months ago

If someone else can give a link to his repo with this issue please do! thanks!

sushichan044 commented 3 months ago

I have same issue in my workflow. https://github.com/VirtualLiveLab/Mikubot/actions/runs/10283711021

crazy-max commented 3 months ago

I have same issue in my workflow. https://github.com/VirtualLiveLab/Mikubot/actions/runs/10283711021

Thanks I'm taking a look.

crazy-max commented 3 months ago

I have same issue in my workflow. https://github.com/VirtualLiveLab/Mikubot/actions/runs/10283711021

Wonder if this linked to this special char in https://github.com/VirtualLiveLab/Mikubot/blob/4a9b43a46f0a20358a504eb14d2781130022c68d/Dockerfile#L12

FROM python:3.11-bookworm as builder

WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONUSERBASE=/app/__pypackages__

COPY requirements.lock ./
RUN pip install --user --no-cache-dir -r requirements.lock

# https://github.com/GoogleContainerTools/distroless/blob/main/python3/BUILD
# distroless/python3-debian12のPythonは3.11
FROM gcr.io/distroless/python3-debian12:nonroot as runner
WORKDIR /app
ENV PYTHONUSERBASE=/app/__pypackages__

USER nonroot
COPY --from=builder /app/__pypackages__ /app/__pypackages__
COPY --chown=nonroot:nonroot . ./

CMD ["main.py"]

Edit: Ok that's it, was able to repro:

InvalidCharacterError: Invalid character
    at btoa (node:buffer:1255:11)
Rycieos commented 3 months ago

This can also happen if the file contains a byte order mark:

$ file Dockerfile
Dockerfile: Unicode text, UTF-8 (with BOM) text
$ head -n1 Dockerfile | hexdump -C
00000000  ef bb bf 46 52 4f 4d 20  2d 2d 70 6c 61 74 66 6f  |...FROM --platfo|
...

The job logs showed:

...
#40 writing config sha256:8007b27a324fdb90c5c2101b7448ed667ba201138fce281f776fe4d3b9cadd33
#40 preparing build cache for export 47.2s done
#40 writing config sha256:8007b27a324fdb90c5c2101b7448ed667ba201138fce281f776fe4d3b9cadd33 done
#40 writing cache manifest sha256:51dbba7a93f69fa3d5762c5c8adb7ec9248de6f5fde6c4ded4187e1ef5772 done
#40 DONE 47.2s

#41 resolving provenance for metadata file
#41 DONE 0.0s

ImageID
Digest
Metadata
Reference
Error: Invalid character

So both the build and the push were successful, as well as the write to cache. It failed after everything except the job summary write finished.

Removing the BOM fixed it:

$ file Dockerfile
Dockerfile: ASCII text
$ head -n1 Dockerfile | hexdump -C
00000000  46 52 4f 4d 20 2d 2d 70  6c 61 74 66 6f 72 6d 3d  |FROM --platform=|
...
crazy-max commented 3 months ago

Should be fixed with latest patch release: https://github.com/docker/build-push-action/releases/tag/v6.6.1

Rycieos commented 3 months ago

Should be fixed with latest patch release

Can confirm my BOM file no longer crashes on build. Thanks!

tsukaby commented 3 months ago

I used version 6.6.1 and it worked fine.

Thank you!