name: Build Backend And Update GitOps on: push: branches: - main - high-performance jobs: build: 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 steps: - name: Checkout uses: actions/checkout@v4 - name: Install Docker CLI run: | apt-get update apt-get install -y docker.io - name: Log in to registry run: | echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.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 }} 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}" 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 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