ci(blog): publish and verify CDN assets before GitOps updates
Export the runtime image and assets together, gate deployment on verified S3 release completion, and share AWS credentials from /platform/tekton/blog in ap-southeast-2.
This commit is contained in:
1 parent
c313573442
commit
87a1d04da1
6 files changed
+206
-6
No files matched your search
+124
-1
@@ -151,12 +151,14 @@ kind: Task
|
||||
metadata:
|
||||
name: blog-build-arm64
|
||||
spec:
|
||||
description: Build and push the linux/arm64 full-stack Leptos image natively using rootless BuildKit.
|
||||
description: Build one runtime image and filesystem, then package, conditionally upload and verify its CDN release before GitOps can run.
|
||||
params:
|
||||
- name: revision
|
||||
type: string
|
||||
- name: image
|
||||
type: string
|
||||
- name: pipeline-run-uid
|
||||
type: string
|
||||
- name: environment
|
||||
type: string
|
||||
default: staging
|
||||
@@ -165,6 +167,10 @@ spec:
|
||||
description: Published repository and unique tag.
|
||||
- name: image-digest
|
||||
description: Immutable linux/arm64 image digest.
|
||||
- name: cdn-release-id
|
||||
description: Verified immutable CDN release ID.
|
||||
- name: cdn-manifest-key
|
||||
description: S3 completion manifest key, written only after every object passes verification.
|
||||
workspaces:
|
||||
- name: credentials
|
||||
readOnly: true
|
||||
@@ -175,6 +181,34 @@ spec:
|
||||
emptyDir: {}
|
||||
- name: buildkit-state
|
||||
emptyDir: {}
|
||||
stepTemplate:
|
||||
env:
|
||||
- name: SOURCE_REVISION
|
||||
value: $(params.revision)
|
||||
- name: PIPELINE_RUN_UID
|
||||
value: $(params.pipeline-run-uid)
|
||||
- name: DEPLOY_ENV
|
||||
value: $(params.environment)
|
||||
- name: CDN_PROJECT
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: blog-cdn-$(params.environment)
|
||||
key: CDN_PROJECT
|
||||
- name: CDN_BASE_URL
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: blog-cdn-$(params.environment)
|
||||
key: CDN_BASE_URL
|
||||
- name: CDN_BUCKET
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: blog-cdn-$(params.environment)
|
||||
key: CDN_BUCKET
|
||||
- name: AWS_REGION
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: blog-cdn-$(params.environment)
|
||||
key: AWS_REGION
|
||||
steps:
|
||||
- name: clone-source
|
||||
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
|
||||
@@ -226,6 +260,35 @@ spec:
|
||||
git clone --quiet --no-tags "$REPO_URL" /workspace/build/source
|
||||
git -C /workspace/build/source checkout --quiet --detach "$REVISION"
|
||||
test "$(git -C /workspace/build/source rev-parse HEAD)" = "$REVISION"
|
||||
- name: prepare-cdn
|
||||
image: docker.io/library/node:26.7.0-trixie-slim@sha256:5758d367d7b4f48b73a9bb3530e687e47efb289f3b43f9c0450a25225ae0db5d
|
||||
workingDir: /workspace/build/source
|
||||
computeResources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 256Mi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 1Gi
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: [ALL]
|
||||
volumeMounts:
|
||||
- name: build-source
|
||||
mountPath: /workspace/build
|
||||
env:
|
||||
- name: npm_config_cache
|
||||
value: /tmp/npm-cache
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
npm ci --prefix tools/cdn --ignore-scripts --no-audit --no-fund
|
||||
npm test --prefix tools/cdn
|
||||
node tools/cdn/cli.mjs check-config --release-result /workspace/build/release-id
|
||||
- name: build-and-push
|
||||
image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c
|
||||
computeResources:
|
||||
@@ -270,6 +333,8 @@ spec:
|
||||
set -eu
|
||||
printf '%s\n' "$IMAGE" | grep -Eq '^registry\.dahyeon\.us/dahyeon/blog:sha-[0-9a-f]{40}-[a-zA-Z0-9-]+$'
|
||||
case "$DEPLOY_ENV" in staging|prod) ;; *) echo 'Invalid deployment environment' >&2; exit 1;; esac
|
||||
CDN_RELEASE="$(cat /workspace/build/release-id)"
|
||||
printf '%s\n' "$CDN_RELEASE" | grep -Eq '^[0-9a-f]{16}$'
|
||||
buildctl-daemonless.sh build \
|
||||
--frontend dockerfile.v0 \
|
||||
--local context=/workspace/build/source \
|
||||
@@ -277,11 +342,15 @@ spec:
|
||||
--opt filename=Dockerfile \
|
||||
--opt target=runtime \
|
||||
--opt platform=linux/arm64 \
|
||||
--opt "build-arg:BLOG_CDN_BASE=$CDN_BASE_URL" \
|
||||
--opt "build-arg:BLOG_CDN_PROJECT=$CDN_PROJECT" \
|
||||
--opt "build-arg:BLOG_CDN_RELEASE=$CDN_RELEASE" \
|
||||
--import-cache "type=registry,ref=$CACHE_REPOSITORY:cache-release-arm64-$DEPLOY_ENV" \
|
||||
--import-cache "type=registry,ref=$CACHE_REPOSITORY:cache-quality-deps-arm64-$DEPLOY_ENV" \
|
||||
--import-cache "type=registry,ref=$CACHE_REPOSITORY:cache-quality-arm64-$DEPLOY_ENV" \
|
||||
--export-cache "type=registry,ref=$CACHE_REPOSITORY:cache-release-arm64-$DEPLOY_ENV,mode=max,image-manifest=true,oci-mediatypes=true" \
|
||||
--output "type=image,name=$IMAGE,push=true" \
|
||||
--output type=local,dest=/workspace/build/runtime,platform-split=false \
|
||||
--metadata-file "$METADATA_FILE"
|
||||
- name: record-digest
|
||||
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
|
||||
@@ -320,6 +389,47 @@ spec:
|
||||
printf '%s\n' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'
|
||||
printf '%s' "$IMAGE" >"$IMAGE_RESULT_PATH"
|
||||
printf '%s' "$DIGEST" >"$DIGEST_RESULT_PATH"
|
||||
- name: publish-cdn
|
||||
image: docker.io/library/node:26.7.0-trixie-slim@sha256:5758d367d7b4f48b73a9bb3530e687e47efb289f3b43f9c0450a25225ae0db5d
|
||||
workingDir: /workspace/build/source
|
||||
computeResources:
|
||||
requests:
|
||||
cpu: 250m
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: "2"
|
||||
memory: 2Gi
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: [ALL]
|
||||
volumeMounts:
|
||||
- name: build-source
|
||||
mountPath: /workspace/build
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: blog-cdn
|
||||
env:
|
||||
- name: AWS_EC2_METADATA_DISABLED
|
||||
value: "true"
|
||||
- name: RELEASE_RESULT_PATH
|
||||
value: $(results.cdn-release-id.path)
|
||||
- name: MANIFEST_RESULT_PATH
|
||||
value: $(results.cdn-manifest-key.path)
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
node tools/cdn/cli.mjs package \
|
||||
--site-root /workspace/build/runtime/app/site \
|
||||
--output-root /workspace/build/cdn \
|
||||
--image-metadata /workspace/build/build-metadata.json
|
||||
node tools/cdn/cli.mjs publish \
|
||||
--output-root /workspace/build/cdn \
|
||||
--release-result "$RELEASE_RESULT_PATH" \
|
||||
--manifest-result "$MANIFEST_RESULT_PATH"
|
||||
---
|
||||
apiVersion: tekton.dev/v1
|
||||
kind: Task
|
||||
@@ -332,6 +442,10 @@ spec:
|
||||
type: string
|
||||
- name: image-digest
|
||||
type: string
|
||||
- name: cdn-release-id
|
||||
type: string
|
||||
- name: cdn-manifest-key
|
||||
type: string
|
||||
- name: environment
|
||||
type: string
|
||||
default: staging
|
||||
@@ -407,6 +521,10 @@ spec:
|
||||
value: registry.dahyeon.us/dahyeon/blog
|
||||
- name: IMAGE_DIGEST
|
||||
value: $(params.image-digest)
|
||||
- name: CDN_RELEASE
|
||||
value: $(params.cdn-release-id)
|
||||
- name: CDN_MANIFEST_KEY
|
||||
value: $(params.cdn-manifest-key)
|
||||
- name: DEPLOYMENT_NAME
|
||||
value: blog
|
||||
script: |
|
||||
@@ -414,12 +532,17 @@ spec:
|
||||
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' "$CDN_RELEASE" | grep -Eq '^[0-9a-f]{16}$'
|
||||
case "$DEPLOY_ENV" in prod) CDN_PROJECT=blog ;; staging) CDN_PROJECT=blog-staging ;; esac
|
||||
test "$CDN_MANIFEST_KEY" = "$CDN_PROJECT/_releases/$CDN_RELEASE/complete.json"
|
||||
MANIFEST="$STATE_DIR/apps/blog/overlays/$DEPLOY_ENV/kustomization.yaml"
|
||||
test "$(yq '[.images[] | select(.name == strenv(APP_IMAGE))] | length' "$MANIFEST")" = 1
|
||||
test "$(yq '[.replicas[] | select(.name == strenv(DEPLOYMENT_NAME))] | length' "$MANIFEST")" = 1
|
||||
yq -i '(.images[] | select(.name == strenv(APP_IMAGE))) |= (del(.newTag) | .digest = strenv(IMAGE_DIGEST))' "$MANIFEST"
|
||||
yq -i '(.replicas[] | select(.name == strenv(DEPLOYMENT_NAME))).count = 1' "$MANIFEST"
|
||||
yq -i '.commonAnnotations."blog.dahyeon.us/source-revision" = strenv(REVISION)' "$MANIFEST"
|
||||
yq -i '.commonAnnotations."blog.dahyeon.us/cdn-release" = strenv(CDN_RELEASE)' "$MANIFEST"
|
||||
yq -i '.commonAnnotations."blog.dahyeon.us/cdn-manifest" = strenv(CDN_MANIFEST_KEY)' "$MANIFEST"
|
||||
- name: commit-and-push
|
||||
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
|
||||
computeResources:
|
||||
|
||||
Reference in new issue
Block a user