mirror of
https://github.com/wahyd4/home-docker.git
synced 2026-08-08 20:15:03 +10:00
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)
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user