mirror of
https://github.com/taylanbakircioglu/haproxy-openmanager.git
synced 2026-09-22 18:43:26 +00:00
1bc99c5fe7
The build workflow tagged the Docker images with the product version but never created the matching git tag, so the repo Tags/Releases drifted behind (stuck at the last manual tag, v1.6.0) while Docker Hub had 1.7.8. Add a step that, after the images are pushed, creates a Release (and its tag) for the current version.json when one does not already exist, and grant the job contents:write so it can do so.
108 lines
4.1 KiB
YAML
108 lines
4.1 KiB
YAML
name: build and push docker images
|
|
|
|
on:
|
|
push:
|
|
branches: ["main"]
|
|
|
|
jobs:
|
|
build_and_push:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: generate version tag
|
|
id: version
|
|
run: echo "TAG=$(date +'%Y%m%d.%H%M')" >> $GITHUB_OUTPUT
|
|
|
|
- name: read product version
|
|
id: prodversion
|
|
run: |
|
|
VERSION=$(jq -r .version version.json)
|
|
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
|
|
echo "Failed to read product version from version.json" >&2
|
|
exit 1
|
|
fi
|
|
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
# The backend image is built with `context: ./backend`, so the
|
|
# repo-root version.json is OUTSIDE the build context and never
|
|
# reaches the container. Backend `main.py` falls back to a
|
|
# compile-time constant when /app/version.json is missing, which
|
|
# caused a real production drift: a redeploy of the v1.5.2 tree
|
|
# silently still reported "v1.5.0" in `/api/version` because the
|
|
# constant in main.py had been bumped but the file was not
|
|
# available to read. Stage version.json into the backend
|
|
# context here so the canonical file IS shipped and the
|
|
# constant only serves as a defensive fallback. The staged file
|
|
# is gitignored to keep `git status` clean for developers.
|
|
- name: stage version.json into backend build context
|
|
run: cp version.json backend/version.json
|
|
|
|
- name: set up qemu
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: set up docker buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: login to docker hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: build & push backend
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./backend
|
|
file: ./backend/Dockerfile
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: |
|
|
taylanbakircioglu/haproxy-openmanager-backend:latest
|
|
taylanbakircioglu/haproxy-openmanager-backend:${{ steps.version.outputs.TAG }}
|
|
taylanbakircioglu/haproxy-openmanager-backend:${{ steps.prodversion.outputs.VERSION }}
|
|
|
|
- name: build & push frontend
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./frontend
|
|
file: ./frontend/Dockerfile
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: |
|
|
taylanbakircioglu/haproxy-openmanager-frontend:latest
|
|
taylanbakircioglu/haproxy-openmanager-frontend:${{ steps.version.outputs.TAG }}
|
|
taylanbakircioglu/haproxy-openmanager-frontend:${{ steps.prodversion.outputs.VERSION }}
|
|
|
|
# Keep the GitHub Releases/Tags in sync with version.json. The docker
|
|
# images above are tagged with the product version, but nothing here
|
|
# created the matching git tag, so the repo's Tags/Releases drifted
|
|
# behind (stuck at the last manually-created tag). After the images are
|
|
# pushed, cut a Release (which also creates the tag) for the current
|
|
# version.json, but only if one does not already exist, so re-runs
|
|
# without a version bump are a no-op.
|
|
- name: create github release from version.json
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
VERSION="${{ steps.prodversion.outputs.VERSION }}"
|
|
TAG="v${VERSION}"
|
|
RELEASE_NAME=$(jq -r '.releaseName // empty' version.json)
|
|
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
|
|
echo "Release $TAG already exists, skipping."
|
|
else
|
|
TITLE="$TAG"
|
|
[ -n "$RELEASE_NAME" ] && TITLE="$TAG — $RELEASE_NAME"
|
|
gh release create "$TAG" \
|
|
--repo "$GITHUB_REPOSITORY" \
|
|
--target "$GITHUB_SHA" \
|
|
--title "$TITLE" \
|
|
--notes "Automated release for $TAG (from version.json)."
|
|
echo "Created release $TAG"
|
|
fi
|
|
|