From bf982d070704478007059f55f003fafa1145c759 Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz <45375059+ngehrsitz@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:15:16 +0100 Subject: [PATCH 1/6] Support running on forks --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 23b9ed602..0f4bd4075 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,8 +36,8 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: | - ghcr.io/swaggo/swag:latest - ghcr.io/swaggo/swag:${{github.ref_name}} + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{github.ref_name}} labels: ${{ steps.meta.outputs.labels }} - name: Image digest From 911a03ca98a82e455d7d72e338a38ba9212528e0 Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz <45375059+ngehrsitz@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:33:48 +0100 Subject: [PATCH 2/6] Fix ARG format --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index dc7c4c621..784cd0c92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,8 @@ RUN go mod download COPY . . # Configure go compiler target platform -ARG TARGETARCH TARGETOS +ARG TARGETOS +ARG TARGETARCH ENV GOARCH=$TARGETARCH \ GOOS=$TARGETOS From f2a8c015434bb14b55d6d5be8da59c4f1a53ea8c Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz <45375059+ngehrsitz@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:36:19 +0100 Subject: [PATCH 3/6] Fix docker digest step --- .github/workflows/docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0f4bd4075..85bc2d004 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,6 +30,7 @@ jobs: images: ghcr.io/swaggo/swag - name: Build image and push to GitHub Container Registry + id: docker_build uses: docker/build-push-action@v2 with: context: . From 01935b0db4a532b5b9526b7d96e689cc2c11ab3e Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz <45375059+ngehrsitz@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:15:45 +0100 Subject: [PATCH 4/6] Restrict permissions --- .github/workflows/docker.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 85bc2d004..b5f727b26 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,6 +5,10 @@ on: tags: - 'v*' +permissions: + contents: read + packages: write + jobs: docker-build: runs-on: ubuntu-latest From 0bdff7c1022f2e7f1dabf1e8c71ff54c619ee0bc Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz <45375059+ngehrsitz@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:18:06 +0100 Subject: [PATCH 5/6] Update action versions --- .github/workflows/docker.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b5f727b26..9be444b25 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,14 +14,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to Github Packages - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -29,13 +29,13 @@ jobs: - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: ghcr.io/swaggo/swag - name: Build image and push to GitHub Container Registry id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64 From ee1a5a2524f84b1fd26ee2db3e4ef039ed6a25fc Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz <45375059+ngehrsitz@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:29:58 +0100 Subject: [PATCH 6/6] Set $TARGETPLATFORM explicitly https://github.com/docker/build-push-action/issues/820#issuecomment-1486849546 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 784cd0c92..a9c2b2c6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o swag cmd/swag/ ######## Start a new stage from scratch ####### -FROM scratch +FROM --platform=$TARGETPLATFORM scratch WORKDIR /code/