ci(forgejo): update backend build pipeline

This commit is contained in:
Ashwin Kumar Sivakumar 2026-07-03 19:51:37 +05:30
parent fcb40c3590
commit f5831da1f5

View file

@ -7,54 +7,13 @@ on:
- high-performance
jobs:
build:
build-and-update:
runs-on: ubuntu-latest
env:
DOCKER_HOST: unix:///var/run/docker.sock
strategy:
fail-fast: false
matrix:
include:
- app_dir: apps/catering_services
image: registry.nxtgauge.com/nxtgauge-rust-catering-services
- app_dir: apps/companies
image: registry.nxtgauge.com/nxtgauge-rust-companies
- app_dir: apps/cron
image: registry.nxtgauge.com/nxtgauge-rust-cron
- app_dir: apps/customers
image: registry.nxtgauge.com/nxtgauge-rust-customers
- app_dir: apps/developers
image: registry.nxtgauge.com/nxtgauge-rust-developers
- app_dir: apps/employees
image: registry.nxtgauge.com/nxtgauge-rust-employees
- app_dir: apps/fitness_trainers
image: registry.nxtgauge.com/nxtgauge-rust-fitness-trainers
- app_dir: apps/gateway
image: registry.nxtgauge.com/nxtgauge-rust-gateway
- app_dir: apps/graphic_designers
image: registry.nxtgauge.com/nxtgauge-rust-graphic-designers
- app_dir: apps/jobs
image: registry.nxtgauge.com/nxtgauge-rust-jobs
- app_dir: apps/job_seekers
image: registry.nxtgauge.com/nxtgauge-rust-job-seekers
- app_dir: apps/leads
image: registry.nxtgauge.com/nxtgauge-rust-leads
- app_dir: apps/makeup_artists
image: registry.nxtgauge.com/nxtgauge-rust-makeup-artists
- app_dir: apps/payments
image: registry.nxtgauge.com/nxtgauge-rust-payments
- app_dir: apps/photographers
image: registry.nxtgauge.com/nxtgauge-rust-photographers
- app_dir: apps/social_media_managers
image: registry.nxtgauge.com/nxtgauge-rust-social-media-managers
- app_dir: apps/tutors
image: registry.nxtgauge.com/nxtgauge-rust-tutors
- app_dir: apps/ugc_content_creators
image: registry.nxtgauge.com/nxtgauge-rust-ugc-content-creators
- app_dir: apps/users
image: registry.nxtgauge.com/nxtgauge-rust-users
- app_dir: apps/video_editors
image: registry.nxtgauge.com/nxtgauge-rust-video-editors
GITOPS_USERNAME: ${{ secrets.GITOPS_GITHUB_USERNAME || 'Traceworks2023' }}
GITOPS_PASSWORD: ${{ secrets.GITOPS_GITHUB_TOKEN || secrets.GITOPS_PAT }}
GITOPS_REPO: https://github.com/Traceworks2023/nxtgauge-gitops.git
steps:
- name: Checkout
uses: actions/checkout@v4
@ -62,55 +21,64 @@ jobs:
- name: Install Docker CLI
run: |
apt-get update
apt-get install -y docker.io
apt-get install -y docker.io git python3
- name: Log in to registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.nxtgauge.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ci.nxtgauge.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
- name: Build and push backend service image
run: |
set -euo pipefail
IMAGE_SHA="${{ matrix.image }}:${{ github.sha }}"
IMAGE_LATEST="${{ matrix.image }}:latest"
docker build -f "${{ matrix.app_dir }}/Dockerfile" -t "${IMAGE_SHA}" -t "${IMAGE_LATEST}" .
docker push "${IMAGE_SHA}"
docker push "${IMAGE_LATEST}"
update-gitops:
needs: build
runs-on: ubuntu-latest
steps:
- name: Update GitOps backend tags
env:
GITOPS_USERNAME: ${{ secrets.GITOPS_GITHUB_USERNAME || 'Traceworks2023' }}
GITOPS_PASSWORD: ${{ secrets.GITOPS_GITHUB_TOKEN || secrets.GITOPS_PAT }}
GITOPS_REPO: https://github.com/Traceworks2023/nxtgauge-gitops.git
IMAGE_TAG: ${{ github.sha }}
- name: Build, push, and update GitOps
run: |
set -euo pipefail
test -n "${GITOPS_PASSWORD:-}" || { echo "GITOPS_PASSWORD is empty"; exit 1; }
AUTH="$(printf '%s' "${GITOPS_USERNAME}:${GITOPS_PASSWORD}" | base64 -w0)"
TMP_DIR="$(mktemp -d)"
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" clone --branch main "${GITOPS_REPO}" "${TMP_DIR}"
while IFS='|' read -r service app_dir; do
[ -n "${service}" ] || continue
IMAGE="ci.nxtgauge.com/ashwin/nxtgauge-rust-${service}:${{ github.sha }}"
docker build -f "${app_dir}/Dockerfile" -t "${IMAGE}" .
docker push "${IMAGE}"
IMAGE_DIGEST="$(docker image inspect "${IMAGE}" --format '{{join .RepoDigests "\n"}}' | grep '@sha256:' | sed -n '1s|.*@||p')"
test -n "${IMAGE_DIGEST}" || { echo "failed to resolve image digest for ${IMAGE}"; exit 1; }
(
cd "${TMP_DIR}"
./scripts/set-backend-rust-release.sh "${service}" "${IMAGE_DIGEST}"
)
done <<'SERVICES'
catering-services|apps/catering_services
companies|apps/companies
cron|apps/cron
customers|apps/customers
developers|apps/developers
employees|apps/employees
fitness-trainers|apps/fitness_trainers
gateway|apps/gateway
graphic-designers|apps/graphic_designers
job-seekers|apps/job_seekers
jobs|apps/jobs
leads|apps/leads
makeup-artists|apps/makeup_artists
payments|apps/payments
photographers|apps/photographers
social-media-managers|apps/social_media_managers
tutors|apps/tutors
ugc-content-creators|apps/ugc_content_creators
users|apps/users
video-editors|apps/video_editors
SERVICES
cd "${TMP_DIR}"
python3 - <<'PY'
from pathlib import Path
import os
path = Path('apps/nxtgauge-backend-rust/overlays/prod/kustomization.yaml')
lines = path.read_text().splitlines()
out = []
for line in lines:
if line.strip().startswith('newTag:'):
indent = line[:len(line) - len(line.lstrip())]
out.append(f"{indent}newTag: {os.environ['IMAGE_TAG']}")
else:
out.append(line)
path.write_text('\n'.join(out) + '\n')
PY
git config user.name "forgejo-actions"
git config user.email "forgejo-actions@nxtgauge.com"
git add apps/nxtgauge-backend-rust/overlays/prod/kustomization.yaml
git add apps/nxtgauge-backend-rust/overlays/prod/backend-release-state.tsv apps/nxtgauge-backend-rust/overlays/prod/release-patches.yaml apps/nxtgauge-backend-rust/overlays/prod/disabled-deployments.yaml
git diff --cached --quiet && exit 0
git commit -m "chore(gitops): update backend images to ${IMAGE_TAG}"
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push origin main
git commit -m "chore(gitops): deploy backend@${{ github.sha }}"
for attempt in 1 2 3 4 5; do
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" pull --rebase origin main
if git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push origin main; then
exit 0
fi
sleep "$attempt"
done
echo "failed to push GitOps update after retries"
exit 1