Tweak workflows

This commit is contained in:
Ben Sarmiento
2023-12-03 13:39:18 +01:00
parent 324374d24b
commit 4d8d5ea71a
2 changed files with 26 additions and 25 deletions

View File

@@ -8,7 +8,7 @@ on:
jobs: jobs:
build: build:
name: Build name: Build
runs-on: self-hosted runs-on: [self-hosted, ubuntu-latest]
permissions: permissions:
contents: read contents: read
packages: write packages: write

View File

@@ -8,18 +8,22 @@ on:
jobs: jobs:
build-and-push-image: build-and-push-image:
name: Docker Build name: Docker Build
runs-on: self-hosted runs-on: [self-hosted, ubuntu-latest]
permissions: permissions:
contents: read contents: read
packages: write packages: write
steps: steps:
- name: Set version - name: Set version
id: version id: buildvars
run: echo "::set-output name=version::$(echo ${GITHUB_REF#refs/tags/})" 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 - name: Set up QEMU
uses: actions/checkout@v4 uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -39,55 +43,52 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
# private image
- name: Extract metadata (tags, labels) for Docker - name: Extract metadata (tags, labels) for Docker
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
id: meta id: meta
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: ghcr.io/${{ github.repository }} 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 - name: Build and push Docker image
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache
build-args: | build-args: |
BuiltAt=${{ steps.prep.outputs.built_at }} BuiltAt=${{ steps.buildvars.outputs.built_at }}
GoVersion=${{ steps.prep.outputs.go_version }} GoVersion=${{ steps.buildvars.outputs.go_version }}
GitCommit=${{ steps.prep.outputs.git_commit }} GitCommit=${{ steps.buildvars.outputs.git_commit }}
Version=${{ steps.version.outputs.version }} Version=${{ steps.buildvars.outputs.version }}
# public image
- name: Extract metadata (tags, labels) for Docker - name: Extract metadata (tags, labels) for Docker
if: startsWith(github.ref, 'refs/tags/v') if: ${{ startsWith(github.ref, 'refs/tags/v') }}
id: publicmeta id: publicmeta
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: ghcr.io/${{ github.repository }}-testing images: ghcr.io/${{ github.repository }}-testing
- name: Build and push Docker image - 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 uses: docker/build-push-action@v5
with: with:
context: . context: .
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true push: true
tags: ${{ steps.publicmeta.outputs.tags }} tags: ${{ steps.publicmeta.outputs.tags }}
labels: ${{ steps.publicmeta.outputs.labels }} labels: ${{ steps.publicmeta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache
build-args: | build-args: |
BuiltAt=$(date +%Y-%m-%dT%H:%M:%S) BuiltAt=${{ steps.buildvars.outputs.built_at }}
GoVersion=$(go version) GoVersion=${{ steps.buildvars.outputs.go_version }}
GitCommit=$(git rev-parse HEAD) GitCommit=${{ steps.buildvars.outputs.git_commit }}
Version=${{ steps.version.outputs.version }} Version=${{ steps.buildvars.outputs.version }}