Compare commits
4 commits
high-perfo
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e63f47195e | ||
|
|
bfdea41bd1 | ||
|
|
9c472ce9a5 | ||
|
|
6887e64ddb |
3 changed files with 213 additions and 87 deletions
126
.forgejo/workflows/build.yaml
Normal file
126
.forgejo/workflows/build.yaml
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
name: build-and-push
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- high-performance
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DOCKER_HOST: tcp://docker:2375
|
||||||
|
DOCKER_TLS_CERTDIR: ""
|
||||||
|
services:
|
||||||
|
docker:
|
||||||
|
image: docker:27-dind
|
||||||
|
env:
|
||||||
|
DOCKER_TLS_CERTDIR: ""
|
||||||
|
options: --privileged
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Docker CLI
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y docker.io
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
run: |
|
||||||
|
export DOCKER_HOST=tcp://docker:2375
|
||||||
|
docker version
|
||||||
|
docker buildx create --use || true
|
||||||
|
docker buildx inspect --bootstrap
|
||||||
|
|
||||||
|
- name: Login to Registry
|
||||||
|
env:
|
||||||
|
REGISTRY_HOSTPORT: ${{ secrets.REGISTRY_HOSTPORT }}
|
||||||
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
export DOCKER_HOST=tcp://docker:2375
|
||||||
|
SHA="$(git rev-parse HEAD)"
|
||||||
|
test -n "$REGISTRY_HOSTPORT"
|
||||||
|
echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_HOSTPORT" -u "$REGISTRY_USERNAME" --password-stdin
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
env:
|
||||||
|
REGISTRY_HOSTPORT: ${{ secrets.REGISTRY_HOSTPORT }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
export DOCKER_HOST=tcp://docker:2375
|
||||||
|
SHA="$(git rev-parse HEAD)"
|
||||||
|
|
||||||
|
build_and_push() {
|
||||||
|
docker buildx build --push \
|
||||||
|
-f Dockerfile \
|
||||||
|
-t "$REGISTRY_HOSTPORT/nxtgauge-frontend-solid:${SHA}" \
|
||||||
|
-t "$REGISTRY_HOSTPORT/nxtgauge-frontend-solid:high-performance-latest" \
|
||||||
|
.
|
||||||
|
}
|
||||||
|
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
echo "Build attempt $attempt"
|
||||||
|
if build_and_push; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "Build attempt $attempt failed; recreating builder and retrying"
|
||||||
|
docker buildx rm --all-inactive --force || true
|
||||||
|
docker buildx create --use || true
|
||||||
|
docker buildx inspect --bootstrap
|
||||||
|
sleep $((attempt * 10))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Build failed after retries"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- 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 .forgejo/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
|
||||||
|
SHA="$(git rev-parse HEAD)"
|
||||||
|
|
||||||
|
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 .forgejo/scripts/update-gitops.py \
|
||||||
|
--repo "$GITEOPS_DIR" \
|
||||||
|
--service "frontend-solid" \
|
||||||
|
--sha "${SHA}" \
|
||||||
|
--message "chore: deploy frontend-solid@${SHA}"
|
||||||
|
|
||||||
|
rm -rf "$GITEOPS_DIR"
|
||||||
|
|
@ -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"
|
|
||||||
|
|
|
||||||
40
.github/workflows/sync-to-forgejo.yml
vendored
Normal file
40
.github/workflows/sync-to-forgejo.yml
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
name: sync-to-forgejo
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- high-performance
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Push branch to Forgejo
|
||||||
|
env:
|
||||||
|
FORGEJO_SECRET: ${{ secrets.FORGEJO_SECRET || secrets.GITEA_SECRET }}
|
||||||
|
FORGEJO_OWNER: ${{ secrets.FORGEJO_OWNER || 'ashwin' }}
|
||||||
|
FORGEJO_USERNAME: ${{ secrets.FORGEJO_USERNAME || secrets.GITEA_USERNAME || 'ashwin' }}
|
||||||
|
REPO: ${{ github.event.repository.name }}
|
||||||
|
BRANCH: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
test -n "${FORGEJO_SECRET:-}" || { echo "FORGEJO_SECRET is empty"; exit 1; }
|
||||||
|
|
||||||
|
ENCODED_PASSWORD="$(printf '%s' "${FORGEJO_SECRET}" | jq -sRr @uri)"
|
||||||
|
TARGET="https://${FORGEJO_USERNAME}:${ENCODED_PASSWORD}@ci.nxtgauge.com/${FORGEJO_OWNER}/${REPO}.git"
|
||||||
|
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
git remote remove forgejo 2>/dev/null || true
|
||||||
|
git remote add forgejo "${TARGET}"
|
||||||
|
|
||||||
|
git push forgejo "HEAD:${BRANCH}" --force
|
||||||
|
git push forgejo --tags --force
|
||||||
Loading…
Add table
Reference in a new issue