Skip to content

Commit

Permalink
Merge pull request #1 from ngehrsitz/multi-arch
Browse files Browse the repository at this point in the history
Improve github action workflow for multi-arch docker images
  • Loading branch information
tnaroska committed Feb 9, 2024
2 parents d0d0233 + ee1a5a2 commit 37536f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,44 @@ on:
tags:
- 'v*'

permissions:
contents: read
packages: write

jobs:
docker-build:
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 }}
password: ${{ secrets.GITHUB_TOKEN }}

- 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
uses: docker/build-push-action@v2
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
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
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -25,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/

Expand Down

0 comments on commit 37536f0

Please sign in to comment.