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.13k stars 532 forks source link

go 1.21.1 errors parsing go.mod #984

Closed Septrum101 closed 9 months ago

Septrum101 commented 9 months ago

Contributing guidelines

I've found a bug, and:

Description

When I user go 1.21.1, this actions will failure

Expected behaviour

success Build and push by digest

Actual behaviour

#14 [builder 4/5] RUN go mod download
#14 0.326 go: errors parsing go.mod:
#14 0.326 /app/go.mod:5: unknown directive: toolchain
#14 ERROR: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1
------
 > [builder 4/5] RUN go mod download:
0.326 go: errors parsing go.mod:
0.326 /app/go.mod:5: unknown directive: toolchain
------
Dockerfile:6
--------------------
   4 |     COPY . .
   5 |     ENV CGO_ENABLED=0
   6 | >>> RUN go mod download
   7 |     RUN go build -v -o XrayR -trimpath -ldflags "-s -w -buildid=" ./main
   8 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1
Error: buildx failed with: ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1

Repository URL

https://github.com/XrayR-project/XrayR

Workflow run URL

https://github.com/XrayR-project/XrayR/actions

YAML workflow

name: Publish Docker image
on:
  workflow_dispatch:
  push:
    branches:
      - master
    paths:
      - "**/*.go"
      - "go.mod"
      - "go.sum"
      - ".github/workflows/*.yml"
    tags:
      - 'v*'
  pull_request:
    branches:
      - 'master'
env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        platform:
          - linux/amd64
          - linux/arm/v6
          - linux/arm/v7
          - linux/arm64
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push by digest
        id: build
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: ${{ matrix.platform }}
          labels: ${{ steps.meta.outputs.labels }}
          outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
      - name: Export digest
        run: |
          mkdir -p /tmp/digests
          digest="${{ steps.build.outputs.digest }}"
          touch "/tmp/digests/${digest#sha256:}"          
      - name: Upload digest
        uses: actions/upload-artifact@v3
        with:
          name: digests
          path: /tmp/digests/*
          if-no-files-found: error
          retention-days: 1

  merge:
    runs-on: ubuntu-latest
    needs:
      - build
    steps:
      - name: Download digests
        uses: actions/download-artifact@v3
        with:
          name: digests
          path: /tmp/digests
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Create manifest list and push
        working-directory: /tmp/digests
        run: |
          docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
            $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)          
      - name: Inspect image
        run: |
          docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}

Workflow logs


#14 [builder 4/5] RUN go mod download
#14 0.326 go: errors parsing go.mod:
#14 0.326 /app/go.mod:5: unknown directive: toolchain
#14 ERROR: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1
------
 > [builder 4/5] RUN go mod download:
0.326 go: errors parsing go.mod:
0.326 /app/go.mod:5: unknown directive: toolchain
------
Dockerfile:6
--------------------
   4 |     COPY . .
   5 |     ENV CGO_ENABLED=0
   6 | >>> RUN go mod download
   7 |     RUN go build -v -o XrayR -trimpath -ldflags "-s -w -buildid=" ./main
   8 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1
Error: buildx failed with: ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1

### BuildKit logs

_No response_

### Additional info

_No response_
Septrum101 commented 9 months ago

This problem comes from buildkit. Need https://github.com/moby/buildkit to update.

crazy-max commented 9 months ago

This problem comes from buildkit. Need https://github.com/moby/buildkit to update.

Why do you think this is a buildkit issue?

unknown directive: toolchain

This looks related to https://github.com/golang/go/issues/62409 and looking at your go.mod: https://github.com/XrayR-project/XrayR/blob/682af90252d1a9c866ece1096698ac693412695b/go.mod#L3 and Dockerfile: https://github.com/XrayR-project/XrayR/blob/682af90252d1a9c866ece1096698ac693412695b/Dockerfile#L2 you need to update to Go 1.21.

Septrum101 commented 9 months ago

This problem comes from buildkit. Need https://github.com/moby/buildkit to update.

Why do you think this is a buildkit issue?

unknown directive: toolchain

This looks related to https://github.com/golang/go/issues/62409 and looking at your go.mod: https://github.com/XrayR-project/XrayR/blob/682af90252d1a9c866ece1096698ac693412695b/go.mod#L3 and Dockerfile: https://github.com/XrayR-project/XrayR/blob/682af90252d1a9c866ece1096698ac693412695b/Dockerfile#L2 you need to update to Go 1.21.

Its awesome, Thank you very much.