|
|
|
@@ -20,16 +20,13 @@ env:
|
|
|
|
|
IMAGE_NAME: cartsnitch/cartsnitch
|
|
|
|
|
RECEIPTWITNESS_IMAGE_NAME: cartsnitch/receiptwitness
|
|
|
|
|
API_IMAGE_NAME: cartsnitch/api
|
|
|
|
|
AUTH_IMAGE_NAME: cartsnitch/auth
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
lint:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
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 .
|
|
|
|
@@ -37,10 +34,10 @@ jobs:
|
|
|
|
|
run: npx tsc --noEmit
|
|
|
|
|
|
|
|
|
|
test:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
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
|
|
|
|
@@ -49,10 +46,10 @@ jobs:
|
|
|
|
|
run: npx vitest run
|
|
|
|
|
|
|
|
|
|
audit:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
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
|
|
|
|
@@ -61,10 +58,10 @@ jobs:
|
|
|
|
|
run: npm audit --audit-level=high
|
|
|
|
|
|
|
|
|
|
e2e:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
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
|
|
|
|
@@ -73,11 +70,11 @@ jobs:
|
|
|
|
|
- run: npx playwright test
|
|
|
|
|
|
|
|
|
|
lighthouse:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
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
|
|
|
|
@@ -98,14 +95,14 @@ jobs:
|
|
|
|
|
CHROME_PATH="$CHROME_PATH" lhci autorun --chrome-flags="--headless=new --no-sandbox --disable-gpu --disable-dev-shm-usage"
|
|
|
|
|
|
|
|
|
|
build-and-push:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
needs: [lint, test, e2e]
|
|
|
|
|
outputs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
@@ -133,13 +130,13 @@ jobs:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: git.farh.net
|
|
|
|
|
username: cartsnitch
|
|
|
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata
|
|
|
|
|
id: meta
|
|
|
|
@@ -159,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
|
|
|
|
@@ -174,11 +171,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
- name: Upload frontend scan results to GitHub Security
|
|
|
|
|
uses: github/codeql-action/upload-sarif@v3
|
|
|
|
|
if: always()
|
|
|
|
|
with:
|
|
|
|
|
sarif_file: ${{ steps.scan.outputs.sarif }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -189,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'
|
|
|
|
@@ -198,14 +191,14 @@ jobs:
|
|
|
|
|
git push origin "v${{ steps.calver.outputs.version }}"
|
|
|
|
|
|
|
|
|
|
build-and-push-receiptwitness:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
needs: [lint, test]
|
|
|
|
|
outputs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
@@ -227,13 +220,13 @@ jobs:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: git.farh.net
|
|
|
|
|
username: cartsnitch
|
|
|
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata
|
|
|
|
|
id: meta
|
|
|
|
@@ -255,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
|
|
|
|
@@ -270,11 +263,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
- name: Upload receiptwitness scan results to GitHub Security
|
|
|
|
|
uses: github/codeql-action/upload-sarif@v3
|
|
|
|
|
if: always()
|
|
|
|
|
with:
|
|
|
|
|
sarif_file: ${{ steps.scan.outputs.sarif }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -287,17 +276,17 @@ 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: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
needs: [lint, test]
|
|
|
|
|
outputs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
@@ -319,13 +308,13 @@ jobs:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: git.farh.net
|
|
|
|
|
username: cartsnitch
|
|
|
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata (API)
|
|
|
|
|
id: meta
|
|
|
|
@@ -347,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
|
|
|
|
@@ -362,11 +351,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
- name: Upload api scan results to GitHub Security
|
|
|
|
|
uses: github/codeql-action/upload-sarif@v3
|
|
|
|
|
if: always()
|
|
|
|
|
with:
|
|
|
|
|
sarif_file: ${{ steps.scan.outputs.sarif }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -379,27 +364,106 @@ 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
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
needs: [lint, test]
|
|
|
|
|
outputs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
|
sha_tag: sha-${{ github.sha }}
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
|
|
- name: Generate CalVer tag
|
|
|
|
|
id: calver
|
|
|
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
|
|
|
run: |
|
|
|
|
|
DATE_TAG=$(date -u +%Y.%m.%d)
|
|
|
|
|
EXISTING=$(git tag -l "v${DATE_TAG}*" | sort -V | tail -1)
|
|
|
|
|
if [ -z "$EXISTING" ]; then VERSION="$DATE_TAG"
|
|
|
|
|
elif [ "$EXISTING" = "v${DATE_TAG}" ]; then VERSION="${DATE_TAG}.2"
|
|
|
|
|
else BUILD_NUM=$(echo "$EXISTING" | sed "s/v${DATE_TAG}\.//"); VERSION="${DATE_TAG}.$((BUILD_NUM + 1))"; fi
|
|
|
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
|
|
|
|
|
|
- name: Log in to Docker Hub
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to Gitea registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata (auth)
|
|
|
|
|
id: meta
|
|
|
|
|
uses: docker/metadata-action@v5
|
|
|
|
|
with:
|
|
|
|
|
images: ${{ env.REGISTRY }}/${{ env.AUTH_IMAGE_NAME }}
|
|
|
|
|
tags: |
|
|
|
|
|
type=sha,prefix=sha-,format=long
|
|
|
|
|
type=raw,value=${{ steps.calver.outputs.version }},enable=${{ github.ref == 'refs/heads/main' }}
|
|
|
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
|
|
|
|
|
|
|
|
|
- name: Build Docker image
|
|
|
|
|
uses: docker/build-push-action@v6
|
|
|
|
|
with:
|
|
|
|
|
context: ./auth
|
|
|
|
|
file: ./auth/Dockerfile
|
|
|
|
|
load: true
|
|
|
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
cache-to: type=inline,mode=max
|
|
|
|
|
|
|
|
|
|
- name: Scan auth image for vulnerabilities
|
|
|
|
|
uses: anchore/scan-action@v5
|
|
|
|
|
id: scan
|
|
|
|
|
env:
|
|
|
|
|
GRYPE_CONFIG: .grype.yaml
|
|
|
|
|
with:
|
|
|
|
|
image: "${{ env.REGISTRY }}/${{ env.AUTH_IMAGE_NAME }}:sha-${{ github.sha }}"
|
|
|
|
|
fail-build: true
|
|
|
|
|
severity-cutoff: high
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
uses: docker/build-push-action@v6
|
|
|
|
|
with:
|
|
|
|
|
context: ./auth
|
|
|
|
|
file: ./auth/Dockerfile
|
|
|
|
|
push: true
|
|
|
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
|
build-args: |
|
|
|
|
|
APT_CACHE_BUST=${{ github.run_id }}
|
|
|
|
|
cache-from: type=inline
|
|
|
|
|
|
|
|
|
|
deploy-dev:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
needs: [build-and-push, build-and-push-receiptwitness, build-and-push-api]
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
needs: [build-and-push, build-and-push-receiptwitness, build-and-push-api, build-and-push-auth]
|
|
|
|
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
|
|
|
|
|
steps:
|
|
|
|
|
- name: Generate GitHub App token
|
|
|
|
|
id: app-token
|
|
|
|
|
uses: actions/create-github-app-token@v1
|
|
|
|
|
with:
|
|
|
|
|
app-id: ${{ secrets.CARTSNITCH_APP_ID }}
|
|
|
|
|
private-key: ${{ secrets.CARTSNITCH_APP_PRIVATE_KEY }}
|
|
|
|
|
owner: ${{ github.repository_owner }}
|
|
|
|
|
repositories: infra
|
|
|
|
|
|
|
|
|
|
- name: Checkout infra repo
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
repository: cartsnitch/infra
|
|
|
|
|
token: ${{ steps.app-token.outputs.token }}
|
|
|
|
|
token: ${{ secrets.CI_GITEA_TOKEN }}
|
|
|
|
|
ref: main
|
|
|
|
|
path: infra
|
|
|
|
|
|
|
|
|
@@ -407,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
|
|
|
|
@@ -422,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
|
|
|
|
@@ -437,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
|
|
|
|
@@ -452,38 +525,89 @@ 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: Commit and push to infra
|
|
|
|
|
- name: Determine image tag for auth
|
|
|
|
|
id: auth_tag
|
|
|
|
|
run: |
|
|
|
|
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
|
|
|
|
echo "tag=${{ needs.build-and-push-auth.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
|
|
|
|
|
else
|
|
|
|
|
echo "tag=${{ needs.build-and-push-auth.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
- name: Update auth image tag
|
|
|
|
|
if: needs.build-and-push-auth.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/dev
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/auth=git.farh.net/cartsnitch/auth:${{ steps.auth_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- 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
|
|
|
|
|
git commit -m "ci(dev): update cartsnitch, receiptwitness, and api images"
|
|
|
|
|
git pull --rebase origin main
|
|
|
|
|
git push origin main
|
|
|
|
|
BRANCH="ci/deploy-dev-${GITHUB_SHA}"
|
|
|
|
|
git checkout -b "$BRANCH"
|
|
|
|
|
git commit -m "ci(dev): update cartsnitch, receiptwitness, api, and auth images"
|
|
|
|
|
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})"
|
|
|
|
|
# Request CTO (cs_savannah) review as the GitOps hand-off. Best-effort:
|
|
|
|
|
# log on non-2xx but never fail the job for this.
|
|
|
|
|
REVIEW_HTTP=$(curl -sS -o /dev/null -w '%{http_code}' -X POST \
|
|
|
|
|
-H "Authorization: token ${CI_GITEA_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d '{"reviewers":["cs_savannah"]}' \
|
|
|
|
|
"https://git.farh.net/api/v1/repos/cartsnitch/infra/pulls/${PR_NUM}/requested_reviewers")
|
|
|
|
|
if [ "${REVIEW_HTTP}" -lt 200 ] || [ "${REVIEW_HTTP}" -ge 300 ]; then
|
|
|
|
|
echo "::notice::Failed to request reviewers for cartsnitch/infra PR #${PR_NUM} (HTTP ${REVIEW_HTTP}); continuing"
|
|
|
|
|
fi
|
|
|
|
|
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 "PR #${PR_NUM} merged into cartsnitch/infra main"
|
|
|
|
|
elif echo "$MERGE_RESP" | grep -qi 'does not have enough approvals'; then
|
|
|
|
|
# GitOps approval gate: the PR is correctly opened and surfaces in
|
|
|
|
|
# the CTO queue via the reviewers request above. Treat as success
|
|
|
|
|
# (exit 0) so the deploy job does not hard-fail on the approvals
|
|
|
|
|
# requirement that only a human maintainer can satisfy.
|
|
|
|
|
echo "::notice::infra PR #${PR_NUM} opened and awaiting CTO (cs_savannah) approve+merge — GitOps approval gate, not a failure"
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
deploy-uat:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
needs: [build-and-push, build-and-push-receiptwitness, build-and-push-api]
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
needs: [build-and-push, build-and-push-receiptwitness, build-and-push-api, build-and-push-auth]
|
|
|
|
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main')
|
|
|
|
|
steps:
|
|
|
|
|
- name: Generate GitHub App token
|
|
|
|
|
id: app-token
|
|
|
|
|
uses: actions/create-github-app-token@v1
|
|
|
|
|
with:
|
|
|
|
|
app-id: ${{ secrets.CARTSNITCH_APP_ID }}
|
|
|
|
|
private-key: ${{ secrets.CARTSNITCH_APP_PRIVATE_KEY }}
|
|
|
|
|
owner: ${{ github.repository_owner }}
|
|
|
|
|
repositories: infra
|
|
|
|
|
|
|
|
|
|
- name: Checkout infra repo
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
|
|
|
with:
|
|
|
|
|
repository: cartsnitch/infra
|
|
|
|
|
token: ${{ steps.app-token.outputs.token }}
|
|
|
|
|
token: ${{ secrets.CI_GITEA_TOKEN }}
|
|
|
|
|
ref: main
|
|
|
|
|
path: infra
|
|
|
|
|
|
|
|
|
@@ -491,7 +615,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
|
|
|
|
@@ -506,7 +639,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
|
|
|
|
@@ -521,7 +654,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
|
|
|
|
@@ -536,15 +669,75 @@ 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: Commit and push to infra
|
|
|
|
|
- name: Determine image tag for auth
|
|
|
|
|
id: auth_tag
|
|
|
|
|
run: |
|
|
|
|
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
|
|
|
|
echo "tag=${{ needs.build-and-push-auth.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
|
|
|
|
|
else
|
|
|
|
|
echo "tag=${{ needs.build-and-push-auth.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
- name: Update auth image tag
|
|
|
|
|
if: needs.build-and-push-auth.result == 'success'
|
|
|
|
|
run: |
|
|
|
|
|
cd infra/apps/overlays/uat
|
|
|
|
|
kustomize edit set image ghcr.io/cartsnitch/auth=git.farh.net/cartsnitch/auth:${{ steps.auth_tag.outputs.tag }}
|
|
|
|
|
|
|
|
|
|
- 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
|
|
|
|
|
git commit -m "ci(uat): update cartsnitch, receiptwitness, and api images"
|
|
|
|
|
git pull --rebase origin main
|
|
|
|
|
git push origin main
|
|
|
|
|
BRANCH="ci/deploy-uat-${GITHUB_SHA}"
|
|
|
|
|
git checkout -b "$BRANCH"
|
|
|
|
|
git commit -m "ci(uat): update cartsnitch, receiptwitness, api, and auth images"
|
|
|
|
|
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})"
|
|
|
|
|
# Request CTO (cs_savannah) review as the GitOps hand-off. Best-effort:
|
|
|
|
|
# log on non-2xx but never fail the job for this.
|
|
|
|
|
REVIEW_HTTP=$(curl -sS -o /dev/null -w '%{http_code}' -X POST \
|
|
|
|
|
-H "Authorization: token ${CI_GITEA_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d '{"reviewers":["cs_savannah"]}' \
|
|
|
|
|
"https://git.farh.net/api/v1/repos/cartsnitch/infra/pulls/${PR_NUM}/requested_reviewers")
|
|
|
|
|
if [ "${REVIEW_HTTP}" -lt 200 ] || [ "${REVIEW_HTTP}" -ge 300 ]; then
|
|
|
|
|
echo "::notice::Failed to request reviewers for cartsnitch/infra PR #${PR_NUM} (HTTP ${REVIEW_HTTP}); continuing"
|
|
|
|
|
fi
|
|
|
|
|
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 "PR #${PR_NUM} merged into cartsnitch/infra main"
|
|
|
|
|
elif echo "$MERGE_RESP" | grep -qi 'does not have enough approvals'; then
|
|
|
|
|
# GitOps approval gate: the PR is correctly opened and surfaces in
|
|
|
|
|
# the CTO queue via the reviewers request above. Treat as success
|
|
|
|
|
# (exit 0) so the deploy job does not hard-fail on the approvals
|
|
|
|
|
# requirement that only a human maintainer can satisfy.
|
|
|
|
|
echo "::notice::infra PR #${PR_NUM} opened and awaiting CTO (cs_savannah) approve+merge — GitOps approval gate, not a failure"
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
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
|