From 425955b92111541fb43042698a07f891fafd3fb9 Mon Sep 17 00:00:00 2001 From: "Junv (via Hermes)" Date: Sun, 14 Jun 2026 11:59:52 +1000 Subject: [PATCH] ci(demo-service): GitHub Actions workflow for ghcr.io build - .github/workflows/build-demo-service.yml builds on push when home-apps/demo-service/** - Pushes to ghcr.io/wahyd4/demo-manager with git SHA tag + :latest - Updates k8s-manifest.yaml with new image tag - ArgoCD picks up the new image on next sync k8s-manifest changes: - image: ghcr.io/wahyd4/demo-manager (was docker.io/library/demo-manager) - imagePullPolicy: Always - imagePullSecrets: github-image-pull-secret (auth for ghcr.io) --- .github/workflows/build-demo-service.yml | 73 ++++++++++++++++++++++++ home-apps/demo-service/k8s-manifest.yaml | 8 ++- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build-demo-service.yml diff --git a/.github/workflows/build-demo-service.yml b/.github/workflows/build-demo-service.yml new file mode 100644 index 0000000..6b9f8ae --- /dev/null +++ b/.github/workflows/build-demo-service.yml @@ -0,0 +1,73 @@ +name: Build demo-service + +on: + push: + branches: [master] + paths: + - 'home-apps/demo-service/**' + workflow_dispatch: + +permissions: + contents: write + packages: write + +jobs: + build: + name: Build & update manifest + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Compute image tag + id: tag + run: | + SHA="${{ github.sha }}" + SHORT_SHA="${SHA:0:7}" + TAG="git-${SHORT_SHA}" + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + echo "full_image=ghcr.io/${{ github.repository_owner }}/demo-manager:${TAG}" >> "$GITHUB_OUTPUT" + + - name: Build & push image + uses: docker/build-push-action@v5 + with: + context: home-apps/demo-service + file: home-apps/demo-service/Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/demo-manager:${{ steps.tag.outputs.tag }} + ghcr.io/${{ github.repository_owner }}/demo-manager:latest + labels: | + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + + - name: Update manifest with new image tag + run: | + IMAGE="${{ steps.tag.outputs.full_image }}" + echo "Updating manifest to: ${IMAGE}" + sed -i "s|image: docker.io/library/demo-manager:.*|image: ${IMAGE}|" home-apps/demo-service/k8s-manifest.yaml + sed -i "s|imagePullPolicy:.*|imagePullPolicy: Always|" home-apps/demo-service/k8s-manifest.yaml + # Show what changed + git diff home-apps/demo-service/k8s-manifest.yaml + + - name: Commit & push manifest update + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add home-apps/demo-service/k8s-manifest.yaml + if git diff --cached --quiet; then + echo "No manifest changes to commit" + exit 0 + fi + git commit -m "ci(demo-service): bump image to ${{ steps.tag.outputs.tag }}" + git push diff --git a/home-apps/demo-service/k8s-manifest.yaml b/home-apps/demo-service/k8s-manifest.yaml index 3ce8463..624e2dd 100644 --- a/home-apps/demo-service/k8s-manifest.yaml +++ b/home-apps/demo-service/k8s-manifest.yaml @@ -108,8 +108,12 @@ spec: cpu: 200m - name: api - image: docker.io/library/demo-manager:latest - imagePullPolicy: IfNotPresent + # Image is updated automatically by .github/workflows/build-demo-service.yml + # on every push that changes home-apps/demo-service/** + image: ghcr.io/wahyd4/demo-manager:PLACEHOLDER + imagePullPolicy: Always + imagePullSecrets: + - name: github-image-pull-secret ports: - containerPort: 3000 name: api