2026-06-14 05:52:49 +05:30
|
|
|
name: build-and-release
|
2026-04-19 00:02:55 +02:00
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- main
|
|
|
|
|
- high-performance
|
|
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
concurrency:
|
|
|
|
|
group: admin-solid-build-${{ github.ref }}
|
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
2026-04-19 00:02:55 +02:00
|
|
|
jobs:
|
|
|
|
|
build:
|
2026-06-15 06:19:17 +05:30
|
|
|
runs-on: docker-ready
|
|
|
|
|
env:
|
|
|
|
|
DOCKER_BUILDKIT: "1"
|
2026-04-19 00:02:55 +02:00
|
|
|
steps:
|
|
|
|
|
- name: Checkout
|
|
|
|
|
uses: actions/checkout@v4
|
2026-06-14 05:52:49 +05:30
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
2026-04-19 00:02:55 +02:00
|
|
|
|
2026-07-12 18:28:38 +05:30
|
|
|
- name: Point DOCKER_HOST at this container's own gateway
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
# 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. Read the container's actual default-route gateway
|
|
|
|
|
# directly from /proc/net/route instead of relying on `ip`/`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:05:00 +02:00
|
|
|
- name: Set up Docker Buildx
|
2026-04-19 18:06:45 +02:00
|
|
|
run: |
|
2026-06-14 05:52:49 +05:30
|
|
|
set -euo pipefail
|
2026-06-15 06:19:17 +05:30
|
|
|
for attempt in $(seq 1 30); do
|
|
|
|
|
if docker version >/dev/null 2>&1; then
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
sleep 2
|
|
|
|
|
done
|
2026-04-30 22:54:24 +02:00
|
|
|
docker version
|
2026-06-14 05:52:49 +05:30
|
|
|
docker buildx create --use --name nxtgauge-builder || docker buildx use nxtgauge-builder
|
2026-04-19 18:06:45 +02:00
|
|
|
docker buildx inspect --bootstrap
|
2026-04-19 00:05:00 +02:00
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
- name: Login to registry
|
2026-04-19 18:13:41 +02:00
|
|
|
env:
|
2026-06-17 03:28:45 +05:30
|
|
|
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
|
|
|
|
|
REGISTRY_NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'ashwin' }}
|
2026-04-19 18:13:41 +02:00
|
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
|
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
2026-04-19 18:06:45 +02:00
|
|
|
run: |
|
2026-04-19 18:13:41 +02:00
|
|
|
set -euo pipefail
|
2026-06-17 03:28:45 +05:30
|
|
|
test -n "$REGISTRY_HOST"
|
|
|
|
|
printf '%s' "$REGISTRY_PASSWORD" | docker login "$REGISTRY_HOST" -u "$REGISTRY_USERNAME" --password-stdin
|
2026-04-19 00:05:00 +02:00
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
- name: Build and push image
|
2026-04-19 18:13:41 +02:00
|
|
|
env:
|
2026-06-17 03:28:45 +05:30
|
|
|
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
|
|
|
|
|
REGISTRY_NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'ashwin' }}
|
2026-06-14 05:52:49 +05:30
|
|
|
SHA: ${{ github.sha }}
|
2026-04-19 18:06:45 +02:00
|
|
|
run: |
|
2026-04-30 22:54:24 +02:00
|
|
|
set -euo pipefail
|
2026-06-14 05:52:49 +05:30
|
|
|
metadata_file="/tmp/admin-solid-metadata.json"
|
2026-06-17 03:28:45 +05:30
|
|
|
image_ref="$REGISTRY_HOST/$REGISTRY_NAMESPACE/nxtgauge-admin-solid:$SHA"
|
2026-06-14 05:52:49 +05:30
|
|
|
|
2026-04-19 18:06:45 +02:00
|
|
|
docker buildx build --push \
|
2026-06-14 05:52:49 +05:30
|
|
|
--metadata-file "$metadata_file" \
|
2026-04-19 18:06:45 +02:00
|
|
|
-f Dockerfile \
|
2026-06-14 05:52:49 +05:30
|
|
|
-t "$image_ref" \
|
2026-04-19 18:06:45 +02:00
|
|
|
.
|
2026-05-01 10:10:30 +02:00
|
|
|
|
2026-07-12 18:32:57 +05:30
|
|
|
digest="$(grep -o '"containerimage\.digest"[[:space:]]*:[[:space:]]*"sha256:[^"]*"' "$metadata_file" | grep -o 'sha256:[^"]*')"
|
2026-06-14 05:52:49 +05:30
|
|
|
test -n "$digest"
|
2026-06-17 03:28:45 +05:30
|
|
|
printf '%s@%s\n' "$REGISTRY_HOST/$REGISTRY_NAMESPACE/nxtgauge-admin-solid" "$digest" > /tmp/admin-solid-image-ref.txt
|
2026-06-14 05:52:49 +05:30
|
|
|
|
|
|
|
|
- name: Prune old SHA tags
|
2026-05-01 10:10:30 +02:00
|
|
|
if: success()
|
|
|
|
|
continue-on-error: true
|
|
|
|
|
env:
|
2026-06-17 03:28:45 +05:30
|
|
|
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
|
|
|
|
|
REGISTRY_NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'ashwin' }}
|
2026-05-01 10:10:30 +02:00
|
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
|
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
2026-07-17 05:37:45 +05:30
|
|
|
SHA: ${{ github.sha }}
|
2026-05-01 10:10:30 +02:00
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-06-11 17:17:42 +05:30
|
|
|
python3 .forgejo/scripts/registry_prune.py \
|
2026-05-01 10:10:30 +02:00
|
|
|
--registry "$REGISTRY_HOST" \
|
2026-06-17 03:28:45 +05:30
|
|
|
--repo "$REGISTRY_NAMESPACE/nxtgauge-admin-solid" \
|
2026-05-01 10:10:30 +02:00
|
|
|
--username "$REGISTRY_USERNAME" \
|
|
|
|
|
--password "$REGISTRY_PASSWORD" \
|
2026-07-17 05:37:45 +05:30
|
|
|
--protect "$SHA" \
|
2026-06-14 05:52:49 +05:30
|
|
|
--keep 2
|
2026-05-01 11:04:23 +02:00
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
- name: Update GitOps release
|
2026-05-01 11:04:23 +02:00
|
|
|
env:
|
2026-07-12 23:00:58 +05:30
|
|
|
GITOPS_GITHUB_OWNER: ${{ secrets.GITOPS_GITHUB_OWNER || 'Traceworks2023' }}
|
2026-07-12 18:37:20 +05:30
|
|
|
GITOPS_REPO: ${{ secrets.GITOPS_REPO || 'nxtgauge-gitops' }}
|
|
|
|
|
GITOPS_BRANCH: ${{ secrets.GITOPS_BRANCH || 'main' }}
|
2026-07-12 23:00:58 +05:30
|
|
|
# GitHub is the source of truth for nxtgauge-gitops. Push there;
|
|
|
|
|
# the repo's own sync-to-forgejo.yml GitHub Action relays the
|
|
|
|
|
# commit to Forgejo, which is what Flux (flux-system GitRepository)
|
|
|
|
|
# actually watches. Do not push straight to Forgejo here - that
|
|
|
|
|
# bypasses GitHub as source of truth.
|
|
|
|
|
GITOPS_GITHUB_TOKEN: ${{ secrets.GITOPS_GITHUB_TOKEN }}
|
2026-06-14 05:52:49 +05:30
|
|
|
SHA: ${{ github.sha }}
|
2026-05-01 11:04:23 +02:00
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-07-12 23:00:58 +05:30
|
|
|
test -n "${GITOPS_GITHUB_TOKEN:-}" || { echo "GITOPS_GITHUB_TOKEN is empty"; exit 1; }
|
2026-05-01 11:04:23 +02:00
|
|
|
|
2026-07-12 18:37:20 +05:30
|
|
|
GITOPS_DIR=$(mktemp -d)
|
2026-07-12 23:00:58 +05:30
|
|
|
git clone "https://${GITOPS_GITHUB_OWNER}:${GITOPS_GITHUB_TOKEN}@github.com/${GITOPS_GITHUB_OWNER}/${GITOPS_REPO}.git" "$GITOPS_DIR"
|
2026-07-12 18:37:20 +05:30
|
|
|
cd "$GITOPS_DIR"
|
|
|
|
|
git checkout "$GITOPS_BRANCH"
|
2026-05-01 11:04:23 +02:00
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
image_ref="$(cat /tmp/admin-solid-image-ref.txt)"
|
|
|
|
|
./scripts/set-app-release.sh admin-solid "$image_ref"
|
2026-05-01 11:04:23 +02:00
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
if git diff --quiet; then
|
|
|
|
|
echo "GitOps repo already up to date."
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
2026-05-01 11:04:23 +02:00
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
git config user.name "forgejo-actions[bot]"
|
|
|
|
|
git config user.email "forgejo-actions@ci.nxtgauge.com"
|
|
|
|
|
git add apps scripts/set-app-release.sh
|
|
|
|
|
git commit -m "chore(gitops): deploy admin-solid@${SHA}"
|
2026-07-12 18:37:20 +05:30
|
|
|
git push origin "HEAD:${GITOPS_BRANCH}"
|