Skip to content

Commit 0edd7fb

Browse files
author
Raffael Herrmann
committed
Add GitHub Actions workflow for Docker image build and push
1 parent 6aaf437 commit 0edd7fb

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

.github/workflows/docker-build.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'Branch to build from'
8+
required: true
9+
type: string
10+
tag_as_latest:
11+
description: 'Tag image as latest'
12+
required: false
13+
default: false
14+
type: boolean
15+
16+
jobs:
17+
build-and-push:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout branch
22+
uses: actions/checkout@v4
23+
with:
24+
ref: ${{ inputs.branch }}
25+
26+
- name: Get latest version tag
27+
id: get-tag
28+
run: |
29+
git fetch --tags
30+
LATEST_TAG=$(git tag | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?$' | sort -V | tail -1)
31+
if [ -z "$LATEST_TAG" ]; then
32+
echo "No version tags found on branch ${{ inputs.branch }}"
33+
exit 1
34+
fi
35+
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
36+
37+
- name: Checkout tag
38+
run: |
39+
git checkout ${{ steps.get-tag.outputs.tag }}
40+
41+
- name: Log in to GitHub Container Registry
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Extract metadata
49+
id: meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ghcr.io/${{ github.repository }}
53+
tags: |
54+
type=raw,value=${{ steps.get-tag.outputs.tag }}
55+
type=raw,value=latest,enable=${{ inputs.tag_as_latest }}
56+
57+
- name: Build and push Docker image
58+
uses: docker/build-push-action@v5
59+
with:
60+
context: .
61+
push: true
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)