2026-06-14 05:52:49 +05:30
|
|
|
name: build-and-release
|
2026-04-19 00:03:05 +02:00
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- main
|
2026-06-14 05:52:49 +05:30
|
|
|
- high-performance
|
|
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
|
group: ai-assistant-build-${{ github.ref }}
|
|
|
|
|
cancel-in-progress: true
|
2026-04-19 00:03:05 +02:00
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
build:
|
2026-07-02 06:51:03 +05:30
|
|
|
runs-on: docker-ready
|
|
|
|
|
env:
|
|
|
|
|
DOCKER_BUILDKIT: "1"
|
2026-04-19 00:03:05 +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:03:05 +02:00
|
|
|
|
2026-07-16 22:01:25 +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
|
|
|
|
|
# from /proc/net/route instead (the dind engine that spawned it).
|
|
|
|
|
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:11 +02:00
|
|
|
- name: Set up Docker Buildx
|
2026-04-19 18:06:59 +02:00
|
|
|
run: |
|
2026-06-14 05:52:49 +05:30
|
|
|
set -euo pipefail
|
2026-07-02 06:51:03 +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:59 +02:00
|
|
|
docker buildx inspect --bootstrap
|
2026-04-19 00:05:11 +02:00
|
|
|
|
2026-07-16 20:33:14 +05:30
|
|
|
- name: Login to Forgejo registry
|
2026-04-19 18:13:55 +02:00
|
|
|
env:
|
2026-07-16 20:33:14 +05:30
|
|
|
REGISTRY_HOST: ci.nxtgauge.com
|
2026-04-19 18:13:55 +02:00
|
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
|
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
2026-04-19 18:06:59 +02:00
|
|
|
run: |
|
2026-04-19 18:13:55 +02:00
|
|
|
set -euo pipefail
|
2026-07-16 20:33:14 +05:30
|
|
|
printf '%s' "$REGISTRY_PASSWORD" | docker login "$REGISTRY_HOST" -u "$REGISTRY_USERNAME" --password-stdin
|
2026-04-19 00:05:11 +02:00
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
- name: Build and push image
|
2026-04-19 18:13:55 +02:00
|
|
|
env:
|
2026-07-16 20:33:14 +05:30
|
|
|
REGISTRY_HOST: ci.nxtgauge.com
|
2026-06-14 05:52:49 +05:30
|
|
|
SHA: ${{ github.sha }}
|
2026-04-19 18:06:59 +02:00
|
|
|
run: |
|
2026-04-30 22:54:24 +02:00
|
|
|
set -euo pipefail
|
2026-07-16 23:47:59 +05:30
|
|
|
image_ref="$REGISTRY_HOST/ashwin/nxtgauge-ai-assistant:$SHA"
|
2026-07-17 04:49:58 +05:30
|
|
|
metadata_file="/tmp/ai-assistant-metadata.json"
|
2026-07-16 23:47:59 +05:30
|
|
|
|
2026-04-19 18:06:59 +02:00
|
|
|
docker buildx build --push \
|
2026-07-17 04:49:58 +05:30
|
|
|
--metadata-file "$metadata_file" \
|
2026-06-14 05:52:49 +05:30
|
|
|
-t "$image_ref" \
|
2026-07-16 23:47:59 +05:30
|
|
|
-t "$REGISTRY_HOST/ashwin/nxtgauge-ai-assistant:latest" \
|
2026-07-16 20:33:14 +05:30
|
|
|
-f Dockerfile \
|
2026-04-19 18:06:59 +02:00
|
|
|
.
|
2026-05-01 10:10:33 +02:00
|
|
|
|
2026-07-17 04:49:58 +05:30
|
|
|
digest="$(grep -o '"containerimage\.digest"[[:space:]]*:[[:space:]]*"sha256:[^"]*"' "$metadata_file" | grep -o 'sha256:[^"]*')"
|
|
|
|
|
test -n "$digest"
|
|
|
|
|
echo "IMAGE_DIGEST=$digest" >> "$GITHUB_ENV"
|
|
|
|
|
|
2026-07-16 20:33:14 +05:30
|
|
|
- name: Update GitOps
|
2026-06-14 05:52:49 +05:30
|
|
|
env:
|
2026-07-16 23:47:59 +05:30
|
|
|
GITOPS_REPO: https://ci.nxtgauge.com/ashwin/nxtgauge-gitops.git
|
2026-07-16 20:33:14 +05:30
|
|
|
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
|
2026-06-14 05:52:49 +05:30
|
|
|
SHA: ${{ github.sha }}
|
2026-07-17 04:49:58 +05:30
|
|
|
DIGEST: ${{ env.IMAGE_DIGEST }}
|
2026-05-01 11:04:27 +02:00
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-07-17 04:59:56 +05:30
|
|
|
echo "[gitops] DIGEST=${DIGEST:-<empty>} SHA=${SHA:-<empty>}"
|
|
|
|
|
test -n "${DIGEST:-}"
|
2026-07-16 20:33:14 +05:30
|
|
|
apk add --no-cache git
|
2026-07-17 04:59:56 +05:30
|
|
|
echo "[gitops] git installed: $(git --version)"
|
2026-07-16 23:47:59 +05:30
|
|
|
|
2026-07-16 20:33:14 +05:30
|
|
|
git config --global credential.helper '!f() { printf "%s\\n" "username=forgejo-actions"; printf "%s\\n" "password=$GITOPS_TOKEN"; }; f'
|
2026-07-16 23:47:59 +05:30
|
|
|
|
2026-07-16 20:33:14 +05:30
|
|
|
GITOPS_DIR=$(mktemp -d)
|
2026-07-17 04:59:56 +05:30
|
|
|
echo "[gitops] cloning into $GITOPS_DIR"
|
2026-07-16 23:56:05 +05:30
|
|
|
# -b main: this repo's server-side HEAD symref is broken (returns
|
|
|
|
|
# "remote HEAD refers to nonexistent ref" on a plain clone even
|
|
|
|
|
# though refs/heads/main exists) - an explicit branch bypasses
|
|
|
|
|
# HEAD resolution entirely instead of relying on it.
|
|
|
|
|
git clone -b main "$GITOPS_REPO" "$GITOPS_DIR"
|
2026-07-17 04:59:56 +05:30
|
|
|
echo "[gitops] clone done"
|
2026-07-16 20:33:14 +05:30
|
|
|
cd "$GITOPS_DIR"
|
2026-07-16 23:47:59 +05:30
|
|
|
|
2026-07-17 04:49:58 +05:30
|
|
|
# release-patch.yaml pins by digest (@sha256:...), not by mutable
|
|
|
|
|
# tag - Flux's ImageUpdateAutomation previously raced this file via
|
|
|
|
|
# a $imagepolicy marker comment and always won because its
|
|
|
|
|
# alphabetical tag ordering sorted "latest" above any hex SHA,
|
|
|
|
|
# clobbering this step's commits every ~2 minutes. The marker was
|
|
|
|
|
# removed from the file so this CI step is now the sole writer.
|
|
|
|
|
sed -i -E "s#image: ci\.nxtgauge\.com/ashwin/nxtgauge-ai-assistant(:[a-f0-9]+|@sha256:[a-f0-9]+)#image: ci.nxtgauge.com/ashwin/nxtgauge-ai-assistant@${DIGEST}#" apps/nxtgauge-ai-assistant/overlays/prod/release-patch.yaml
|
2026-07-17 04:59:56 +05:30
|
|
|
echo "[gitops] after sed:"
|
|
|
|
|
cat apps/nxtgauge-ai-assistant/overlays/prod/release-patch.yaml
|
2026-07-16 23:47:59 +05:30
|
|
|
|
2026-06-14 05:52:49 +05:30
|
|
|
git config user.name "forgejo-actions[bot]"
|
|
|
|
|
git config user.email "forgejo-actions@ci.nxtgauge.com"
|
2026-07-16 23:47:59 +05:30
|
|
|
git add apps/nxtgauge-ai-assistant/overlays/prod/release-patch.yaml
|
2026-07-17 04:59:56 +05:30
|
|
|
if git diff --cached --quiet; then
|
|
|
|
|
echo "[gitops] no changes to commit"
|
|
|
|
|
else
|
|
|
|
|
echo "[gitops] committing and pushing"
|
|
|
|
|
git commit -m "chore(gitops): deploy ai-assistant@${SHA} (${DIGEST})"
|
|
|
|
|
git push
|
|
|
|
|
echo "[gitops] push exit code: $?"
|
|
|
|
|
fi
|