From 4d8d5ea71a75d8100ee10d870c2308fdc2bc4545 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sun, 3 Dec 2023 13:39:18 +0100 Subject: [PATCH] Tweak workflows --- .github/workflows/build.yml | 2 +- .github/workflows/build_docker.yml | 49 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea39dd1..360f50d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ on: jobs: build: name: Build - runs-on: self-hosted + runs-on: [self-hosted, ubuntu-latest] permissions: contents: read packages: write diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 5302b24..d293983 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -8,18 +8,22 @@ on: jobs: build-and-push-image: name: Docker Build - runs-on: self-hosted + runs-on: [self-hosted, ubuntu-latest] permissions: contents: read packages: write steps: - name: Set version - id: version - run: echo "::set-output name=version::$(echo ${GITHUB_REF#refs/tags/})" + id: buildvars + run: | + echo "version=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT + echo "built_at=$(date +%Y-%m-%dT%H:%M:%S)" >> $GITHUB_OUTPUT + echo "go_version=$(go version | cut -d ' ' -f 3)" >> $GITHUB_OUTPUT + echo "git_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - name: Check out the repo - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -39,55 +43,52 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + # private image - name: Extract metadata (tags, labels) for Docker + if: ${{ !startsWith(github.ref, 'refs/tags/v') }} id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} - - name: Generate build variables - id: prep - run: | - echo "built_at=$(date +%Y-%m-%dT%H:%M:%S)" >> $GITHUB_OUTPUT - echo "go_version=$(go version | cut -d ' ' -f 3)" >> $GITHUB_OUTPUT - echo "git_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - name: Build and push Docker image + if: ${{ !startsWith(github.ref, 'refs/tags/v') }} uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache build-args: | - BuiltAt=${{ steps.prep.outputs.built_at }} - GoVersion=${{ steps.prep.outputs.go_version }} - GitCommit=${{ steps.prep.outputs.git_commit }} - Version=${{ steps.version.outputs.version }} + BuiltAt=${{ steps.buildvars.outputs.built_at }} + GoVersion=${{ steps.buildvars.outputs.go_version }} + GitCommit=${{ steps.buildvars.outputs.git_commit }} + Version=${{ steps.buildvars.outputs.version }} + # public image - name: Extract metadata (tags, labels) for Docker - if: startsWith(github.ref, 'refs/tags/v') + if: ${{ startsWith(github.ref, 'refs/tags/v') }} id: publicmeta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }}-testing - name: Build and push Docker image - if: startsWith(github.ref, 'refs/tags/v') + if: ${{ startsWith(github.ref, 'refs/tags/v') }} uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ steps.publicmeta.outputs.tags }} labels: ${{ steps.publicmeta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache build-args: | - BuiltAt=$(date +%Y-%m-%dT%H:%M:%S) - GoVersion=$(go version) - GitCommit=$(git rev-parse HEAD) - Version=${{ steps.version.outputs.version }} + BuiltAt=${{ steps.buildvars.outputs.built_at }} + GoVersion=${{ steps.buildvars.outputs.go_version }} + GitCommit=${{ steps.buildvars.outputs.git_commit }} + Version=${{ steps.buildvars.outputs.version }}