feat(url-shortener): add production promotion pipeline
This commit is contained in:
1 parent
aae1888bea
commit
b941de2e0e
5 files changed
+214
-19
No files matched your search
+61
-19
@@ -396,15 +396,44 @@ kind: Task
|
||||
metadata:
|
||||
name: url-shortener-deploy-cloudflare
|
||||
spec:
|
||||
description: Recheck main, migrate D1, deploy the staging Redirect Worker, then build and deploy static admin Pages from the same revision.
|
||||
description: Deploy D1, the Redirect Worker and admin Pages from the selected revision and environment.
|
||||
params:
|
||||
- name: revision
|
||||
type: string
|
||||
- name: environment
|
||||
type: string
|
||||
default: staging
|
||||
workspaces:
|
||||
- name: source
|
||||
- name: credentials
|
||||
readOnly: true
|
||||
steps:
|
||||
- name: prepare-dependencies
|
||||
image: docker.io/library/node:26.13.0-bookworm@sha256:fa52d1669505e29b58c042875b1d65c229e0787a3610fd52869b22b68e480853
|
||||
workingDir: $(workspaces.source.path)
|
||||
computeResources:
|
||||
requests:
|
||||
cpu: 200m
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: "2"
|
||||
memory: 4Gi
|
||||
env:
|
||||
- name: CI
|
||||
value: "true"
|
||||
- name: NPM_CONFIG_CACHE
|
||||
value: $(workspaces.source.path)/.cache/ci/npm
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Staging's quality task already installed these dependencies.
|
||||
if [ -x .cache/ci/pnpm/bin/pnpm ] && [ -d node_modules ]; then
|
||||
exit 0
|
||||
fi
|
||||
umask 0002
|
||||
mkdir -p .cache/ci/pnpm .cache/ci/npm
|
||||
npm install --global --prefix "$PWD/.cache/ci/pnpm" pnpm@12.16.1
|
||||
.cache/ci/pnpm/bin/pnpm install --frozen-lockfile
|
||||
- name: deploy
|
||||
image: docker.io/library/node:26.13.0-bookworm@sha256:fa52d1669505e29b58c042875b1d65c229e0787a3610fd52869b22b68e480853
|
||||
workingDir: $(workspaces.source.path)
|
||||
@@ -422,6 +451,8 @@ spec:
|
||||
value: https://git.dahyeon.us/dahyeon/url-shortener.git
|
||||
- name: REVISION
|
||||
value: $(params.revision)
|
||||
- name: DEPLOY_ENV
|
||||
value: $(params.environment)
|
||||
- name: GITEA_CREDENTIALS_DIR
|
||||
value: $(workspaces.credentials.path)
|
||||
- name: PATH
|
||||
@@ -436,10 +467,11 @@ spec:
|
||||
- secretRef:
|
||||
name: url-shortener-cloudflare
|
||||
- secretRef:
|
||||
name: url-shortener-edge-staging
|
||||
name: url-shortener-edge-$(params.environment)
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
case "$DEPLOY_ENV" in staging|prod) ;; *) echo 'Invalid deployment environment' >&2; exit 1;; esac
|
||||
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
|
||||
AUTH_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$AUTH_DIR"' EXIT
|
||||
@@ -454,26 +486,31 @@ spec:
|
||||
chmod 0700 "$AUTH_DIR/askpass"
|
||||
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
|
||||
test "$(git rev-parse HEAD)" = "$REVISION"
|
||||
REMOTE_REVISION="$(git ls-remote "$REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
|
||||
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
|
||||
echo 'Source revision was superseded before Cloudflare deployment.' >&2
|
||||
exit 1
|
||||
if [ "$DEPLOY_ENV" = staging ]; then
|
||||
REMOTE_REVISION="$(git ls-remote "$REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
|
||||
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
|
||||
echo 'Source revision was superseded before Cloudflare deployment.' >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
command -v pnpm >/dev/null
|
||||
pnpm deploy:cloudflare -- staging
|
||||
pnpm deploy:pages -- staging
|
||||
pnpm deploy:cloudflare -- "$DEPLOY_ENV"
|
||||
pnpm deploy:pages -- "$DEPLOY_ENV"
|
||||
---
|
||||
apiVersion: tekton.dev/v1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: url-shortener-update-gitops
|
||||
spec:
|
||||
description: Publish the staging app digest and matching D1 identifiers, bootstrapping at least two replicas without reducing a larger configured count.
|
||||
description: Publish the selected environment's app digest and D1 identifiers, bootstrapping at least two replicas without reducing a larger configured count.
|
||||
params:
|
||||
- name: revision
|
||||
type: string
|
||||
- name: image-digest
|
||||
type: string
|
||||
- name: environment
|
||||
type: string
|
||||
default: staging
|
||||
results:
|
||||
- name: gitops-commit
|
||||
description: Commit pushed to service-state main.
|
||||
@@ -497,6 +534,8 @@ spec:
|
||||
value: https://git.dahyeon.us/dahyeon/url-shortener.git
|
||||
- name: REVISION
|
||||
value: $(params.revision)
|
||||
- name: DEPLOY_ENV
|
||||
value: $(params.environment)
|
||||
- name: STATE_DIR
|
||||
value: $(workspaces.source.path)/.cache/gitops-state
|
||||
- name: GITEA_CREDENTIALS_DIR
|
||||
@@ -547,7 +586,7 @@ spec:
|
||||
- name: DEPLOYMENT_NAME
|
||||
value: url-shortener
|
||||
- name: CLOUDFLARE_PROFILE
|
||||
value: $(workspaces.source.path)/deploy/cloudflare/staging.json
|
||||
value: $(workspaces.source.path)/deploy/cloudflare/$(params.environment).json
|
||||
- name: CLOUDFLARE_ACCOUNT_ID
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
@@ -556,15 +595,16 @@ spec:
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
case "$DEPLOY_ENV" in staging|prod) ;; *) echo 'Invalid deployment environment' >&2; exit 1;; esac
|
||||
printf '%s\n' "$IMAGE_DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'
|
||||
printf '%s\n' "$CLOUDFLARE_ACCOUNT_ID" | grep -Eq '^[0-9a-fA-F]{32}$'
|
||||
test "$(yq -r '.environment' "$CLOUDFLARE_PROFILE")" = staging
|
||||
test "$(yq -r '.environment' "$CLOUDFLARE_PROFILE")" = "$DEPLOY_ENV"
|
||||
CLOUDFLARE_D1_DATABASE_ID="$(yq -r '.databaseId' "$CLOUDFLARE_PROFILE")"
|
||||
printf '%s\n' "$CLOUDFLARE_D1_DATABASE_ID" | grep -Eq '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
|
||||
test "$CLOUDFLARE_D1_DATABASE_ID" != '00000000-0000-0000-0000-000000000000'
|
||||
export CLOUDFLARE_D1_DATABASE_ID
|
||||
MANIFEST="$STATE_DIR/apps/url-shortener/overlays/staging/kustomization.yaml"
|
||||
CONFIGMAP="$STATE_DIR/apps/url-shortener/overlays/staging/configmap.yaml"
|
||||
MANIFEST="$STATE_DIR/apps/url-shortener/overlays/$DEPLOY_ENV/kustomization.yaml"
|
||||
CONFIGMAP="$STATE_DIR/apps/url-shortener/overlays/$DEPLOY_ENV/configmap.yaml"
|
||||
test "$(yq '[.images[] | select(.name == strenv(APP_IMAGE))] | length' "$MANIFEST")" = 1
|
||||
test "$(yq '[.replicas[] | select(.name == strenv(DEPLOYMENT_NAME))] | length' "$MANIFEST")" = 1
|
||||
REPLICAS="$(yq '.replicas[] | select(.name == strenv(DEPLOYMENT_NAME)) | .count' "$MANIFEST")"
|
||||
@@ -614,12 +654,14 @@ spec:
|
||||
git -C "$STATE_DIR" rev-parse HEAD >"$GITOPS_RESULT_PATH"
|
||||
exit 0
|
||||
fi
|
||||
git -C "$STATE_DIR" add apps/url-shortener/overlays/staging/kustomization.yaml apps/url-shortener/overlays/staging/configmap.yaml
|
||||
git -C "$STATE_DIR" commit -m "chore(url-shortener): deploy staging $REVISION"
|
||||
REMOTE_REVISION="$(git ls-remote "$SOURCE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
|
||||
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
|
||||
echo 'Source revision was superseded before GitOps push.' >&2
|
||||
exit 1
|
||||
git -C "$STATE_DIR" add "apps/url-shortener/overlays/$DEPLOY_ENV/kustomization.yaml" "apps/url-shortener/overlays/$DEPLOY_ENV/configmap.yaml"
|
||||
git -C "$STATE_DIR" commit -m "chore(url-shortener): deploy $DEPLOY_ENV $REVISION"
|
||||
if [ "$DEPLOY_ENV" = staging ]; then
|
||||
REMOTE_REVISION="$(git ls-remote "$SOURCE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
|
||||
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
|
||||
echo 'Source revision was superseded before GitOps push.' >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
# A concurrent state update causes a non-fast-forward failure, never an overwrite.
|
||||
git -C "$STATE_DIR" push origin HEAD:main
|
||||
|
||||
Reference in new issue
Block a user