71 lines
2.5 KiB
YAML
71 lines
2.5 KiB
YAML
name: Build Admin And Update GitOps
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- high-performance
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
DOCKER_HOST: unix:///var/run/docker.sock
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install Docker CLI
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y docker.io
|
|
|
|
- name: Log in to registry
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.nxtgauge.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
|
|
|
- name: Build and push admin image
|
|
run: |
|
|
set -euo pipefail
|
|
IMAGE="registry.nxtgauge.com/nxtgauge-admin-solid:${{ github.sha }}"
|
|
docker build -t "${IMAGE}" -t registry.nxtgauge.com/nxtgauge-admin-solid:latest .
|
|
docker push "${IMAGE}"
|
|
docker push registry.nxtgauge.com/nxtgauge-admin-solid:latest
|
|
|
|
update-gitops:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Update GitOps admin tag
|
|
env:
|
|
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: |
|
|
set -euo pipefail
|
|
test -n "${GITOPS_PASSWORD:-}" || { echo "GITOPS_PASSWORD is empty"; exit 1; }
|
|
AUTH="$(printf '%s' "${GITOPS_USERNAME}:${GITOPS_PASSWORD}" | base64 -w0)"
|
|
TMP_DIR="$(mktemp -d)"
|
|
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" clone --branch main "${GITOPS_REPO}" "${TMP_DIR}"
|
|
cd "${TMP_DIR}"
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
import os
|
|
path = Path('apps/nxtgauge-admin-solid/overlays/prod/kustomization.yaml')
|
|
lines = path.read_text().splitlines()
|
|
out = []
|
|
for line in lines:
|
|
if line.strip().startswith('newTag:'):
|
|
indent = line[:len(line) - len(line.lstrip())]
|
|
out.append(f"{indent}newTag: {os.environ['IMAGE_TAG']}")
|
|
else:
|
|
out.append(line)
|
|
path.write_text('\n'.join(out) + '\n')
|
|
PY
|
|
git config user.name "forgejo-actions"
|
|
git config user.email "forgejo-actions@nxtgauge.com"
|
|
git add apps/nxtgauge-admin-solid/overlays/prod/kustomization.yaml
|
|
git diff --cached --quiet && exit 0
|
|
git commit -m "chore(gitops): update admin image to ${IMAGE_TAG}"
|
|
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push origin main
|