From 7dfa08f148cbddafa74cc38500d60a9d9917976c Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Sun, 14 Jun 2026 22:48:56 +0530 Subject: [PATCH] ci: deploy admin via github actions and ghcr --- .github/workflows/build-and-deploy-ghcr.yml | 90 +++++++++++++++++++++ .github/workflows/sync-to-forgejo.yml | 40 --------- Dockerfile | 2 +- 3 files changed, 91 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/build-and-deploy-ghcr.yml delete mode 100644 .github/workflows/sync-to-forgejo.yml diff --git a/.github/workflows/build-and-deploy-ghcr.yml b/.github/workflows/build-and-deploy-ghcr.yml new file mode 100644 index 0000000..7dedd11 --- /dev/null +++ b/.github/workflows/build-and-deploy-ghcr.yml @@ -0,0 +1,90 @@ +name: build-and-deploy-ghcr + +on: + push: + branches: + - main + - high-performance + workflow_dispatch: + +permissions: + contents: read + packages: write + +env: + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} + K8S_NAMESPACE: nxtgauge + DEPLOYMENT_NAME: nxtgauge-admin-solid + CONTAINER_NAME: admin-solid + APP_KEY: admin-solid + GITOPS_REPO: Traceworks2023/nxtgauge-gitops + +jobs: + build-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USERNAME }} + password: ${{ secrets.DEPLOY_GITHUB_TOKEN }} + + - name: Build and push image + id: build + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + push: true + platforms: linux/amd64 + tags: ${{ env.IMAGE_NAME }}:${{ github.sha }} + + - name: Configure kubeconfig + run: | + set -euo pipefail + mkdir -p ~/.kube + printf '%s' '${{ secrets.KUBE_CONFIG_DATA }}' | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + + - name: Install kubectl + uses: azure/setup-kubectl@v4 + + - name: Deploy to Kubernetes + env: + GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }} + GHCR_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }} + run: | + set -euo pipefail + image_ref="${IMAGE_NAME}@${{ steps.build.outputs.digest }}" + kubectl -n "$K8S_NAMESPACE" create secret docker-registry ghcr-regcred --docker-server=ghcr.io --docker-username="$GHCR_USERNAME" --docker-password="$GHCR_TOKEN" --dry-run=client -o yaml | kubectl apply -f - + kubectl -n "$K8S_NAMESPACE" patch deployment "$DEPLOYMENT_NAME" --type merge -p '{"spec":{"template":{"spec":{"imagePullSecrets":[{"name":"ghcr-regcred"}]}}}}' + kubectl -n "$K8S_NAMESPACE" set image deployment/"$DEPLOYMENT_NAME" "$CONTAINER_NAME"="$image_ref" + kubectl -n "$K8S_NAMESPACE" rollout status deployment/"$DEPLOYMENT_NAME" --timeout=10m + + - name: Sync GitOps release + env: + GITOPS_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }} + run: | + set -euo pipefail + image_ref="${IMAGE_NAME}@${{ steps.build.outputs.digest }}" + git clone "https://${{ secrets.GHCR_USERNAME }}:${GITOPS_TOKEN}@github.com/${GITOPS_REPO}.git" /tmp/nxtgauge-gitops + cd /tmp/nxtgauge-gitops + ./scripts/set-app-release.sh "$APP_KEY" "$image_ref" + if git diff --quiet; then + echo "GitOps repo already up to date." + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add apps scripts/set-app-release.sh + git commit -m "chore(gitops): deploy ${APP_KEY}@${{ github.sha }}" + git push origin HEAD:main diff --git a/.github/workflows/sync-to-forgejo.yml b/.github/workflows/sync-to-forgejo.yml deleted file mode 100644 index 354a407..0000000 --- a/.github/workflows/sync-to-forgejo.yml +++ /dev/null @@ -1,40 +0,0 @@ -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; } - - AUTH="$(printf '%s' "${FORGEJO_USERNAME}:${FORGEJO_SECRET}" | base64 -w0)" - TARGET="https://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 -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push forgejo "HEAD:${BRANCH}" --force - git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push forgejo --tags --force diff --git a/Dockerfile b/Dockerfile index 7248b86..c8a9997 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ ENV NODE_OPTIONS="--max-old-space-size=4096" RUN npm run build # Runtime stage -FROM registry.nxtgauge.com/node:20-alpine +FROM node:20-alpine WORKDIR /app # Copy built output