nxtgauge-admin-solid/.forgejo/workflows/build.yaml

133 lines
5.2 KiB
YAML
Raw Normal View History

name: build-and-release
2026-04-19 00:02:55 +02:00
on:
push:
branches:
- main
- high-performance
concurrency:
group: admin-solid-build-${{ github.ref }}
cancel-in-progress: true
2026-04-19 00:02:55 +02:00
jobs:
build:
runs-on: docker-ready
env:
DOCKER_BUILDKIT: "1"
2026-04-19 00:02:55 +02:00
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
2026-04-19 00:02:55 +02:00
- 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"
- name: Set up Docker Buildx
2026-04-19 18:06:45 +02:00
run: |
set -euo pipefail
for attempt in $(seq 1 30); do
if docker version >/dev/null 2>&1; then
break
fi
sleep 2
done
docker version
docker buildx create --use --name nxtgauge-builder || docker buildx use nxtgauge-builder
2026-04-19 18:06:45 +02:00
docker buildx inspect --bootstrap
- name: Login to registry
env:
2026-06-17 03:28:45 +05:30
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
REGISTRY_NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'ashwin' }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
2026-04-19 18:06:45 +02:00
run: |
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
- name: Build and push image
env:
2026-06-17 03:28:45 +05:30
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
REGISTRY_NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'ashwin' }}
SHA: ${{ github.sha }}
2026-04-19 18:06:45 +02:00
run: |
set -euo pipefail
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-04-19 18:06:45 +02:00
docker buildx build --push \
--metadata-file "$metadata_file" \
2026-04-19 18:06:45 +02:00
-f Dockerfile \
-t "$image_ref" \
2026-04-19 18:06:45 +02:00
.
digest="$(grep -o '"containerimage\.digest"[[:space:]]*:[[:space:]]*"sha256:[^"]*"' "$metadata_file" | grep -o 'sha256:[^"]*')"
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
- name: Prune old SHA tags
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' }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
set -euo pipefail
2026-06-11 17:17:42 +05:30
python3 .forgejo/scripts/registry_prune.py \
--registry "$REGISTRY_HOST" \
2026-06-17 03:28:45 +05:30
--repo "$REGISTRY_NAMESPACE/nxtgauge-admin-solid" \
--username "$REGISTRY_USERNAME" \
--password "$REGISTRY_PASSWORD" \
--keep 2
- name: Update GitOps release
env:
GITOPS_GITHUB_OWNER: ${{ secrets.GITOPS_GITHUB_OWNER || 'Traceworks2023' }}
GITOPS_REPO: ${{ secrets.GITOPS_REPO || 'nxtgauge-gitops' }}
GITOPS_BRANCH: ${{ secrets.GITOPS_BRANCH || 'main' }}
# 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 }}
SHA: ${{ github.sha }}
run: |
set -euo pipefail
test -n "${GITOPS_GITHUB_TOKEN:-}" || { echo "GITOPS_GITHUB_TOKEN is empty"; exit 1; }
GITOPS_DIR=$(mktemp -d)
git clone "https://${GITOPS_GITHUB_OWNER}:${GITOPS_GITHUB_TOKEN}@github.com/${GITOPS_GITHUB_OWNER}/${GITOPS_REPO}.git" "$GITOPS_DIR"
cd "$GITOPS_DIR"
git checkout "$GITOPS_BRANCH"
image_ref="$(cat /tmp/admin-solid-image-ref.txt)"
./scripts/set-app-release.sh admin-solid "$image_ref"
if git diff --quiet; then
echo "GitOps repo already up to date."
exit 0
fi
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}"
git push origin "HEAD:${GITOPS_BRANCH}"