fix: restore forgejo build workflow filename

This commit is contained in:
Ashwin Kumar Sivakumar 2026-06-12 21:54:48 +05:30
parent 82ea154c9f
commit 6887e64ddb

View file

@ -1,4 +1,4 @@
name: build-and-push name: Build Frontend And Update GitOps
on: on:
push: push:
@ -15,97 +15,57 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Install Docker CLI
run: | run: |
export DOCKER_HOST=unix:///var/run/docker.sock apt-get update
docker version apt-get install -y docker.io
docker buildx create --use || true
docker buildx inspect --bootstrap
- name: Login to Registry - name: Log in to registry
env: run: |
REGISTRY_HOSTPORT: ${{ secrets.REGISTRY_HOSTPORT }} echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.nxtgauge.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} - name: Build and push frontend image
run: | run: |
set -euo pipefail set -euo pipefail
export DOCKER_HOST=unix:///var/run/docker.sock IMAGE="registry.nxtgauge.com/nxtgauge-frontend-solid:${{ github.sha }}"
test -n "$REGISTRY_HOSTPORT" docker build -t "${IMAGE}" -t registry.nxtgauge.com/nxtgauge-frontend-solid:latest .
echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_HOSTPORT" -u "$REGISTRY_USERNAME" --password-stdin docker push "${IMAGE}"
docker push registry.nxtgauge.com/nxtgauge-frontend-solid:latest
- name: Build and push update-gitops:
needs: build
runs-on: ubuntu-latest
steps:
- name: Update GitOps frontend tag
env: env:
REGISTRY_HOSTPORT: ${{ secrets.REGISTRY_HOSTPORT }} GITOPS_USERNAME: ${{ secrets.GITOPS_GITHUB_USERNAME || 'Traceworks2023' }}
GITOPS_PASSWORD: ${{ secrets.GITOPS_GITHUB_TOKEN || secrets.GITOPS_PAT }}
GITOPS_REPO: https://github.com/Traceworks2023/nxtgauge-gitops.git
IMAGE_TAG: ${{ github.sha }}
run: | run: |
set -euo pipefail set -euo pipefail
export DOCKER_HOST=unix:///var/run/docker.sock test -n "${GITOPS_PASSWORD:-}" || { echo "GITOPS_PASSWORD is empty"; exit 1; }
AUTH="$(printf '%s' "${GITOPS_USERNAME}:${GITOPS_PASSWORD}" | base64 -w0)"
build_and_push() { TMP_DIR="$(mktemp -d)"
docker buildx build --push \ git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" clone --branch main "${GITOPS_REPO}" "${TMP_DIR}"
-f Dockerfile \ cd "${TMP_DIR}"
-t "$REGISTRY_HOSTPORT/nxtgauge-frontend-solid:${{ gitea.sha }}" \ python3 - <<'PY'
-t "$REGISTRY_HOSTPORT/nxtgauge-frontend-solid:high-performance-latest" \ from pathlib import Path
. import os
} path = Path('apps/nxtgauge-frontend-solid/overlays/prod/kustomization.yaml')
lines = path.read_text().splitlines()
for attempt in 1 2 3; do out = []
echo "Build attempt $attempt" for line in lines:
if build_and_push; then if line.strip().startswith('newTag:'):
exit 0 indent = line[:len(line) - len(line.lstrip())]
fi out.append(f"{indent}newTag: {os.environ['IMAGE_TAG']}")
echo "Build attempt $attempt failed; recreating builder and retrying" else:
docker buildx rm --all-inactive --force || true out.append(line)
docker buildx create --use || true path.write_text('\n'.join(out) + '\n')
docker buildx inspect --bootstrap PY
sleep $((attempt * 10)) git config user.name "forgejo-actions"
done git config user.email "forgejo-actions@nxtgauge.com"
git add apps/nxtgauge-frontend-solid/overlays/prod/kustomization.yaml
echo "Build failed after retries" git diff --cached --quiet && exit 0
exit 1 git commit -m "chore(gitops): update frontend image to ${IMAGE_TAG}"
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push origin main
- name: Prune old image tags (keep latest 1 SHA)
if: success()
continue-on-error: true
env:
REGISTRY_HOST: ${{ secrets.REGISTRY_HOSTPORT }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
set -euo pipefail
python3 .gitea/scripts/registry_prune.py \
--registry "$REGISTRY_HOST" \
--repo "nxtgauge-frontend-solid" \
--username "$REGISTRY_USERNAME" \
--password "$REGISTRY_PASSWORD" \
--keep 1
- name: Update GitOps and trigger deployment
if: success()
continue-on-error: true
env:
GITEOPS_REPO: ${{ secrets.GITEOPS_REPO }}
GITEOPS_SSH_KEY: ${{ secrets.GITEOPS_SSH_KEY }}
run: |
set -euo pipefail
if [ -z "$GITEOPS_REPO" ]; then
echo "GITEOPS_REPO secret not set, skipping GitOps update"
exit 0
fi
GITEOPS_DIR=$(mktemp -d)
git clone "$GITEOPS_REPO" "$GITEOPS_DIR"
cd "$GITEOPS_DIR"
mkdir -p ~/.ssh
echo "$GITEOPS_SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
python3 .gitea/scripts/update-gitops.py \
--repo "$GITEOPS_DIR" \
--service "frontend-solid" \
--sha "${{ gitea.sha }}" \
--message "chore: deploy frontend-solid@${{ gitea.sha }}"
rm -rf "$GITEOPS_DIR"