|
|
|
@@ -16,7 +16,7 @@ permissions:
|
|
|
|
|
security-events: write
|
|
|
|
|
|
|
|
|
|
env:
|
|
|
|
|
REGISTRY: ghcr.io
|
|
|
|
|
REGISTRY: git.farh.net
|
|
|
|
|
IMAGE_NAME: cartsnitch/cartsnitch
|
|
|
|
|
RECEIPTWITNESS_IMAGE_NAME: cartsnitch/receiptwitness
|
|
|
|
|
API_IMAGE_NAME: cartsnitch/api
|
|
|
|
@@ -26,11 +26,7 @@ jobs:
|
|
|
|
|
lint:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/setup-node@v4
|
|
|
|
|
with:
|
|
|
|
|
node-version: "20"
|
|
|
|
|
cache: npm
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
- run: npm ci
|
|
|
|
|
- name: ESLint
|
|
|
|
|
run: npx eslint .
|
|
|
|
@@ -40,8 +36,8 @@ jobs:
|
|
|
|
|
test:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/setup-node@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
|
|
|
|
with:
|
|
|
|
|
node-version: "20"
|
|
|
|
|
cache: npm
|
|
|
|
@@ -52,8 +48,8 @@ jobs:
|
|
|
|
|
audit:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/setup-node@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
|
|
|
|
with:
|
|
|
|
|
node-version: "20"
|
|
|
|
|
cache: npm
|
|
|
|
@@ -64,8 +60,8 @@ jobs:
|
|
|
|
|
e2e:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/setup-node@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
|
|
|
|
with:
|
|
|
|
|
node-version: "20"
|
|
|
|
|
cache: npm
|
|
|
|
@@ -77,8 +73,8 @@ jobs:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
needs: [test]
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/setup-node@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
|
|
|
|
with:
|
|
|
|
|
node-version: "20"
|
|
|
|
|
cache: npm
|
|
|
|
@@ -106,7 +102,7 @@ jobs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
@@ -134,13 +130,13 @@ jobs:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to GHCR
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata
|
|
|
|
|
id: meta
|
|
|
|
@@ -160,8 +156,8 @@ jobs:
|
|
|
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
target: prod
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-to: type=gha,mode=max
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
cache-to: type=inline,mode=max
|
|
|
|
|
|
|
|
|
|
- name: Scan frontend image for vulnerabilities
|
|
|
|
|
uses: anchore/scan-action@v5
|
|
|
|
@@ -175,7 +171,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -186,7 +182,7 @@ jobs:
|
|
|
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
target: prod
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
|
|
|
|
|
- name: Create git tag
|
|
|
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
|
|
@@ -202,7 +198,7 @@ jobs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
@@ -224,13 +220,13 @@ jobs:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to GHCR
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata
|
|
|
|
|
id: meta
|
|
|
|
@@ -252,8 +248,8 @@ jobs:
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-to: type=gha,mode=max
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
cache-to: type=inline,mode=max
|
|
|
|
|
|
|
|
|
|
- name: Scan receiptwitness image for vulnerabilities
|
|
|
|
|
uses: anchore/scan-action@v5
|
|
|
|
@@ -267,7 +263,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -280,7 +276,7 @@ jobs:
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
|
|
|
|
|
build-and-push-api:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
@@ -290,7 +286,7 @@ jobs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
@@ -312,13 +308,13 @@ jobs:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to GHCR
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata (API)
|
|
|
|
|
id: meta
|
|
|
|
@@ -340,8 +336,8 @@ jobs:
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-to: type=gha,mode=max
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
cache-to: type=inline,mode=max
|
|
|
|
|
|
|
|
|
|
- name: Scan api image for vulnerabilities
|
|
|
|
|
uses: anchore/scan-action@v5
|
|
|
|
@@ -355,7 +351,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -368,7 +364,7 @@ jobs:
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
|
|
|
|
|
build-and-push-auth:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
@@ -378,7 +374,7 @@ jobs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
@@ -400,13 +396,13 @@ jobs:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to GHCR
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata (auth)
|
|
|
|
|
id: meta
|
|
|
|
@@ -428,8 +424,8 @@ jobs:
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-to: type=gha,mode=max
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
cache-to: type=inline,mode=max
|
|
|
|
|
|
|
|
|
|
- name: Scan auth image for vulnerabilities
|
|
|
|
|
uses: anchore/scan-action@v5
|
|
|
|
@@ -443,7 +439,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -456,7 +452,7 @@ jobs:
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=gha
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
|
|
|
|
|
deploy-dev:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
@@ -464,10 +460,10 @@ jobs:
|
|
|
|
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
|
|
|
|
|
steps:
|
|
|
|
|
- name: Checkout infra repo
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
repository: cartsnitch/infra
|
|
|
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
token: ${{ secrets.CI_GITEA_TOKEN }}
|
|
|
|
|
ref: main
|
|
|
|
|
path: infra
|
|
|
|
|
|
|
|
|
@@ -475,7 +471,16 @@ jobs:
|
|
|
|
|
uses: azure/setup-kubectl@v4
|
|
|
|
|
|
|
|
|
|
- name: Install kustomize
|
|
|
|
|
uses: imranismail/setup-kustomize@v2
|
|
|
|
|
# imranismail/setup-kustomize@v2 calls the Gitea API to record
|
|
|
|
|
# telemetry under the "kubernetes-sigs" user, which doesn't exist
|
|
|
|
|
# on this Gitea instance. Install the binary directly instead.
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
version="5.4.3"
|
|
|
|
|
url="https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${version}/kustomize_v${version}_linux_amd64.tar.gz"
|
|
|
|
|
curl -fsSL --retry 3 "$url" | tar -xz -C /tmp kustomize
|
|
|
|
|
sudo install -m 0755 /tmp/kustomize /usr/local/bin/kustomize
|
|
|
|
|
kustomize version
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for frontend
|
|
|
|
|
id: frontend_tag
|
|
|
|
@@ -490,7 +495,7 @@ jobs:
|
|
|
|
|
if: needs.build-and-push.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/dev
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/cartsnitch:${{ steps.frontend_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/cartsnitch=git.farh.net/cartsnitch/cartsnitch:${{ steps.frontend_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for receiptwitness
|
|
|
|
|
id: receiptwitness_tag
|
|
|
|
@@ -505,7 +510,7 @@ jobs:
|
|
|
|
|
if: needs.build-and-push-receiptwitness.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/dev
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/receiptwitness:${{ steps.receiptwitness_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/receiptwitness=git.farh.net/cartsnitch/receiptwitness:${{ steps.receiptwitness_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for api
|
|
|
|
|
id: api_tag
|
|
|
|
@@ -520,7 +525,7 @@ jobs:
|
|
|
|
|
if: needs.build-and-push-api.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/dev
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/api:${{ steps.api_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/api=git.farh.net/cartsnitch/api:${{ steps.api_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for auth
|
|
|
|
|
id: auth_tag
|
|
|
|
@@ -535,18 +540,45 @@ jobs:
|
|
|
|
|
if: needs.build-and-push-auth.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/dev
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/auth:${{ steps.auth_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/auth=git.farh.net/cartsnitch/auth:${{ steps.auth_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Commit and push to infra
|
|
|
|
|
- name: Commit and push to infra (via PR)
|
|
|
|
|
env:
|
|
|
|
|
CI_GITEA_TOKEN: ${{ secrets.CI_GITEA_TOKEN }}
|
|
|
|
|
run: |
|
|
|
|
|
cd infra
|
|
|
|
|
git config user.name "cartsnitch-ci[bot]"
|
|
|
|
|
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
|
|
|
|
git config user.email "cartsnitch-ci[bot]@users.noreply.git.farh.net"
|
|
|
|
|
git add apps/overlays/dev/kustomization.yaml
|
|
|
|
|
git diff --cached --quiet && echo "No image changes to deploy" && exit 0
|
|
|
|
|
BRANCH="ci/deploy-dev-${GITHUB_SHA}"
|
|
|
|
|
git checkout -b "$BRANCH"
|
|
|
|
|
git commit -m "ci(dev): update cartsnitch, receiptwitness, api, and auth images"
|
|
|
|
|
git pull --rebase origin main
|
|
|
|
|
git push origin main
|
|
|
|
|
git push origin "$BRANCH"
|
|
|
|
|
PR_BODY=$(printf 'Auto-opened by deploy-dev (CAR-1195).\n\nBuild SHA: %s' "${GITHUB_SHA}")
|
|
|
|
|
PR_JSON=$(curl -sS -X POST \
|
|
|
|
|
-H "Authorization: token ${CI_GITEA_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d "$(jq -n --arg head "cartsnitch:${BRANCH}" --arg base main --arg title "ci(dev): update overlay image tags (${GITHUB_SHA::12})" --arg body "$PR_BODY" '{head:$head,base:$base,title:$title,body:$body}')" \
|
|
|
|
|
"https://git.farh.net/api/v1/repos/cartsnitch/infra/pulls")
|
|
|
|
|
PR_NUM=$(echo "$PR_JSON" | jq -r '.number // empty')
|
|
|
|
|
if [ -z "$PR_NUM" ]; then
|
|
|
|
|
echo "::error::Failed to open PR against cartsnitch/infra: $PR_JSON"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo "Opened cartsnitch/infra PR #${PR_NUM} (head=${BRANCH})"
|
|
|
|
|
MERGE_RESP=$(curl -sS -X POST \
|
|
|
|
|
-H "Authorization: token ${CI_GITEA_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d '{"Do":"merge","delete_branch_after_merge":true}' \
|
|
|
|
|
"https://git.farh.net/api/v1/repos/cartsnitch/infra/pulls/${PR_NUM}/merge")
|
|
|
|
|
MERGED=$(echo "$MERGE_RESP" | jq -r '.merged // false')
|
|
|
|
|
if [ "$MERGED" != "true" ]; then
|
|
|
|
|
echo "::error::Auto-merge of cartsnitch/infra PR #${PR_NUM} failed: $MERGE_RESP"
|
|
|
|
|
echo "::error::Reassign to cs_savannah (authorized merger for cartsnitch/infra main) for backstop merge."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo "PR #${PR_NUM} merged into cartsnitch/infra main"
|
|
|
|
|
|
|
|
|
|
deploy-uat:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
@@ -554,10 +586,10 @@ jobs:
|
|
|
|
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main')
|
|
|
|
|
steps:
|
|
|
|
|
- name: Checkout infra repo
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
repository: cartsnitch/infra
|
|
|
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
token: ${{ secrets.CI_GITEA_TOKEN }}
|
|
|
|
|
ref: main
|
|
|
|
|
path: infra
|
|
|
|
|
|
|
|
|
@@ -565,7 +597,16 @@ jobs:
|
|
|
|
|
uses: azure/setup-kubectl@v4
|
|
|
|
|
|
|
|
|
|
- name: Install kustomize
|
|
|
|
|
uses: imranismail/setup-kustomize@v2
|
|
|
|
|
# imranismail/setup-kustomize@v2 calls the Gitea API to record
|
|
|
|
|
# telemetry under the "kubernetes-sigs" user, which doesn't exist
|
|
|
|
|
# on this Gitea instance. Install the binary directly instead.
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
version="5.4.3"
|
|
|
|
|
url="https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${version}/kustomize_v${version}_linux_amd64.tar.gz"
|
|
|
|
|
curl -fsSL --retry 3 "$url" | tar -xz -C /tmp kustomize
|
|
|
|
|
sudo install -m 0755 /tmp/kustomize /usr/local/bin/kustomize
|
|
|
|
|
kustomize version
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for frontend
|
|
|
|
|
id: frontend_tag
|
|
|
|
@@ -580,7 +621,7 @@ jobs:
|
|
|
|
|
if: needs.build-and-push.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/uat
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/cartsnitch:${{ steps.frontend_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/cartsnitch=git.farh.net/cartsnitch/cartsnitch:${{ steps.frontend_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for receiptwitness
|
|
|
|
|
id: receiptwitness_tag
|
|
|
|
@@ -595,7 +636,7 @@ jobs:
|
|
|
|
|
if: needs.build-and-push-receiptwitness.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/uat
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/receiptwitness:${{ steps.receiptwitness_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/receiptwitness=git.farh.net/cartsnitch/receiptwitness:${{ steps.receiptwitness_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for api
|
|
|
|
|
id: api_tag
|
|
|
|
@@ -610,7 +651,7 @@ jobs:
|
|
|
|
|
if: needs.build-and-push-api.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/uat
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/api:${{ steps.api_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/api=git.farh.net/cartsnitch/api:${{ steps.api_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Determine image tag for auth
|
|
|
|
|
id: auth_tag
|
|
|
|
@@ -625,15 +666,42 @@ jobs:
|
|
|
|
|
if: needs.build-and-push-auth.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/uat
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/auth:${{ steps.auth_tag.outputs.tag }}
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/auth=git.farh.net/cartsnitch/auth:${{ steps.auth_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- name: Commit and push to infra
|
|
|
|
|
- name: Commit and push to infra (via PR)
|
|
|
|
|
env:
|
|
|
|
|
CI_GITEA_TOKEN: ${{ secrets.CI_GITEA_TOKEN }}
|
|
|
|
|
run: |
|
|
|
|
|
cd infra
|
|
|
|
|
git config user.name "cartsnitch-ci[bot]"
|
|
|
|
|
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
|
|
|
|
git config user.email "cartsnitch-ci[bot]@users.noreply.git.farh.net"
|
|
|
|
|
git add apps/overlays/uat/kustomization.yaml
|
|
|
|
|
git diff --cached --quiet && echo "No image changes to deploy" && exit 0
|
|
|
|
|
BRANCH="ci/deploy-uat-${GITHUB_SHA}"
|
|
|
|
|
git checkout -b "$BRANCH"
|
|
|
|
|
git commit -m "ci(uat): update cartsnitch, receiptwitness, api, and auth images"
|
|
|
|
|
git pull --rebase origin main
|
|
|
|
|
git push origin main
|
|
|
|
|
git push origin "$BRANCH"
|
|
|
|
|
PR_BODY=$(printf 'Auto-opened by deploy-uat (CAR-1195).\n\nBuild SHA: %s' "${GITHUB_SHA}")
|
|
|
|
|
PR_JSON=$(curl -sS -X POST \
|
|
|
|
|
-H "Authorization: token ${CI_GITEA_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d "$(jq -n --arg head "cartsnitch:${BRANCH}" --arg base main --arg title "ci(uat): update overlay image tags (${GITHUB_SHA::12})" --arg body "$PR_BODY" '{head:$head,base:$base,title:$title,body:$body}')" \
|
|
|
|
|
"https://git.farh.net/api/v1/repos/cartsnitch/infra/pulls")
|
|
|
|
|
PR_NUM=$(echo "$PR_JSON" | jq -r '.number // empty')
|
|
|
|
|
if [ -z "$PR_NUM" ]; then
|
|
|
|
|
echo "::error::Failed to open PR against cartsnitch/infra: $PR_JSON"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo "Opened cartsnitch/infra PR #${PR_NUM} (head=${BRANCH})"
|
|
|
|
|
MERGE_RESP=$(curl -sS -X POST \
|
|
|
|
|
-H "Authorization: token ${CI_GITEA_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d '{"Do":"merge","delete_branch_after_merge":true}' \
|
|
|
|
|
"https://git.farh.net/api/v1/repos/cartsnitch/infra/pulls/${PR_NUM}/merge")
|
|
|
|
|
MERGED=$(echo "$MERGE_RESP" | jq -r '.merged // false')
|
|
|
|
|
if [ "$MERGED" != "true" ]; then
|
|
|
|
|
echo "::error::Auto-merge of cartsnitch/infra PR #${PR_NUM} failed: $MERGE_RESP"
|
|
|
|
|
echo "::error::Reassign to cs_savannah (authorized merger for cartsnitch/infra main) for backstop merge."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo "PR #${PR_NUM} merged into cartsnitch/infra main"
|