Skip to content

Commit 21cfb6f

Browse files
committed
Add GitHub Actions workflow for Docker image build and publish
1 parent 1d65190 commit 21cfb6f

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

.github/workflows/docker-image.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,30 @@ jobs:
5050
username: ${{ github.actor }}
5151
password: ${{ secrets.GITHUB_TOKEN }}
5252

53+
- name: Extract project version
54+
id: project
55+
shell: bash
56+
run: |
57+
version="$(python3 -c "import xml.etree.ElementTree as ET; ns={'m':'http://maven.apache.org/POM/4.0.0'}; root=ET.parse('pom.xml').getroot(); version=root.find('m:version', ns); print(version.text.strip() if version is not None and version.text else '')")"
58+
if [ -z "${version}" ]; then
59+
echo "Could not find root project version in pom.xml" >&2
60+
exit 1
61+
fi
62+
echo "version=${version}" >> "${GITHUB_OUTPUT}"
63+
5364
- name: Extract Docker metadata
5465
id: meta
5566
uses: docker/metadata-action@v5
67+
env:
68+
DOCKER_METADATA_SHORT_SHA_LENGTH: 8
5669
with:
5770
images: ${{ env.IMAGE_NAME }}
5871
tags: |
5972
type=ref,event=branch
6073
type=ref,event=tag
61-
type=sha,prefix=sha-
62-
type=raw,value=latest,enable={{is_default_branch}}
74+
type=sha,format=short,prefix=
75+
type=raw,value=${{ steps.project.outputs.version }}
76+
type=raw,value=latest
6377
6478
- name: Build and publish Docker image
6579
uses: docker/build-push-action@v6

0 commit comments

Comments
 (0)