diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a7a23586..76687cb2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,57 +1,98 @@ -name: Release +name: Docker on: - release: - types: [published] + push: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} -jobs: +jobs: build: - name: Build release binaries runs-on: ubuntu-latest + strategy: + matrix: + arch: ["arm64", "amd64"] steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.13 - id: go - - - name: Build AMD64 - run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -installsuffix nocgo -v -o traefik-forward-auth_amd64 ./cmd - - - name: Build ARM - run: CGO_ENABLED=0 GOOS=linux GOARCH=arm GO111MODULE=on go build -a -installsuffix nocgo -v -o traefik-forward-auth_arm ./cmd - - - name: Get tag name - run: echo "TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - - name: Get artifact details - uses: octokit/request-action@v2.x - id: get_release_details - with: - route: get /repos/${{ github.repository }}/releases/tags/${{ env.TAG }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Upload AMD64 release asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ fromJson(steps.get_release_details.outputs.data).upload_url }} - asset_path: traefik-forward-auth_amd64 - asset_name: traefik-forward-auth_amd64 - asset_content_type: application/octet-stream - - - name: Upload ARM release asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ fromJson(steps.get_release_details.outputs.data).upload_url }} - asset_path: traefik-forward-auth_arm - asset_name: traefik-forward-auth_arm - asset_content_type: application/octet-stream + - name: Checkout repository + uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache-dependency-path: "**/*.sum" + - name: Build Service + env: + CGO_ENABLED: 0 + GOOS: linux + GOARCH: ${{ matrix.arch }} + GO111MODULE: on + run: go build -a -installsuffix nocgo -o main/traefik-forward-auth cmd/main.go + - uses: actions/upload-artifact@v4 + with: + # Name of the artifact to upload. + # Optional. Default is 'artifact' + name: binary-${{ matrix.arch }} + + # A file, directory or wildcard pattern that describes what to upload + # Required. + path: main + deploy: + runs-on: ubuntu-latest + needs: build + if: ${{ github.event_name != 'pull_request' }} + permissions: + contents: read + packages: write + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: binary-amd64 + path: amd64 + - uses: actions/download-artifact@v4 + with: + name: binary-arm64 + path: arm64 + - name: Install cosign + uses: sigstore/cosign-installer@v3 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + - uses: docker/setup-qemu-action@v3 + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: latest=auto + tags: | + # set latest tag for releases + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} + # branch + type=ref,event=branch + # SHA + type=sha + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/arm64, linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Sign the published Docker image + env: + COSIGN_EXPERIMENTAL: "true" + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }} -y diff --git a/Dockerfile b/Dockerfile index 80fe861c..3917a74a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,10 @@ -FROM golang:1.20-alpine as builder +FROM alpine AS certs -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth - -# Add libraries -RUN apk add --no-cache git - -# Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd +RUN apk add ca-certificates # Copy into scratch container -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ +FROM --platform=$TARGETOS/$TARGETARCH alpine +ARG TARGETARCH +COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --chmod=755 $TARGETARCH/traefik-forward-auth ./ ENTRYPOINT ["./traefik-forward-auth"] diff --git a/Dockerfile.arm b/Dockerfile.arm deleted file mode 100644 index e10021e6..00000000 --- a/Dockerfile.arm +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.13-alpine as builder - -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth - -# Add libraries -RUN apk add --no-cache git - -# Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd - -# Copy into scratch container -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ -ENTRYPOINT ["./traefik-forward-auth"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index a9806863..00000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.13-alpine as builder - -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth - -# Add libraries -RUN apk add --no-cache git - -# Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd - -# Copy into scratch container -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ -ENTRYPOINT ["./traefik-forward-auth"]