Some checks failed
build-and-release / build (push) Failing after 1m17s
Same fix as nxtgauge-backend-rust and nxtgauge-frontend-solid: every build here has been failing with "Cannot connect to the Docker daemon at tcp://127.0.0.1:2375" since the job container is nested inside the runner pod's dind sidecar. Detect the real gateway from /proc/net/route instead of hardcoding loopback.
130 lines
4.7 KiB
YAML
130 lines
4.7 KiB
YAML
name: build-and-release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- high-performance
|
|
|
|
concurrency:
|
|
group: admin-solid-build-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: docker-ready
|
|
env:
|
|
DOCKER_BUILDKIT: "1"
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- 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
|
|
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
|
|
docker buildx inspect --bootstrap
|
|
|
|
- name: Login to registry
|
|
env:
|
|
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
|
|
test -n "$REGISTRY_HOST"
|
|
printf '%s' "$REGISTRY_PASSWORD" | docker login "$REGISTRY_HOST" -u "$REGISTRY_USERNAME" --password-stdin
|
|
|
|
- name: Build and push image
|
|
env:
|
|
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST || 'ci.nxtgauge.com' }}
|
|
REGISTRY_NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'ashwin' }}
|
|
SHA: ${{ github.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
metadata_file="/tmp/admin-solid-metadata.json"
|
|
image_ref="$REGISTRY_HOST/$REGISTRY_NAMESPACE/nxtgauge-admin-solid:$SHA"
|
|
|
|
docker buildx build --push \
|
|
--metadata-file "$metadata_file" \
|
|
-f Dockerfile \
|
|
-t "$image_ref" \
|
|
.
|
|
|
|
digest="$(grep -o '"containerimage.digest":"sha256:[^"]*"' "$metadata_file" | cut -d'"' -f4)"
|
|
test -n "$digest"
|
|
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:
|
|
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
|
|
python3 .forgejo/scripts/registry_prune.py \
|
|
--registry "$REGISTRY_HOST" \
|
|
--repo "$REGISTRY_NAMESPACE/nxtgauge-admin-solid" \
|
|
--username "$REGISTRY_USERNAME" \
|
|
--password "$REGISTRY_PASSWORD" \
|
|
--keep 2
|
|
|
|
- name: Update GitOps release
|
|
env:
|
|
GITEOPS_REPO: ${{ secrets.GITEOPS_REPO }}
|
|
GITEOPS_SSH_KEY: ${{ secrets.GITEOPS_SSH_KEY }}
|
|
SHA: ${{ github.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "$GITEOPS_REPO"
|
|
test -n "$GITEOPS_SSH_KEY"
|
|
|
|
mkdir -p ~/.ssh
|
|
printf '%s\n' "$GITEOPS_SSH_KEY" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
for host in github.com ci.nxtgauge.com; do ssh-keyscan -H "$host" >> ~/.ssh/known_hosts 2>/dev/null || true; done
|
|
|
|
GITEOPS_DIR=$(mktemp -d)
|
|
git clone "$GITEOPS_REPO" "$GITEOPS_DIR"
|
|
cd "$GITEOPS_DIR"
|
|
|
|
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
|