Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new release CI #396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 91 additions & 50 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
20 changes: 6 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
18 changes: 0 additions & 18 deletions Dockerfile.arm

This file was deleted.

18 changes: 0 additions & 18 deletions Dockerfile.arm64

This file was deleted.