Docker Compose Version Sync
This guide explains the automated synchronization of Docker image versions between the Maven POM and Docker Compose files.
Overview
Docker Compose files in src/main/docker/ reference specific Docker image versions. These versions must match the project dependencies defined in pom.xml. The sync workflow automates this synchronization.
How It Works
When pom.xml is pushed to the develop branch, a GitHub Actions workflow:
-
Extracts version properties from
pom.xml -
Updates image tags in Docker Compose files
-
Commits and pushes changes if any updates were made
Version Properties
The workflow extracts these properties from pom.xml:
| Property | Source | Used For |
|---|---|---|
|
|
Gateway/UI image version |
|
|
Admin Service image version |
Files Updated
The workflow updates these Docker Compose files:
src/main/docker/dev.yml
|
Full stack compose file (Gateway, Admin Service, MySQL) |
src/main/docker/admin-service.yml
|
Admin Service and MySQL only |
Workflow Configuration
name: 'Sync Docker Compose Versions'
on:
push:
branches:
- develop
paths:
- 'pom.xml'
env:
DOCKER_REGISTRY: christhonie
PORTAL_IMAGE_NAME: registration-portal # or membership-ui, event-admin-ui
ADMIN_IMAGE_NAME: event-admin-service
DEV_YML_PATH: src/main/docker/dev.yml
ADMIN_SERVICE_YML_PATH: src/main/docker/admin-service.yml
jobs:
sync-versions:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Extract versions from POM
id: versions
run: |
REVISION=$(grep -oP '(?<=<revision>)[^<]+' pom.xml | head -1)
echo "revision=$REVISION" >> $GITHUB_OUTPUT
ADMIN_VERSION=$(grep -oP '(?<=<admin-service.version>)[^<]+' pom.xml | head -1)
echo "admin_version=$ADMIN_VERSION" >> $GITHUB_OUTPUT
- name: Update Docker Compose files
run: |
PORTAL_IMAGE="${DOCKER_REGISTRY}/${PORTAL_IMAGE_NAME}"
ADMIN_IMAGE="${DOCKER_REGISTRY}/${ADMIN_IMAGE_NAME}"
sed -i "s|${PORTAL_IMAGE}:[^[:space:]]*|${PORTAL_IMAGE}:${{ steps.versions.outputs.revision }}|g" "$DEV_YML_PATH"
sed -i "s|${ADMIN_IMAGE}:[^[:space:]]*|${ADMIN_IMAGE}:${{ steps.versions.outputs.admin_version }}|g" "$DEV_YML_PATH"
sed -i "s|${ADMIN_IMAGE}:[^[:space:]]*|${ADMIN_IMAGE}:${{ steps.versions.outputs.admin_version }}|g" "$ADMIN_SERVICE_YML_PATH"
- name: Check for changes
id: changes
run: |
if git diff --quiet "$DEV_YML_PATH" "$ADMIN_SERVICE_YML_PATH"; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$DEV_YML_PATH" "$ADMIN_SERVICE_YML_PATH"
git commit -m "[AutoTask] Sync Docker image versions with POM"
git push
POM Configuration
Ensure your pom.xml has the required properties:
<properties>
<revision>1.2.4-SNAPSHOT</revision>
<admin-service.version>2.3.1-SNAPSHOT</admin-service.version>
</properties>
Commit Message Format
The workflow creates commits with this format:
[AutoTask] Sync Docker image versions with POM
- registration-portal: 1.2.4-SNAPSHOT
- event-admin-service: 2.3.1-SNAPSHOT
Generated by GitHub Actions
When Sync Runs
The workflow triggers when:
-
A push is made to the
developbranch -
The push includes changes to
pom.xml
It does not run for:
-
Pull requests (only merged changes)
-
Other branches
-
Changes to files other than
pom.xml
Manual Version Updates
If you need to update versions manually:
-
Edit
pom.xmlwith new version values -
Push to
developbranch -
The workflow will automatically update Docker Compose files
Alternatively, edit both pom.xml and the compose files in the same commit if you want to avoid the automated commit.
Troubleshooting
Workflow Doesn’t Run
-
Verify the push is to
developbranch -
Check that
pom.xmlwas modified in the push -
Review GitHub Actions permissions
Customizing for New Projects
When adding this workflow to a new project:
-
Copy the workflow file to
.github/workflows/ -
Update
PORTAL_IMAGE_NAMEto match your project’s image name -
Ensure
pom.xmlhas bothrevisionandadmin-service.versionproperties -
Create the Docker Compose files with the expected image references