Skip to content

Commit

Permalink
Added release flow tested in PR rancher#25. Only change is in trigger…
Browse files Browse the repository at this point in the history
… condition.
  • Loading branch information
andreas-kupries committed Apr 18, 2024
1 parent 4b4c920 commit 69d114a
Showing 1 changed file with 148 additions and 0 deletions.
148 changes: 148 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
## (5b) Pin to commits, not tags

name: CI Build And Publish Release

on:
release:
types:
- published

permissions:
contents: read

env:
IMAGE: rancher/kube-api-auth

jobs:
push:
permissions:
contents: read
id-token: write # this is important, it's how we authenticate with Vault
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Prepare Matrix Instance
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Retrieve Docker Hub Credentials From Vault
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKERHUB_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKERHUB_PASSWORD
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}

- name: Get Sources
uses: actions/checkout@v4

- name: Docker Meta Data Setup
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: false

- name: Build and stage
run: |
case "${{ matrix.platform }}" in
*/arm64) export ARCH=arm64 ; export GOARCH=arm64 ;;
*) export ARCH=amd64 ; export GOARCH=amd64 ;;
esac
./scripts/build
# Stage binary for packaging step
cp -r ./bin/* ./package/
- name: Build image and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: package
file: package/Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.IMAGE }},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@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
permissions:
contents: read
id-token: write # this is important, it's how we authenticate with Vault
runs-on: ubuntu-latest
needs:
- push
steps:
- name: Retrieve Docker Hub Credentials From Vault
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKERHUB_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKERHUB_PASSWORD
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}

- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}

- 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.IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.IMAGE }}:${{ steps.meta.outputs.version }}

0 comments on commit 69d114a

Please sign in to comment.