2026-06-14 01:20:24 +05:30
|
|
|
name: build-and-release
|
2026-04-19 00:03:00 +02:00
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- main
|
|
|
|
|
- high-performance
|
|
|
|
|
|
2026-06-14 01:20:24 +05:30
|
|
|
concurrency:
|
|
|
|
|
group: backend-build-${{ github.ref }}
|
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
2026-04-19 00:03:00 +02:00
|
|
|
jobs:
|
2026-06-14 01:20:24 +05:30
|
|
|
build:
|
2026-07-06 04:24:06 +05:30
|
|
|
runs-on: docker-ready
|
2026-07-08 01:54:47 +05:30
|
|
|
strategy:
|
|
|
|
|
fail-fast: false
|
2026-07-08 02:43:46 +05:30
|
|
|
max-parallel: 6
|
2026-07-08 01:54:47 +05:30
|
|
|
matrix:
|
|
|
|
|
service:
|
|
|
|
|
- gateway
|
|
|
|
|
- users
|
|
|
|
|
- companies
|
|
|
|
|
- jobs
|
|
|
|
|
- job-seekers
|
|
|
|
|
- customers
|
|
|
|
|
- payments
|
|
|
|
|
- employees
|
|
|
|
|
- photographers
|
|
|
|
|
- makeup-artists
|
|
|
|
|
- tutors
|
|
|
|
|
- developers
|
|
|
|
|
- video-editors
|
|
|
|
|
- graphic-designers
|
|
|
|
|
- social-media-managers
|
|
|
|
|
- fitness-trainers
|
|
|
|
|
- catering-services
|
|
|
|
|
- ugc-content-creators
|
|
|
|
|
- cron
|
2026-07-06 04:24:06 +05:30
|
|
|
env:
|
|
|
|
|
DOCKER_BUILDKIT: "1"
|
2026-04-29 10:01:22 +02:00
|
|
|
steps:
|
|
|
|
|
- name: Checkout
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
2026-07-08 01:54:47 +05:30
|
|
|
# Static matrix (all 20 services every push) instead of a single job
|
|
|
|
|
# looping sequentially - up to 3 run concurrently (one per runner pod;
|
|
|
|
|
# each runner's capacity is 1). This step is each job's own quick
|
|
|
|
|
# "do I actually need to do anything" check, so unaffected services
|
|
|
|
|
# skip in a couple of seconds rather than sitting in a shared queue.
|
|
|
|
|
- name: Check if this service needs building
|
|
|
|
|
id: check
|
2026-04-29 10:01:22 +02:00
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-07-08 01:54:47 +05:30
|
|
|
service="${{ matrix.service }}"
|
|
|
|
|
svc_dir="$(echo "$service" | tr '-' '_')"
|
2026-06-14 01:20:24 +05:30
|
|
|
|
2026-04-29 10:01:22 +02:00
|
|
|
if git rev-parse --verify HEAD^ >/dev/null 2>&1; then
|
2026-06-14 01:20:24 +05:30
|
|
|
CHANGED_FILES="$(git diff --name-only HEAD^ HEAD)"
|
2026-04-29 10:01:22 +02:00
|
|
|
else
|
2026-06-14 01:20:24 +05:30
|
|
|
CHANGED_FILES="$(git ls-files)"
|
2026-04-29 10:01:22 +02:00
|
|
|
fi
|
2026-06-14 01:20:24 +05:30
|
|
|
LAST_COMMIT_MSG="$(git log -1 --pretty=%B | tr '\n' ' ')"
|
|
|
|
|
|
2026-07-08 01:54:47 +05:30
|
|
|
build=false
|
2026-06-13 01:23:22 +05:30
|
|
|
if echo "$LAST_COMMIT_MSG" | grep -Eiq 'trigger build|force build|rebuild all'; then
|
2026-07-08 01:54:47 +05:30
|
|
|
build=true
|
2026-06-14 01:20:24 +05:30
|
|
|
elif echo "$CHANGED_FILES" | grep -Eq '^(\.forgejo/workflows/|Dockerfile|Cargo\.toml|Cargo\.lock|crates/|scripts/)'; then
|
2026-07-08 01:54:47 +05:30
|
|
|
build=true
|
|
|
|
|
elif echo "$CHANGED_FILES" | grep -q "^apps/${svc_dir}/"; then
|
|
|
|
|
build=true
|
2026-04-29 11:56:40 +02:00
|
|
|
fi
|
2026-06-14 01:20:24 +05:30
|
|
|
|
2026-07-08 01:54:47 +05:30
|
|
|
echo "build=$build" >> "$GITHUB_OUTPUT"
|
|
|
|
|
if [ "$build" = "false" ]; then
|
|
|
|
|
echo "No changes relevant to $service - skipping."
|
2026-04-29 10:01:22 +02:00
|
|
|
fi
|
2026-06-14 01:20:24 +05:30
|
|
|
|
2026-07-08 01:54:47 +05:30
|
|
|
- name: Point DOCKER_HOST at this container's own gateway
|
|
|
|
|
if: steps.check.outputs.build == 'true'
|
2026-06-14 01:20:24 +05:30
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-07-08 01:54:47 +05:30
|
|
|
# 127.0.0.1 doesn't work: the job container is nested one level
|
|
|
|
|
# inside the runner pod's dind sidecar, so its own loopback isn't
|
|
|
|
|
# the sidecar's. --add-host=host.docker.internal:host-gateway is
|
|
|
|
|
# not being honored by this runner (tried via both global
|
|
|
|
|
# container.options and a per-job container: block — neither
|
|
|
|
|
# resolved), so read the container's actual default-route gateway
|
|
|
|
|
# directly instead, which is the dind engine that spawned it.
|
|
|
|
|
# Read directly from /proc/net/route instead of relying on the `ip`
|
|
|
|
|
# or `route` CLI tools being installed in the job image.
|
|
|
|
|
GATEWAY="$(awk '$2 == "00000000" {print $3}' /proc/net/route | head -1 | \
|
|
|
|
|
sed -E 's/(..)(..)(..)(..)/0x\4 0x\3 0x\2 0x\1/' | \
|
|
|
|
|
{ read -r a b c d; printf '%d.%d.%d.%d' "$a" "$b" "$c" "$d"; })"
|
|
|
|
|
echo "Detected docker host gateway: $GATEWAY"
|
|
|
|
|
echo "DOCKER_HOST=tcp://$GATEWAY:2375" >> "$GITHUB_ENV"
|
2026-04-19 00:03:00 +02:00
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
2026-07-08 01:54:47 +05:30
|
|
|
if: steps.check.outputs.build == 'true'
|
2026-04-19 18:06:52 +02:00
|
|
|
run: |
|
2026-06-14 01:20:24 +05:30
|
|
|
set -euo pipefail
|
2026-04-29 10:10:07 +02:00
|
|
|
docker version
|
2026-07-08 01:54:47 +05:30
|
|
|
# Same builder name on every node is safe: each runner has
|
|
|
|
|
# capacity 1, so only one job ever touches a given node's dind
|
|
|
|
|
# engine at a time - reusing the name lets its build cache persist
|
|
|
|
|
# (and warm up) across services scheduled on that node over time.
|
2026-06-14 01:20:24 +05:30
|
|
|
docker buildx create --use --name nxtgauge-builder || docker buildx use nxtgauge-builder
|
2026-04-19 18:06:52 +02:00
|
|
|
docker buildx inspect --bootstrap
|
2026-04-19 00:03:00 +02:00
|
|
|
|
2026-06-14 01:20:24 +05:30
|
|
|
- name: Login to registry
|
2026-07-08 01:54:47 +05:30
|
|
|
if: steps.check.outputs.build == 'true'
|
2026-06-14 01:20:24 +05:30
|
|
|
env:
|
2026-06-17 03:28:46 +05:30
|
|
|
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
|
|
|
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
|
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
2026-06-14 01:20:24 +05:30
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-06-17 03:28:46 +05:30
|
|
|
printf '%s' "$REGISTRY_PASSWORD" | docker login "$REGISTRY_HOST" -u "$REGISTRY_USERNAME" --password-stdin
|
2026-06-14 01:20:24 +05:30
|
|
|
|
2026-07-08 01:54:47 +05:30
|
|
|
- name: Build and push
|
|
|
|
|
if: steps.check.outputs.build == 'true'
|
2026-06-14 01:20:24 +05:30
|
|
|
env:
|
2026-06-17 03:28:46 +05:30
|
|
|
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
|
|
|
|
|
REGISTRY_NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'ashwin' }}
|
2026-06-14 01:20:24 +05:30
|
|
|
SHA: ${{ github.sha }}
|
2026-04-19 18:06:52 +02:00
|
|
|
run: |
|
2026-04-19 18:13:48 +02:00
|
|
|
set -euo pipefail
|
2026-07-08 01:54:47 +05:30
|
|
|
service="${{ matrix.service }}"
|
|
|
|
|
metadata_file="/tmp/${service}-metadata.json"
|
|
|
|
|
image_ref="$REGISTRY_HOST/$REGISTRY_NAMESPACE/nxtgauge-rust-${service}:${SHA}"
|
|
|
|
|
|
|
|
|
|
docker buildx build --push \
|
|
|
|
|
--metadata-file "$metadata_file" \
|
|
|
|
|
-f Dockerfile.simple \
|
|
|
|
|
--build-arg SERVICE_NAME="$service" \
|
|
|
|
|
-t "$image_ref" \
|
|
|
|
|
.
|
|
|
|
|
|
|
|
|
|
# buildx writes the metadata file pretty-printed (space after the
|
|
|
|
|
# colon), which the old compact-JSON-only pattern never matched -
|
|
|
|
|
# tolerate optional whitespace and extract the digest directly.
|
|
|
|
|
digest="$(grep -o '"containerimage\.digest"[[:space:]]*:[[:space:]]*"sha256:[^"]*"' "$metadata_file" | grep -o 'sha256:[^"]*')"
|
|
|
|
|
if [ -z "$digest" ]; then
|
|
|
|
|
echo "Failed to determine digest for $service" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo "DIGEST=$digest" >> "$GITHUB_ENV"
|
2026-06-14 01:20:24 +05:30
|
|
|
|
|
|
|
|
- name: Update GitOps release state
|
2026-07-08 01:54:47 +05:30
|
|
|
if: steps.check.outputs.build == 'true'
|
2026-04-19 18:13:48 +02:00
|
|
|
env:
|
2026-06-17 03:28:46 +05:30
|
|
|
GITOPS_SERVER: ${{ secrets.GITOPS_SERVER || 'ci.nxtgauge.com' }}
|
|
|
|
|
GITOPS_OWNER: ${{ secrets.GITOPS_OWNER || 'ashwin' }}
|
2026-06-14 01:20:24 +05:30
|
|
|
GITOPS_REPO: ${{ secrets.GITOPS_REPO || 'nxtgauge-gitops' }}
|
|
|
|
|
GITOPS_BRANCH: ${{ secrets.GITOPS_BRANCH || 'main' }}
|
2026-07-08 02:10:33 +05:30
|
|
|
# The gitops repo now lives on Forgejo (ci.nxtgauge.com), not
|
|
|
|
|
# GitHub - GITOPS_PUSH_USERNAME/GITOPS_PUSH_TOKEN were never
|
|
|
|
|
# actually configured as repo secrets (only the leftover
|
|
|
|
|
# GITOPS_GITHUB_* pair and GITOPS_PAT exist). Use GITOPS_PAT,
|
|
|
|
|
# which matches the current Forgejo-hosted repo.
|
|
|
|
|
GITOPS_PAT: ${{ secrets.GITOPS_PAT }}
|
2026-06-14 01:20:24 +05:30
|
|
|
SHA: ${{ github.sha }}
|
2026-04-19 18:06:52 +02:00
|
|
|
run: |
|
2026-04-29 10:10:07 +02:00
|
|
|
set -euo pipefail
|
2026-07-08 02:10:33 +05:30
|
|
|
test -n "${GITOPS_PAT:-}" || { echo "GITOPS_PAT is empty"; exit 1; }
|
2026-07-08 01:54:47 +05:30
|
|
|
service="${{ matrix.service }}"
|
2026-06-14 01:20:24 +05:30
|
|
|
|
2026-07-08 02:10:33 +05:30
|
|
|
git clone "https://forgejo-actions:${GITOPS_PAT}@${GITOPS_SERVER}/${GITOPS_OWNER}/${GITOPS_REPO}.git" /tmp/nxtgauge-gitops
|
2026-06-14 01:20:24 +05:30
|
|
|
cd /tmp/nxtgauge-gitops
|
|
|
|
|
|
2026-07-08 02:30:36 +05:30
|
|
|
# Up to 9 of these jobs can be pushing to the same gitops branch at
|
2026-07-08 01:54:47 +05:30
|
|
|
# once now - retry with a fresh pull+rebase on a non-fast-forward
|
|
|
|
|
# rejection instead of assuming we're the only writer.
|
2026-07-08 02:30:36 +05:30
|
|
|
pushed=false
|
|
|
|
|
for attempt in 1 2 3 4 5 6 7 8; do
|
2026-07-08 01:54:47 +05:30
|
|
|
git checkout "$GITOPS_BRANCH"
|
|
|
|
|
./scripts/set-backend-rust-release.sh "$service" "$DIGEST"
|
2026-06-14 01:20:24 +05:30
|
|
|
|
2026-07-08 01:54:47 +05:30
|
|
|
if git diff --quiet; then
|
|
|
|
|
echo "GitOps repo already up to date for $service."
|
2026-07-08 02:30:36 +05:30
|
|
|
pushed=true
|
2026-07-08 01:54:47 +05:30
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
git config user.name "forgejo-actions[bot]"
|
|
|
|
|
git config user.email "forgejo-actions@ci.nxtgauge.com"
|
|
|
|
|
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 commit -m "chore(gitops): update ${service} image for ${SHA}"
|
|
|
|
|
|
|
|
|
|
if git push origin "HEAD:${GITOPS_BRANCH}"; then
|
2026-07-08 02:30:36 +05:30
|
|
|
pushed=true
|
2026-07-08 01:54:47 +05:30
|
|
|
break
|
|
|
|
|
fi
|
2026-04-29 10:10:07 +02:00
|
|
|
|
2026-07-08 02:30:36 +05:30
|
|
|
echo "Push rejected (attempt $attempt/8), pulling latest and retrying..."
|
2026-07-08 01:54:47 +05:30
|
|
|
git fetch origin "$GITOPS_BRANCH"
|
|
|
|
|
git reset --hard "origin/${GITOPS_BRANCH}"
|
|
|
|
|
sleep $((attempt * 2))
|
|
|
|
|
done
|
2026-07-08 02:30:36 +05:30
|
|
|
|
|
|
|
|
if [ "$pushed" != true ]; then
|
|
|
|
|
echo "Failed to push gitops update for $service after all retries" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|