Compare commits

...
64 Commits
Author SHA1 Message Date
blog-tekton eb9eb1d1c2 chore(blog): deploy staging ab68ddf5a88b6ea4cc47c9d7b86f0df361a3ae61 2026-11-18 18:12:48 +00:00
blog-tekton 2a653c0508 chore(blog): deploy staging 4c6ab802b46f41d610c4add8586442b9e9c8c200 2026-11-18 14:56:01 +00:00
blog-tekton a326fe8878 chore(blog): deploy staging 9d7c0112bd5f20a1843b3aa593bb76db0adcae48 2026-11-18 13:47:31 +00:00
dahyeon ede18d4ec4 docs(blog-ci): keep only configuration and operation commands 2026-11-18 22:09:07 +09:00
dahyeon 4336d923aa fix(blog-ci): create checkout directories as the build user
Start CDN containers at the shared volume root and enter the checkout from their scripts, avoiding root-owned directories created before clone-source runs.
2026-11-18 22:04:51 +09:00
dahyeon ccf2190592 fix(blog-ci): pass CDN settings as Pipeline parameters
Remove CDN ConfigMaps and forward CDN_URL_PREFIX, CDN_BASE_URL, CDN_S3_BUCKET_NAME, and AWS_REGION through build and publication tasks.
2026-11-18 21:41:36 +09:00
dahyeon 87a1d04da1 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.
2026-11-18 21:15:53 +09:00
blog-tekton c313573442 chore(blog): deploy staging ebc27d0c407c6e299846bb63164cd949bb98d42a 2026-11-18 07:26:22 +00:00
blog-tekton c305d03dc5 chore(blog): deploy staging 4b1c9c4b7f707adb64030fc614c1f6992ce53c9e 2026-11-18 04:32:31 +00:00
dahyeon eba6763eee docs(blog): align quality checks with production features 2026-11-18 12:56:14 +09:00
blog-tekton 618b5182d8 chore(blog): deploy staging 59e34958e91d43de456a47d7b9e4aefd84e8901f 2026-11-17 17:08:04 +00:00
dahyeon dcc476b6fa perf(blog): pin CI builds to heize with 20Gi limits 2026-11-18 01:37:13 +09:00
blog-tekton 554c09cae9 chore(blog): deploy staging adeffabcc1cd8ebba7d0e7e9da96eae65e533b74 2026-11-17 15:03:51 +00:00
dahyeon b0b1f3630b fix(blog): allow scheduling on any arm64 node 2026-11-17 22:56:13 +09:00
dahyeon 8c947b6482 fix(blog): schedule 10Gi builds on the high-memory arm64 node 2026-11-17 22:50:22 +09:00
dahyeon be032170db perf(blog): preserve dependency cache before quality checks 2026-11-17 22:45:01 +09:00
dahyeon 83efb25978 perf(blog): cache CI builds and raise memory limits to 10Gi 2026-11-17 21:52:03 +09:00
dahyeon bb34391305 fix(blog): reserve memory and serialize CI builds 2026-11-17 19:57:22 +09:00
dahyeon c6e886012f fix(blog): update staging domain to blog-staging.dahyeon.us 2026-11-17 19:29:51 +09:00
dahyeon b44398719c feat(blog): add staging and production CI/CD 2026-11-17 18:47:40 +09:00
dahyeon ca3817f8da fix(make-space): disable HAProxy SSL redirect 2026-11-14 10:58:29 +09:00
dahyeon b9fe1bcf5e chore(lolympus): promote staging digest to prod 2026-11-11 20:33:27 +09:00
lolympus-tekton c1ce3e8f18 chore(lolympus): deploy staging sha256:898cd7cacbcf1cd03ac02db003f7a78543ef6dfce806ad9fb955faef15c47332 2026-11-11 11:32:24 +00:00
dahyeon c2e201ab82 chore(lolympus): promote staging digest to prod 2026-11-11 12:50:08 +09:00
lolympus-tekton 2ee964931d chore(lolympus): deploy staging sha256:b82d2634d5664174f7668839a967c2fd6e7e784d8b70c7d08a03b2a9e5a42cb0 2026-11-10 17:14:29 +00:00
dahyeon a8cb2d22d9 chore(lolympus): promote staging digest to prod 2026-11-09 23:36:20 +09:00
lolympus-tekton 0cc28fda66 chore(lolympus): deploy staging sha256:1b1eabb9073582cc55ef4f151053c17d82a27eaf55277b18eea67689539958d8 2026-11-09 14:29:17 +00:00
dahyeon c4d2e340a9 refactor(ci): transfer shared namespace policies to platform 2026-11-09 18:35:24 +09:00
lolympus-tekton 6c3857628b chore(lolympus): deploy staging sha256:398194f075711282939bd5e136f41f5fdcd71e38d9f4e440fbdb8ea817a4a089 2026-11-09 09:20:09 +00:00
dahyeon ae8d1ab9a7 chore(lolympus): promote staging digest to prod 2026-11-09 17:49:17 +09:00
lolympus-tekton 7ccc70c0e1 chore(lolympus): deploy staging sha256:e9a958a0ba094d352894782b67c9d8e7a656c4c190dc2b50f145120780c871ba 2026-11-09 08:43:03 +00:00
dahyeon 21e46316dc chore(lolympus): promote staging digest to prod 2026-11-09 16:39:52 +09:00
lolympus-tekton 8a50b69b2a chore(lolympus): deploy staging sha256:932a0757a5eb7dc3209f7d9ce8b1ec53bfacdf3269df1c7fd048b2981259e45e 2026-11-09 07:35:00 +00:00
dahyeon 51adf81529 chore(lolympus): promote staging digest to prod 2026-11-07 20:37:53 +09:00
lolympus-tekton 1ae6a3ced1 chore(lolympus): deploy staging sha256:172bbed45a3f36f5c9f45b8d6e21b1fc8f6d41fe1b1e6d3511331ae57d188a4f 2026-11-07 11:26:52 +00:00
dahyeon d38e1d2522 fix(ci): remove aggregate Tekton CPU and memory limit quotas 2026-11-06 21:46:07 +09:00
make-space-tekton ee78781f58 chore(make-space): deploy prod 6a157a2eca0cfe85aae4e6810da799ca54ce0c21 2026-11-04 14:39:21 +00:00
make-space-tekton 155ad7e449 chore(make-space): deploy staging b43b060c8a1f6f2de9927cbfbcf561d0000fe0c4 2026-11-04 12:46:11 +00:00
make-space-tekton d31cb21004 chore(make-space): deploy prod b43b060c8a1f6f2de9927cbfbcf561d0000fe0c4 2026-11-04 12:31:58 +00:00
dahyeon fcea6e7107 feat(make-space): add staging/prod overlays and arm64 Tekton CI 2026-11-04 20:41:46 +09:00
url-shortener-tekton 3d4d541d48 chore(url-shortener): deploy staging 93c79698083efe0bd87a9435e3adc70be4d3e458 2026-11-04 06:05:29 +00:00
url-shortener-tekton 4206a20dc5 chore(url-shortener): deploy prod 93c79698083efe0bd87a9435e3adc70be4d3e458 2026-11-04 05:56:29 +00:00
dahyeon a02e372e85 feat(url-shortener): deploy staging and prod branches automatically 2026-11-04 14:19:16 +09:00
dahyeon 3ec9732190 fix(url-shortener): expose only task results from prod pipeline 2026-11-04 14:11:30 +09:00
dahyeon b941de2e0e feat(url-shortener): add production promotion pipeline 2026-11-04 14:10:18 +09:00
url-shortener-tekton aae1888bea chore(url-shortener): deploy staging 55f7c19d9d0e5e151435b54017e704fb1ba993e2 2026-11-04 04:47:23 +00:00
dahyeon 0108a18e9c fix(ci): let non-root clone create build source directory 2026-11-04 05:45:29 +09:00
dahyeon 17e90dae80 fix(ci): move url-shortener cluster RBAC to platform-state 2026-11-04 05:07:41 +09:00
dahyeon d909a86b0e feat(url-shortener): add deployment manifests and Tekton CI 2026-11-04 04:56:48 +09:00
dahyeon 176c214f86 chore(lolympus): promote staging digest to prod 2026-09-27 02:30:33 +09:00
lolympus-tekton 5f119e0429 chore(lolympus): deploy staging sha256:1c2a1bff08f472f5c4906f9f29d40165f71efa40d2a2a6e0b04a0488738cc7bc 2026-09-26 17:15:15 +00:00
lolympus-tekton 68025438ed chore(lolympus): deploy staging sha256:e6762f8ec60565e2a1ad3f6ef94456224011bb5604e9bfe90b18e7f0dbace5f8 2026-09-19 11:34:05 +00:00
lolympus-tekton c63751b700 chore(lolympus): deploy staging sha256:b149ec71a3ec438016427c5c261917ae18b1532050f59291e8317a4f83bdda34 2026-07-25 18:34:04 +00:00
dahyeon 5edb902c0a fix(ci): avoid precreated root-owned build directory 2026-07-26 03:26:37 +09:00
dahyeon 979745c7a0 fix(ci): use owned directory for native builds 2026-07-26 03:12:54 +09:00
dahyeon 966e109d28 feat(ci): build API images for multiple architectures 2026-07-26 02:48:39 +09:00
lolympus-tekton 54f5c63727 chore(lolympus): deploy staging sha-34a47c053e043119a5da63837168c65cbf79afa0 2026-07-25 17:11:29 +00:00
dahyeon 7eadf3d6cc fix(ci): align GitOps task file ownership 2026-07-26 01:59:14 +09:00
dahyeon f05f0f2af9 fix(ci): align API build with rootless BuildKit 2026-07-26 00:17:52 +09:00
dahyeon 2ed6b93bbe fix(ci): enable user namespace for API build 2026-07-25 23:18:08 +09:00
dahyeon 5422fef4fb fix: use shell substitutions in Tekton tasks 2026-07-18 17:53:42 +00:00
dahyeon 52233a7a78 fix: bootstrap pnpm for Node 26 tasks 2026-07-18 08:19:41 +00:00
dahyeon 47b4440245 fix: run valid lolympus test commands 2026-07-18 08:08:52 +00:00
dahyeon 5295851a12 fix: grant EventListener interceptor access 2026-07-18 08:02:08 +00:00
77 changed files with 4494 additions and 90 deletions

No files matched your search

+3
View File
@@ -9,5 +9,8 @@ Argo CD는 아래 경로에서 서비스 배포 대상을 찾습니다.
애플리케이션 목록: 애플리케이션 목록:
- `blog`
- `lolympus-tournament-support` - `lolympus-tournament-support`
- `make-space`
- `persona-lenz` - `persona-lenz`
- `url-shortener`
+10
View File
@@ -0,0 +1,10 @@
# blog
- staging: `blog-staging` / `blog-staging.dahyeon.us`
- prod: `blog-prod` / `rabbitmaus.com`
- 이미지: `registry.dahyeon.us/dahyeon/blog` (`linux/arm64`)
- Secret: `harbor-registry`(이미지 pull), `blog-secrets`(Infisical)
- 상태 확인: `/healthz`
브랜치 push → Tekton → GitOps 갱신 → Argo CD 자동 Sync.
[CI 설정](../../ci/blog/README.md)
+81
View File
@@ -0,0 +1,81 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: blog
labels:
app.kubernetes.io/component: app
spec:
replicas: 0
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app.kubernetes.io/name: blog
app.kubernetes.io/component: app
template:
metadata:
labels:
app.kubernetes.io/name: blog
app.kubernetes.io/component: app
spec:
serviceAccountName: blog
automountServiceAccountToken: false
nodeSelector:
kubernetes.io/arch: arm64
imagePullSecrets:
- name: harbor-registry
terminationGracePeriodSeconds: 60
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
containers:
- name: app
image: registry.dahyeon.us/dahyeon/blog
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
envFrom:
- configMapRef:
name: blog-config
- secretRef:
name: blog-secrets
ports:
- name: http
containerPort: 3000
protocol: TCP
startupProbe:
httpGet:
path: /healthz
port: http
periodSeconds: 5
failureThreshold: 24
livenessProbe:
httpGet:
path: /healthz
port: http
periodSeconds: 15
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /healthz
port: http
periodSeconds: 10
timeoutSeconds: 3
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: "2"
memory: 1Gi
+13
View File
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- services.yaml
- serviceaccount.yaml
- poddisruptionbudget.yaml
labels:
- includeSelectors: true
pairs:
app.kubernetes.io/name: blog
app.kubernetes.io/part-of: blog
app.kubernetes.io/managed-by: kustomize
+10
View File
@@ -0,0 +1,10 @@
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: blog
spec:
minAvailable: 1
selector:
matchLabels:
app.kubernetes.io/name: blog
app.kubernetes.io/component: app
+5
View File
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: blog
automountServiceAccountToken: false
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: blog
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: blog
app.kubernetes.io/component: app
ports:
- name: http
port: 3000
targetPort: http
protocol: TCP
+11
View File
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: blog-config
data:
LEPTOS_ENV: PROD
LEPTOS_OUTPUT_NAME: blog
LEPTOS_SITE_ADDR: 0.0.0.0:3000
LEPTOS_SITE_ROOT: /app/site
LEPTOS_SITE_PKG_DIR: pkg
BLOG_PUBLIC_ORIGIN: https://rabbitmaus.com
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: blog
spec:
template:
metadata:
labels:
app.kubernetes.io/environment: prod
@@ -0,0 +1,31 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: blog-secrets
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: eb73ed07-2fc4-48ca-927b-cf3692b97cf6
environmentSlug: prod
secretPath: /
recursive: false
targets:
- name: blog-secrets
namespace: blog-prod
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
MONGODB_CONNECTION_STRING: "{{ .MONGODB_CONNECTION_STRING.Value }}"
MONGODB_DATABASE: "{{ .MONGODB_DATABASE.Value }}"
MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS: "{{ .MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS.Value }}"
MICROSOFT_ENTRAID_CLIENT_ID: "{{ .MICROSOFT_ENTRAID_CLIENT_ID.Value }}"
MICROSOFT_ENTRAID_CLIENT_SECRET: "{{ .MICROSOFT_ENTRAID_CLIENT_SECRET.Value }}"
MICROSOFT_ENTRAID_TENANT_ID: "{{ .MICROSOFT_ENTRAID_TENANT_ID.Value }}"
+24
View File
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: blog
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
haproxy.org/ssl-redirect: 'false'
spec:
ingressClassName: haproxy
tls:
- hosts:
- rabbitmaus.com
secretName: blog-prod-tls
rules:
- host: rabbitmaus.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: blog
port:
number: 3000
@@ -0,0 +1,19 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: blog-prod
resources:
- ../../base
- configmap.yaml
- infisical-secret.yaml
- ingress.yaml
images:
- name: registry.dahyeon.us/dahyeon/blog
newName: registry.dahyeon.us/dahyeon/blog
# Bootstrap sentinel, not a published image. The first successful CI run
# writes a real digest and changes replicas from 0 to 1 in the same commit.
digest: sha256:0000000000000000000000000000000000000000000000000000000000000000
replicas:
- name: blog
count: 0
patches:
- path: deployment-patch.yaml
+11
View File
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: blog-config
data:
LEPTOS_ENV: PROD
LEPTOS_OUTPUT_NAME: blog
LEPTOS_SITE_ADDR: 0.0.0.0:3000
LEPTOS_SITE_ROOT: /app/site
LEPTOS_SITE_PKG_DIR: pkg
BLOG_PUBLIC_ORIGIN: https://blog-staging.dahyeon.us
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: blog
spec:
template:
metadata:
labels:
app.kubernetes.io/environment: staging
@@ -0,0 +1,31 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: blog-secrets
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: eb73ed07-2fc4-48ca-927b-cf3692b97cf6
environmentSlug: staging
secretPath: /
recursive: false
targets:
- name: blog-secrets
namespace: blog-staging
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
MONGODB_CONNECTION_STRING: "{{ .MONGODB_CONNECTION_STRING.Value }}"
MONGODB_DATABASE: "{{ .MONGODB_DATABASE.Value }}"
MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS: "{{ .MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS.Value }}"
MICROSOFT_ENTRAID_CLIENT_ID: "{{ .MICROSOFT_ENTRAID_CLIENT_ID.Value }}"
MICROSOFT_ENTRAID_CLIENT_SECRET: "{{ .MICROSOFT_ENTRAID_CLIENT_SECRET.Value }}"
MICROSOFT_ENTRAID_TENANT_ID: "{{ .MICROSOFT_ENTRAID_TENANT_ID.Value }}"
+24
View File
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: blog
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
haproxy.org/ssl-redirect: 'false'
spec:
ingressClassName: haproxy
tls:
- hosts:
- blog-staging.dahyeon.us
secretName: blog-staging-tls
rules:
- host: blog-staging.dahyeon.us
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: blog
port:
number: 3000
@@ -0,0 +1,23 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: blog-staging
resources:
- ../../base
- configmap.yaml
- infisical-secret.yaml
- ingress.yaml
images:
- name: registry.dahyeon.us/dahyeon/blog
newName: registry.dahyeon.us/dahyeon/blog
# Bootstrap sentinel, not a published image. The first successful CI run
# writes a real digest and changes replicas from 0 to 1 in the same commit.
digest: sha256:cdba3439a07123d4cc17fa2465eb1a42f0bb5ed6c579cea0e1d023bcbe7e0e4c
replicas:
- name: blog
count: 1
patches:
- path: deployment-patch.yaml
commonAnnotations:
blog.dahyeon.us/source-revision: ab68ddf5a88b6ea4cc47c9d7b86f0df361a3ae61
blog.dahyeon.us/cdn-release: e260431c1e669129
blog.dahyeon.us/cdn-manifest: blog-staging/_releases/e260431c1e669129/complete.json
@@ -12,7 +12,7 @@ resources:
images: images:
- name: registry.dahyeon.us/lolympus/lolympus-tournament-support - name: registry.dahyeon.us/lolympus/lolympus-tournament-support
newName: registry.dahyeon.us/lolympus/lolympus-tournament-support newName: registry.dahyeon.us/lolympus/lolympus-tournament-support
newTag: "86.2" digest: sha256:898cd7cacbcf1cd03ac02db003f7a78543ef6dfce806ad9fb955faef15c47332
replicas: replicas:
- name: lolympus-tournament-support - name: lolympus-tournament-support
@@ -1,22 +1,17 @@
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
namespace: lolympus-staging namespace: lolympus-staging
resources: resources:
- ../../base - ../../base
- configmap.yaml - configmap.yaml
- infisical-secret.yaml - infisical-secret.yaml
- ingress.yaml - ingress.yaml
images: images:
- name: registry.dahyeon.us/lolympus/lolympus-tournament-support - name: registry.dahyeon.us/lolympus/lolympus-tournament-support
newName: registry.dahyeon.us/lolympus/lolympus-tournament-support newName: registry.dahyeon.us/lolympus/lolympus-tournament-support
newTag: "86.2" digest: sha256:898cd7cacbcf1cd03ac02db003f7a78543ef6dfce806ad9fb955faef15c47332
replicas: replicas:
- name: lolympus-tournament-support - name: lolympus-tournament-support
count: 2 count: 2
patches: patches:
- path: deployment-patch.yaml - path: deployment-patch.yaml
+8
View File
@@ -0,0 +1,8 @@
# make-space
- 환경: `overlays/staging`, `overlays/prod`
- 이미지: `registry.dahyeon.us/dahyeon/make-space` (linux/arm64)
- Harbor pull Secret: `harbor-registry`
- 앱 Secret: `make-space-secrets` (Infisical project `e60bd852-956a-454c-aaeb-65bd0cf418a9`)
앱 저장소의 `staging`/`prod` 브랜치 push → 해당 Tekton Pipeline → 환경별 GitOps 갱신 → Argo CD 자동 Sync.
+81
View File
@@ -0,0 +1,81 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: make-space
labels:
app.kubernetes.io/component: app
spec:
replicas: 0
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app.kubernetes.io/name: make-space
app.kubernetes.io/component: app
template:
metadata:
labels:
app.kubernetes.io/name: make-space
app.kubernetes.io/component: app
spec:
serviceAccountName: make-space
automountServiceAccountToken: false
nodeSelector:
kubernetes.io/arch: arm64
imagePullSecrets:
- name: harbor-registry
terminationGracePeriodSeconds: 60
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
containers:
- name: app
image: registry.dahyeon.us/dahyeon/make-space
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
envFrom:
- configMapRef:
name: make-space-config
- secretRef:
name: make-space-secrets
ports:
- name: http
containerPort: 3000
protocol: TCP
startupProbe:
httpGet:
path: /health/live
port: http
periodSeconds: 5
failureThreshold: 24
livenessProbe:
httpGet:
path: /health/live
port: http
periodSeconds: 15
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /health/live
port: http
periodSeconds: 10
timeoutSeconds: 3
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: "2"
memory: 1Gi
+13
View File
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- services.yaml
- serviceaccount.yaml
- poddisruptionbudget.yaml
labels:
- includeSelectors: true
pairs:
app.kubernetes.io/name: make-space
app.kubernetes.io/part-of: make-space
app.kubernetes.io/managed-by: kustomize
@@ -0,0 +1,10 @@
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: make-space
spec:
minAvailable: 1
selector:
matchLabels:
app.kubernetes.io/name: make-space
app.kubernetes.io/component: app
+5
View File
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: make-space
automountServiceAccountToken: false
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: make-space
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: make-space
app.kubernetes.io/component: app
ports:
- name: http
port: 3000
targetPort: http
protocol: TCP
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: make-space-config
data:
APP_ENV: production
HOST: 0.0.0.0
PORT: "3000"
LEPTOS_OUTPUT_NAME: make-space
LEPTOS_SITE_ADDR: 0.0.0.0:3000
LEPTOS_SITE_ROOT: /app/site
LEPTOS_SITE_PKG_DIR: pkg
MONGODB_DB: make_space
MINIO_ENDPOINT: https://s3.dahyeon.us
MINIO_BUCKET: make-space-photos
MAX_PHOTOS_PER_SOURCE: "40"
MAX_PHOTOS_TOTAL: "120"
RUST_LOG: info,server=info,pipeline=info,providers=info
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: make-space
spec:
template:
metadata:
labels:
app.kubernetes.io/environment: prod
@@ -0,0 +1,21 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: make-space-secrets
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: e60bd852-956a-454c-aaeb-65bd0cf418a9
environmentSlug: prod
secretPath: /
recursive: true
targets:
- name: make-space-secrets
namespace: make-space-prod
kind: Secret
creationPolicy: Owner
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: make-space
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
haproxy.org/ssl-redirect: 'false'
spec:
ingressClassName: haproxy
tls:
- hosts:
- make-space.dahyeon.us
secretName: make-space-prod-tls
rules:
- host: make-space.dahyeon.us
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: make-space
port:
number: 3000
@@ -0,0 +1,19 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: make-space-prod
resources:
- ../../base
- configmap.yaml
- infisical-secret.yaml
- ingress.yaml
images:
- name: registry.dahyeon.us/dahyeon/make-space
newName: registry.dahyeon.us/dahyeon/make-space
digest: sha256:87674fd46d9d19b22f7f0b7bfe9e0f8428795d1635ff89f7937dd0ce9a92a8e1
replicas:
- name: make-space
count: 1
patches:
- path: deployment-patch.yaml
commonAnnotations:
make-space.dahyeon.us/source-revision: 6a157a2eca0cfe85aae4e6810da799ca54ce0c21
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: make-space-config
data:
APP_ENV: staging
HOST: 0.0.0.0
PORT: "3000"
LEPTOS_OUTPUT_NAME: make-space
LEPTOS_SITE_ADDR: 0.0.0.0:3000
LEPTOS_SITE_ROOT: /app/site
LEPTOS_SITE_PKG_DIR: pkg
MONGODB_DB: make_space
MINIO_ENDPOINT: https://s3.dahyeon.us
MINIO_BUCKET: make-space-photos
MAX_PHOTOS_PER_SOURCE: "40"
MAX_PHOTOS_TOTAL: "120"
RUST_LOG: info,server=debug,pipeline=debug,providers=debug
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: make-space
spec:
template:
metadata:
labels:
app.kubernetes.io/environment: staging
@@ -0,0 +1,21 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: make-space-secrets
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: e60bd852-956a-454c-aaeb-65bd0cf418a9
environmentSlug: staging
secretPath: /
recursive: true
targets:
- name: make-space-secrets
namespace: make-space-staging
kind: Secret
creationPolicy: Owner
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: make-space
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
haproxy.org/ssl-redirect: 'false'
spec:
ingressClassName: haproxy
tls:
- hosts:
- make-space-staging.dahyeon.us
secretName: make-space-staging-tls
rules:
- host: make-space-staging.dahyeon.us
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: make-space
port:
number: 3000
@@ -0,0 +1,19 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: make-space-staging
resources:
- ../../base
- configmap.yaml
- infisical-secret.yaml
- ingress.yaml
images:
- name: registry.dahyeon.us/dahyeon/make-space
newName: registry.dahyeon.us/dahyeon/make-space
digest: sha256:aa3da3c933fa99e507f3782906a551868edb830a01658148d259095ed8618eb0
replicas:
- name: make-space
count: 1
patches:
- path: deployment-patch.yaml
commonAnnotations:
make-space.dahyeon.us/source-revision: b43b060c8a1f6f2de9927cbfbcf561d0000fe0c4
+9
View File
@@ -0,0 +1,9 @@
# URL shortener
- 환경: `overlays/staging`, `overlays/prod`
- 이미지: `registry.dahyeon.us/dahyeon/url-shortener`
- Harbor pull Secret: `harbor-registry`
- 앱 Secret: `url-shortener-secrets` (Infisical)
앱 저장소의 `staging`/`prod` 브랜치 push → 해당 Tekton Pipeline → 환경별 GitOps 갱신 → Argo CD 자동 Sync.
이 저장소는 `main`의 환경별 overlay를 유지하며, 앱의 `main` push는 배포하지 않습니다.
+89
View File
@@ -0,0 +1,89 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: url-shortener
labels:
app.kubernetes.io/component: app
spec:
replicas: 0
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/component: app
template:
metadata:
labels:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/component: app
spec:
serviceAccountName: url-shortener
automountServiceAccountToken: false
imagePullSecrets:
- name: harbor-registry
terminationGracePeriodSeconds: 120
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/component: app
topologyKey: kubernetes.io/hostname
containers:
- name: app
image: registry.dahyeon.us/dahyeon/url-shortener
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
envFrom:
- configMapRef:
name: url-shortener-config
- secretRef:
name: url-shortener-secrets
ports:
- name: http
containerPort: 3000
protocol: TCP
startupProbe:
httpGet:
path: /health/live
port: http
periodSeconds: 5
failureThreshold: 24
livenessProbe:
httpGet:
path: /health/live
port: http
periodSeconds: 15
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /health/ready
port: http
periodSeconds: 10
timeoutSeconds: 3
resources:
requests:
cpu: 50m
memory: 128Mi
limits:
cpu: "1"
memory: 512Mi
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- services.yaml
- serviceaccount.yaml
- poddisruptionbudget.yaml
labels:
- includeSelectors: true
pairs:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/part-of: url-shortener
app.kubernetes.io/managed-by: kustomize
@@ -0,0 +1,10 @@
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: url-shortener
spec:
minAvailable: 1
selector:
matchLabels:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/component: app
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: url-shortener
automountServiceAccountToken: false
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: url-shortener
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/component: app
ports:
- name: http
port: 3000
targetPort: http
protocol: TCP
@@ -0,0 +1,20 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: url-shortener-config
data:
APP_ENV: prod
HOST: 0.0.0.0
PORT: "3000"
DEV_AUTH_ENABLED: "false"
APP_ORIGIN: https://urls.dahyeon.us
API_ORIGIN: https://urls-api.dahyeon.us
SHORT_ORIGIN: https://rabbitma.us
SESSION_HOURS: "8"
# Set during promotion; database ID must match deploy/cloudflare/prod.json in the source revision.
CLOUDFLARE_ACCOUNT_ID: "e80e9f6a4c0ce49c1047c970919f3aa6"
CLOUDFLARE_D1_DATABASE_ID: "c01c4d75-90d8-424e-b9d4-717e3ee4de35"
PUBLISH_WAIT_MS: "1500"
JOB_POLL_MS: "1000"
STATS_INTERVAL_MS: "60000"
API_RATE_LIMIT: "300"
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: url-shortener
spec:
template:
metadata:
labels:
app.kubernetes.io/environment: prod
@@ -0,0 +1,38 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: url-shortener-secrets
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: 01c4ebe5-8c73-475c-ba29-56709483b0f1
environmentSlug: prod
secretPath: /
recursive: false
targets:
- name: url-shortener-secrets
namespace: url-shortener-prod
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
MONGODB_CONNECTION_STRING: "{{ .MONGODB_CONNECTION_STRING.Value }}"
MICROSOFT_ENTRAID_TENANT_ID: "{{ .MICROSOFT_ENTRAID_TENANT_ID.Value }}"
MICROSOFT_ENTRAID_CLIENT_ID: "{{ .MICROSOFT_ENTRAID_CLIENT_ID.Value }}"
MICROSOFT_ENTRAID_CLIENT_SECRET: "{{ .MICROSOFT_ENTRAID_CLIENT_SECRET.Value }}"
MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS: "{{ .MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS.Value }}"
CLOUDFLARE_D1_API_TOKEN: "{{ .CLOUDFLARE_D1_API_TOKEN.Value }}"
INGEST_HMAC_SECRET: "{{ .INGEST_HMAC_SECRET.Value }}"
NEW_RELIC_LICENSE_KEY: "{{ .NEW_RELIC_LICENSE_KEY.Value }}"
MONGODB_DATABASE: "{{ .MONGODB_DATABASE.Value }}"
LOG_LEVEL: "{{ .LOG_LEVEL.Value }}"
NEW_RELIC_APP_NAME: "{{ .NEW_RELIC_APP_NAME.Value }}"
NEW_RELIC_ENABLED: "{{ .NEW_RELIC_ENABLED.Value }}"
NEW_RELIC_LOG_LEVEL: "{{ .NEW_RELIC_LOG_LEVEL.Value }}"
@@ -0,0 +1,44 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: url-shortener-api
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: haproxy
tls:
- hosts:
- urls-api.dahyeon.us
secretName: url-shortener-api-prod-tls
rules:
- host: urls-api.dahyeon.us
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: url-shortener
port:
number: 3000
- path: /auth
pathType: Prefix
backend:
service:
name: url-shortener
port:
number: 3000
- path: /service/v1
pathType: Prefix
backend:
service:
name: url-shortener
port:
number: 3000
- path: /ingest/v1/clicks
pathType: Exact
backend:
service:
name: url-shortener
port:
number: 3000
@@ -0,0 +1,19 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: url-shortener-prod
resources:
- ../../base
- configmap.yaml
- infisical-secret.yaml
- ingress.yaml
images:
- name: registry.dahyeon.us/dahyeon/url-shortener
newName: registry.dahyeon.us/dahyeon/url-shortener
digest: sha256:990c8b40c36ef4d655d76f0c176b8f1a07068a571d7ce7784dfe6ff5b03713b7
replicas:
- name: url-shortener
count: 2
patches:
- path: deployment-patch.yaml
commonAnnotations:
url-shortener.dahyeon.us/source-revision: 93c79698083efe0bd87a9435e3adc70be4d3e458
@@ -0,0 +1,20 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: url-shortener-config
data:
APP_ENV: staging
HOST: 0.0.0.0
PORT: "3000"
DEV_AUTH_ENABLED: "false"
APP_ORIGIN: https://urls-staging.dahyeon.us
API_ORIGIN: https://urls-api-staging.dahyeon.us
SHORT_ORIGIN: https://staging.rabbitma.us
SESSION_HOURS: "8"
# Tekton copies these public identifiers from its Cloudflare account and the source D1 profile.
CLOUDFLARE_ACCOUNT_ID: "e80e9f6a4c0ce49c1047c970919f3aa6"
CLOUDFLARE_D1_DATABASE_ID: "6c24c97b-5c1f-46b9-b345-e6336567cbdb"
PUBLISH_WAIT_MS: "1500"
JOB_POLL_MS: "1000"
STATS_INTERVAL_MS: "60000"
API_RATE_LIMIT: "300"
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: url-shortener
spec:
template:
metadata:
labels:
app.kubernetes.io/environment: staging
@@ -0,0 +1,38 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: url-shortener-secrets
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: 01c4ebe5-8c73-475c-ba29-56709483b0f1
environmentSlug: staging
secretPath: /
recursive: false
targets:
- name: url-shortener-secrets
namespace: url-shortener-staging
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
MONGODB_CONNECTION_STRING: "{{ .MONGODB_CONNECTION_STRING.Value }}"
MICROSOFT_ENTRAID_TENANT_ID: "{{ .MICROSOFT_ENTRAID_TENANT_ID.Value }}"
MICROSOFT_ENTRAID_CLIENT_ID: "{{ .MICROSOFT_ENTRAID_CLIENT_ID.Value }}"
MICROSOFT_ENTRAID_CLIENT_SECRET: "{{ .MICROSOFT_ENTRAID_CLIENT_SECRET.Value }}"
MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS: "{{ .MICROSOFT_ENTRAID_BOOTSTRAP_ADMIN_OIDS.Value }}"
CLOUDFLARE_D1_API_TOKEN: "{{ .CLOUDFLARE_D1_API_TOKEN.Value }}"
INGEST_HMAC_SECRET: "{{ .INGEST_HMAC_SECRET.Value }}"
NEW_RELIC_LICENSE_KEY: "{{ .NEW_RELIC_LICENSE_KEY.Value }}"
MONGODB_DATABASE: "{{ .MONGODB_DATABASE.Value }}"
LOG_LEVEL: "{{ .LOG_LEVEL.Value }}"
NEW_RELIC_APP_NAME: "{{ .NEW_RELIC_APP_NAME.Value }}"
NEW_RELIC_ENABLED: "{{ .NEW_RELIC_ENABLED.Value }}"
NEW_RELIC_LOG_LEVEL: "{{ .NEW_RELIC_LOG_LEVEL.Value }}"
@@ -0,0 +1,44 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: url-shortener-api
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: haproxy
tls:
- hosts:
- urls-api-staging.dahyeon.us
secretName: url-shortener-api-staging-tls
rules:
- host: urls-api-staging.dahyeon.us
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: url-shortener
port:
number: 3000
- path: /auth
pathType: Prefix
backend:
service:
name: url-shortener
port:
number: 3000
- path: /service/v1
pathType: Prefix
backend:
service:
name: url-shortener
port:
number: 3000
- path: /ingest/v1/clicks
pathType: Exact
backend:
service:
name: url-shortener
port:
number: 3000
@@ -0,0 +1,19 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: url-shortener-staging
resources:
- ../../base
- configmap.yaml
- infisical-secret.yaml
- ingress.yaml
images:
- name: registry.dahyeon.us/dahyeon/url-shortener
newName: registry.dahyeon.us/dahyeon/url-shortener
digest: sha256:2944112942f7562b55652bae31d74cb7dcf6e24bb08d64a8c1ba527083745fcd
replicas:
- name: url-shortener
count: 2
patches:
- path: deployment-patch.yaml
commonAnnotations:
url-shortener.dahyeon.us/source-revision: 93c79698083efe0bd87a9435e3adc70be4d3e458
+47
View File
@@ -0,0 +1,47 @@
# Blog CI/CD
`staging`·`prod` push를 배포합니다. Webhook: `https://tekton-hook.dahyeon.us/blog`
| 브랜치 | Pipeline | 서비스 URL |
| --- | --- | --- |
| `staging` | `blog-staging` | `https://blog-staging.dahyeon.us` |
| `prod` | `blog-prod` | `https://rabbitmaus.com` |
## CDN 설정
[pipeline.yaml](pipeline.yaml)의 Pipeline 파라미터 기본값을 수정합니다.
| 파라미터 | prod | staging |
| --- | --- | --- |
| `CDN_URL_PREFIX` | `blog` | `blog-staging` |
| `CDN_BASE_URL` | `https://cdn.rabbitmaus.com` | 동일 |
| `CDN_S3_BUCKET_NAME` | `rabbitmaus` | 동일 |
| `AWS_REGION` | `ap-southeast-2` | 동일 |
## 자격 증명
Infisical 플랫폼 프로젝트 `8520b8c0-3796-4fd6-a03c-6f0508c8c42c`, 환경 `prod`, 경로 `/platform/tekton/blog`:
| 키 | 용도 |
| --- | --- |
| `GITEA_USERNAME` | Git bot 계정 |
| `GITEA_TOKEN` | 소스 읽기·service-state 쓰기 |
| `HARBOR_DOCKER_CONFIG_JSON` | 이미지 push |
| `GITEA_WEBHOOK_SECRET` | Webhook 서명 검증 |
| `AWS_ACCESS_KEY_ID` | S3 업로드 |
| `AWS_SECRET_ACCESS_KEY` | S3 업로드 |
S3 권한: `rabbitmaus/blog/*`, `rabbitmaus/blog-staging/*`에 `s3:PutObject`, `s3:GetObject`.
앱 런타임 Secret은 [앱 설정](../../apps/blog/README.md)을 참고합니다.
## 검증·상태 확인
저장소 루트에서 실행합니다.
```sh
kubectl kustomize ci/blog
kubectl apply --dry-run=server -k ci/blog
node ../blog/tools/cdn/verify-pipeline.mjs . ../platform-state
kubectl -n tekton-ci get pipelineruns -l app.kubernetes.io/name=blog
kubectl -n argocd get application blog-ci
```
+55
View File
@@ -0,0 +1,55 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: blog-pipeline
automountServiceAccountToken: false
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: blog-event-listener
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: blog-event-listener
rules:
- apiGroups: [tekton.dev]
resources: [pipelineruns]
verbs: [create, get, list]
- apiGroups: [triggers.tekton.dev]
resources:
[
eventlisteners,
interceptors,
triggerbindings,
triggertemplates,
triggers,
]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [configmaps]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [serviceaccounts]
resourceNames: [blog-pipeline]
verbs: [impersonate]
- apiGroups: [""]
resources: [events]
verbs: [create, patch]
- apiGroups: [""]
resources: [secrets]
resourceNames: [blog-webhook]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: blog-event-listener
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: blog-event-listener
subjects:
- kind: ServiceAccount
name: blog-event-listener
+55
View File
@@ -0,0 +1,55 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: blog-ci-credentials
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: 8520b8c0-3796-4fd6-a03c-6f0508c8c42c
environmentSlug: prod
secretPath: /platform/tekton/blog
recursive: false
targets:
- name: blog-gitea
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: kubernetes.io/basic-auth
template:
engineVersion: v1
data:
username: "{{ .GITEA_USERNAME.Value }}"
password: "{{ .GITEA_TOKEN.Value }}"
- name: blog-harbor
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: kubernetes.io/dockerconfigjson
template:
engineVersion: v1
data:
.dockerconfigjson: "{{ .HARBOR_DOCKER_CONFIG_JSON.Value }}"
- name: blog-webhook
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
secretToken: "{{ .GITEA_WEBHOOK_SECRET.Value }}"
- name: blog-cdn
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
AWS_ACCESS_KEY_ID: "{{ .AWS_ACCESS_KEY_ID.Value }}"
AWS_SECRET_ACCESS_KEY: "{{ .AWS_SECRET_ACCESS_KEY.Value }}"
+23
View File
@@ -0,0 +1,23 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: blog-main-webhook
annotations:
haproxy.org/ssl-redirect: 'false'
spec:
ingressClassName: haproxy
tls:
- hosts: [tekton-hook.dahyeon.us]
# The existing lolympus Ingress owns issuance for this shared hostname.
secretName: lolympus-main-webhook-tls
rules:
- host: tekton-hook.dahyeon.us
http:
paths:
- path: /blog
pathType: Prefix
backend:
service:
name: el-blog-main
port:
number: 8080
+16
View File
@@ -0,0 +1,16 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: tekton-ci
resources:
- foundation.yaml
- infisical-secret.yaml
- tasks.yaml
- pipeline.yaml
- trigger.yaml
- ingress.yaml
labels:
- includeSelectors: false
pairs:
app.kubernetes.io/name: blog
app.kubernetes.io/part-of: blog-ci
app.kubernetes.io/managed-by: argocd
+223
View File
@@ -0,0 +1,223 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: blog-staging
spec:
description: Validate an exact staging revision, publish the arm64 image and verify its S3 CDN release, then update staging GitOps.
params:
- name: git-revision
type: string
- name: CDN_URL_PREFIX
type: string
default: blog-staging
- name: CDN_BASE_URL
type: string
default: https://cdn.rabbitmaus.com
- name: CDN_S3_BUCKET_NAME
type: string
default: rabbitmaus
- name: AWS_REGION
type: string
default: ap-southeast-2
results:
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
- name: cdn-release-id
value: $(tasks.build-arm64.results.cdn-release-id)
- name: cdn-manifest-key
value: $(tasks.build-arm64.results.cdn-manifest-key)
- name: gitops-commit
value: $(tasks.update-gitops.results.gitops-commit)
workspaces:
- name: source
- name: gitea-credentials
- name: harbor-dockerconfig
tasks:
- name: clone
taskRef:
name: blog-clone
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: staging
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: quality
runAfter:
- clone
taskRef:
name: blog-quality
params:
- name: environment
value: staging
workspaces:
- name: source
workspace: source
- name: dockerconfig
workspace: harbor-dockerconfig
- name: build-arm64
runAfter:
- quality
taskRef:
name: blog-build-arm64
params:
- name: revision
value: $(params.git-revision)
- name: image
value: registry.dahyeon.us/dahyeon/blog:sha-$(params.git-revision)-$(context.pipelineRun.uid)
- name: pipeline-run-uid
value: $(context.pipelineRun.uid)
- name: CDN_URL_PREFIX
value: $(params.CDN_URL_PREFIX)
- name: CDN_BASE_URL
value: $(params.CDN_BASE_URL)
- name: CDN_S3_BUCKET_NAME
value: $(params.CDN_S3_BUCKET_NAME)
- name: AWS_REGION
value: $(params.AWS_REGION)
- name: environment
value: staging
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: update-gitops
runAfter:
- build-arm64
taskRef:
name: blog-update-gitops
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: staging
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
- name: cdn-release-id
value: $(tasks.build-arm64.results.cdn-release-id)
- name: cdn-manifest-key
value: $(tasks.build-arm64.results.cdn-manifest-key)
- name: CDN_URL_PREFIX
value: $(params.CDN_URL_PREFIX)
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: blog-prod
spec:
description: Validate an exact prod revision, publish the arm64 image and verify its S3 CDN release, then update production GitOps.
params:
- name: git-revision
type: string
- name: CDN_URL_PREFIX
type: string
default: blog
- name: CDN_BASE_URL
type: string
default: https://cdn.rabbitmaus.com
- name: CDN_S3_BUCKET_NAME
type: string
default: rabbitmaus
- name: AWS_REGION
type: string
default: ap-southeast-2
results:
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
- name: cdn-release-id
value: $(tasks.build-arm64.results.cdn-release-id)
- name: cdn-manifest-key
value: $(tasks.build-arm64.results.cdn-manifest-key)
- name: gitops-commit
value: $(tasks.update-gitops.results.gitops-commit)
workspaces:
- name: source
- name: gitea-credentials
- name: harbor-dockerconfig
tasks:
- name: clone
taskRef:
name: blog-clone
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: prod
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: quality
runAfter:
- clone
taskRef:
name: blog-quality
params:
- name: environment
value: prod
workspaces:
- name: source
workspace: source
- name: dockerconfig
workspace: harbor-dockerconfig
- name: build-arm64
runAfter:
- quality
taskRef:
name: blog-build-arm64
params:
- name: revision
value: $(params.git-revision)
- name: image
value: registry.dahyeon.us/dahyeon/blog:sha-$(params.git-revision)-$(context.pipelineRun.uid)
- name: pipeline-run-uid
value: $(context.pipelineRun.uid)
- name: CDN_URL_PREFIX
value: $(params.CDN_URL_PREFIX)
- name: CDN_BASE_URL
value: $(params.CDN_BASE_URL)
- name: CDN_S3_BUCKET_NAME
value: $(params.CDN_S3_BUCKET_NAME)
- name: AWS_REGION
value: $(params.AWS_REGION)
- name: environment
value: prod
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: update-gitops
runAfter:
- build-arm64
taskRef:
name: blog-update-gitops
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: prod
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
- name: cdn-release-id
value: $(tasks.build-arm64.results.cdn-release-id)
- name: cdn-manifest-key
value: $(tasks.build-arm64.results.cdn-manifest-key)
- name: CDN_URL_PREFIX
value: $(params.CDN_URL_PREFIX)
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
+596
View File
@@ -0,0 +1,596 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: blog-clone
spec:
description: Clone the pushed source revision and verify the selected deployment branch.
params:
- name: revision
type: string
- name: environment
type: string
default: staging
workspaces:
- name: source
- name: credentials
readOnly: true
steps:
- name: clone
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: "1"
memory: 1Gi
env:
- name: REPO_URL
value: https://git.dahyeon.us/dahyeon/blog.git
- name: REVISION
value: $(params.revision)
- name: DEPLOY_ENV
value: $(params.environment)
- name: SOURCE_DIR
value: $(workspaces.source.path)
- name: GITEA_CREDENTIALS_DIR
value: $(workspaces.credentials.path)
script: |
#!/bin/sh
set -eu
umask 0002
case "$DEPLOY_ENV" in staging|prod) ;; *) echo 'Invalid deployment environment' >&2; exit 1;; esac
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
test "$REVISION" != '0000000000000000000000000000000000000000'
case "$SOURCE_DIR" in /workspace/*) ;; *) echo 'Unexpected workspace path' >&2; exit 1;; esac
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
REMOTE_REVISION="$(git ls-remote "$REPO_URL" "refs/heads/$DEPLOY_ENV" | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
echo 'Source revision was superseded before checkout.' >&2
exit 1
fi
find "$SOURCE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
git clone --quiet --no-tags "$REPO_URL" "$SOURCE_DIR"
git -C "$SOURCE_DIR" checkout --quiet --detach "$REVISION"
test "$(git -C "$SOURCE_DIR" rev-parse HEAD)" = "$REVISION"
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: blog-quality
spec:
description: Run the Dockerfile quality target with a branch-scoped registry cache and no runtime credentials.
params:
- name: environment
type: string
default: staging
workspaces:
- name: source
readOnly: true
- name: dockerconfig
readOnly: true
volumes:
- name: buildkit-state
emptyDir: {}
steps:
- name: verify-rust
image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c
computeResources:
requests:
cpu: 500m
memory: 6Gi
limits:
cpu: "4"
memory: 20Gi
securityContext:
privileged: false
allowPrivilegeEscalation: true
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: Unconfined
appArmorProfile:
type: Unconfined
volumeMounts:
- name: buildkit-state
mountPath: /home/user/.local/share/buildkit
env:
- name: BUILDKITD_FLAGS
value: --oci-worker-no-process-sandbox
- name: DOCKER_CONFIG
value: $(workspaces.dockerconfig.path)
- name: SOURCE_DIR
value: $(workspaces.source.path)
- name: DEPLOY_ENV
value: $(params.environment)
- name: CACHE_REPOSITORY
value: registry.dahyeon.us/dahyeon/blog
script: |
#!/bin/sh
set -eu
case "$DEPLOY_ENV" in staging|prod) ;; *) echo 'Invalid deployment environment' >&2; exit 1;; esac
# Export dependencies before checking the app, so a failed check does
# not discard all the work performed by this ephemeral builder.
buildctl-daemonless.sh build \
--frontend dockerfile.v0 \
--local context="$SOURCE_DIR" \
--local dockerfile="$SOURCE_DIR" \
--opt filename=Dockerfile \
--opt target=quality-deps \
--opt platform=linux/arm64 \
--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" \
--import-cache "type=registry,ref=$CACHE_REPOSITORY:cache-release-arm64-$DEPLOY_ENV" \
--export-cache "type=registry,ref=$CACHE_REPOSITORY:cache-quality-deps-arm64-$DEPLOY_ENV,mode=max,image-manifest=true,oci-mediatypes=true"
buildctl-daemonless.sh build \
--frontend dockerfile.v0 \
--local context="$SOURCE_DIR" \
--local dockerfile="$SOURCE_DIR" \
--opt filename=Dockerfile \
--opt target=quality \
--opt platform=linux/arm64 \
--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" \
--import-cache "type=registry,ref=$CACHE_REPOSITORY:cache-release-arm64-$DEPLOY_ENV" \
--export-cache "type=registry,ref=$CACHE_REPOSITORY:cache-quality-arm64-$DEPLOY_ENV,mode=max,image-manifest=true,oci-mediatypes=true"
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: blog-build-arm64
spec:
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: CDN_URL_PREFIX
type: string
- name: CDN_BASE_URL
type: string
- name: CDN_S3_BUCKET_NAME
type: string
- name: AWS_REGION
type: string
- name: environment
type: string
default: staging
results:
- name: image-url
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
- name: dockerconfig
readOnly: true
volumes:
- name: build-source
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_URL_PREFIX
value: $(params.CDN_URL_PREFIX)
- name: CDN_BASE_URL
value: $(params.CDN_BASE_URL)
- name: CDN_S3_BUCKET_NAME
value: $(params.CDN_S3_BUCKET_NAME)
- name: AWS_REGION
value: $(params.AWS_REGION)
steps:
- name: clone-source
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: "1"
memory: 1Gi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
workspaces:
- name: credentials
volumeMounts:
- name: build-source
mountPath: /workspace/build
env:
- name: REPO_URL
value: https://git.dahyeon.us/dahyeon/blog.git
- name: REVISION
value: $(params.revision)
- name: GITEA_CREDENTIALS_DIR
value: $(workspaces.credentials.path)
script: |
#!/bin/sh
set -eu
umask 0002
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
test "$REVISION" != '0000000000000000000000000000000000000000'
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
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
# The checkout must be created by clone-source as UID 1000, not by container startup.
workingDir: /workspace/build
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
cd /workspace/build/source
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:
requests:
cpu: "1"
memory: 2Gi
limits:
cpu: "4"
memory: 20Gi
securityContext:
privileged: false
allowPrivilegeEscalation: true
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: Unconfined
appArmorProfile:
type: Unconfined
workspaces:
- name: dockerconfig
volumeMounts:
- name: build-source
mountPath: /workspace/build
- name: buildkit-state
mountPath: /home/user/.local/share/buildkit
env:
- name: BUILDKITD_FLAGS
value: --oci-worker-no-process-sandbox
- name: DOCKER_CONFIG
value: $(workspaces.dockerconfig.path)
- name: IMAGE
value: $(params.image)
- name: DEPLOY_ENV
value: $(params.environment)
- name: CACHE_REPOSITORY
value: registry.dahyeon.us/dahyeon/blog
- name: METADATA_FILE
value: /workspace/build/build-metadata.json
script: |
#!/bin/sh
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_ID="$(cat /workspace/build/release-id)"
printf '%s\n' "$CDN_RELEASE_ID" | grep -Eq '^[0-9a-f]{16}$'
buildctl-daemonless.sh build \
--frontend dockerfile.v0 \
--local context=/workspace/build/source \
--local dockerfile=/workspace/build/source \
--opt filename=Dockerfile \
--opt target=runtime \
--opt platform=linux/arm64 \
--opt "build-arg:CDN_BASE_URL=$CDN_BASE_URL" \
--opt "build-arg:CDN_URL_PREFIX=$CDN_URL_PREFIX" \
--opt "build-arg:CDN_RELEASE_ID=$CDN_RELEASE_ID" \
--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
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 250m
memory: 256Mi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- name: build-source
mountPath: /workspace/build
readOnly: true
env:
- name: IMAGE
value: $(params.image)
- name: METADATA_FILE
value: /workspace/build/build-metadata.json
- name: DIGEST_RESULT_PATH
value: $(results.image-digest.path)
- name: IMAGE_RESULT_PATH
value: $(results.image-url.path)
script: |
#!/bin/sh
set -eu
DIGEST="$(yq -r '."containerimage.digest"' "$METADATA_FILE")"
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
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
cd /workspace/build/source
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
metadata:
name: blog-update-gitops
spec:
description: Publish the selected environment's app digest to service-state keeping replicas at 1.
params:
- name: revision
type: string
- name: image-digest
type: string
- name: cdn-release-id
type: string
- name: cdn-manifest-key
type: string
- name: CDN_URL_PREFIX
type: string
- name: environment
type: string
default: staging
results:
- name: gitops-commit
description: Commit pushed to service-state main.
workspaces:
- name: source
- name: credentials
readOnly: true
stepTemplate:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
env:
- name: STATE_REPO_URL
value: https://git.dahyeon.us/dahyeon/service-state.git
- name: SOURCE_REPO_URL
value: https://git.dahyeon.us/dahyeon/blog.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
value: $(workspaces.credentials.path)
steps:
- name: clone-state
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 512Mi
script: |
#!/bin/sh
set -eu
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
case "$STATE_DIR" in /workspace/*/.cache/gitops-state) ;; *) echo 'Unexpected GitOps path' >&2; exit 1;; esac
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
rm -rf "$STATE_DIR"
git clone --quiet --depth=1 --branch main "$STATE_REPO_URL" "$STATE_DIR"
- name: update-manifest
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 250m
memory: 256Mi
env:
- name: APP_IMAGE
value: registry.dahyeon.us/dahyeon/blog
- name: IMAGE_DIGEST
value: $(params.image-digest)
- name: CDN_RELEASE_ID
value: $(params.cdn-release-id)
- name: CDN_MANIFEST_KEY
value: $(params.cdn-manifest-key)
- name: CDN_URL_PREFIX
value: $(params.CDN_URL_PREFIX)
- name: DEPLOYMENT_NAME
value: blog
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' "$CDN_RELEASE_ID" | grep -Eq '^[0-9a-f]{16}$'
printf '%s\n' "$CDN_URL_PREFIX" | grep -Eq '^[a-z][a-z0-9-]{0,62}$'
test "$CDN_MANIFEST_KEY" = "$CDN_URL_PREFIX/_releases/$CDN_RELEASE_ID/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_ID)' "$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:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 512Mi
env:
- name: GITOPS_RESULT_PATH
value: $(results.gitops-commit.path)
script: |
#!/bin/sh
set -eu
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
BASE_COMMIT="$(git -C "$STATE_DIR" rev-parse HEAD)"
REMOTE_STATE="$(git ls-remote "$STATE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_STATE" != "$BASE_COMMIT" ]; then
echo 'service-state advanced; rerun from the latest source. No automatic rebase or force push.' >&2
exit 1
fi
git -C "$STATE_DIR" config user.name blog-tekton
git -C "$STATE_DIR" config user.email tekton@dahyeon.us
if git -C "$STATE_DIR" diff --quiet; then
git -C "$STATE_DIR" rev-parse HEAD >"$GITOPS_RESULT_PATH"
exit 0
fi
git -C "$STATE_DIR" add "apps/blog/overlays/$DEPLOY_ENV/kustomization.yaml"
git -C "$STATE_DIR" commit -m "chore(blog): deploy $DEPLOY_ENV $REVISION"
REMOTE_REVISION="$(git ls-remote "$SOURCE_REPO_URL" "refs/heads/$DEPLOY_ENV" | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
echo 'Source revision was superseded before GitOps push.' >&2
exit 1
fi
git -C "$STATE_DIR" push origin HEAD:main
git -C "$STATE_DIR" rev-parse HEAD >"$GITOPS_RESULT_PATH"
+102
View File
@@ -0,0 +1,102 @@
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
name: blog-main
spec:
params:
- name: git-revision
value: $(body.after)
- name: environment
value: $(extensions.environment)
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: blog-main
spec:
params:
- name: git-revision
- name: environment
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: blog-$(tt.params.environment)-
labels:
app.kubernetes.io/name: blog
app.kubernetes.io/part-of: blog-ci
spec:
pipelineRef:
name: blog-$(tt.params.environment)
params:
- name: git-revision
value: $(tt.params.git-revision)
taskRunTemplate:
serviceAccountName: blog-pipeline
podTemplate:
nodeSelector:
kubernetes.io/arch: arm64
kubernetes.io/hostname: heize
securityContext:
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
workspaces:
- name: source
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 10Gi
- name: gitea-credentials
secret:
secretName: blog-gitea
items:
- key: username
path: username
- key: password
path: password
- name: harbor-dockerconfig
secret:
secretName: blog-harbor
items:
- key: .dockerconfigjson
path: config.json
timeouts:
pipeline: 90m
tasks: 85m
---
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: blog-main
spec:
serviceAccountName: blog-event-listener
triggers:
- name: branch-push
interceptors:
- ref:
name: github
params:
- name: secretRef
value:
secretName: blog-webhook
secretKey: secretToken
- name: eventTypes
value:
- push
- ref:
name: cel
params:
- name: filter
value: body.repository.full_name == 'dahyeon/blog' && body.ref in ['refs/heads/staging', 'refs/heads/prod'] && body.after.matches('^[0-9a-f]{40}$') && body.after != '0000000000000000000000000000000000000000'
- name: overlays
value:
- key: environment
expression: "body.ref.split('/')[2]"
bindings:
- ref: blog-main
template:
ref: blog-main
+1 -30
View File
@@ -1,34 +1,4 @@
apiVersion: v1 apiVersion: v1
kind: ResourceQuota
metadata:
name: lolympus-ci
spec:
hard:
pods: "20"
persistentvolumeclaims: "10"
requests.cpu: "8"
requests.memory: 16Gi
requests.storage: 100Gi
limits.cpu: "16"
limits.memory: 32Gi
count/pipelineruns.tekton.dev: "20"
count/taskruns.tekton.dev: "100"
---
apiVersion: v1
kind: LimitRange
metadata:
name: lolympus-ci
spec:
limits:
- type: Container
defaultRequest:
cpu: 100m
memory: 256Mi
default:
cpu: "2"
memory: 4Gi
---
apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
metadata: metadata:
name: lolympus-pipeline name: lolympus-pipeline
@@ -56,6 +26,7 @@ rules:
- triggers.tekton.dev - triggers.tekton.dev
resources: resources:
- eventlisteners - eventlisteners
- interceptors
- triggerbindings - triggerbindings
- triggertemplates - triggertemplates
- triggers - triggers
+51 -10
View File
@@ -11,8 +11,8 @@ spec:
type: string type: string
results: results:
- name: image-digest - name: image-digest
description: Immutable API image digest. description: Immutable multi-platform API image index digest.
value: $(tasks.build-api.results.image-digest) value: $(tasks.create-image-index.results.image-digest)
- name: gitops-commit - name: gitops-commit
description: service-state commit applied to staging. description: service-state commit applied to staging.
value: $(tasks.update-gitops.results.gitops-commit) value: $(tasks.update-gitops.results.gitops-commit)
@@ -40,22 +40,63 @@ spec:
workspaces: workspaces:
- name: source - name: source
workspace: source workspace: source
- name: build-api - name: build-api-amd64
runAfter: runAfter:
- quality - quality
taskRef: taskRef:
name: lolympus-build-image name: lolympus-build-platform
params:
- name: revision
value: $(params.git-revision)
- name: platform
value: linux/amd64
- name: image
value: registry.dahyeon.us/lolympus/lolympus-tournament-support:$(params.image-tag)-$(context.pipelineRun.uid)-amd64
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: build-api-arm64
runAfter:
- quality
taskRef:
name: lolympus-build-platform
params:
- name: revision
value: $(params.git-revision)
- name: platform
value: linux/arm64
- name: image
value: registry.dahyeon.us/lolympus/lolympus-tournament-support:$(params.image-tag)-$(context.pipelineRun.uid)-arm64
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: create-image-index
runAfter:
- build-api-amd64
- build-api-arm64
taskRef:
name: lolympus-create-image-index
params: params:
- name: image - name: image
value: registry.dahyeon.us/lolympus/lolympus-tournament-support:$(params.image-tag) value: registry.dahyeon.us/lolympus/lolympus-tournament-support:$(params.image-tag)-$(context.pipelineRun.uid)
- name: amd64-image
value: $(tasks.build-api-amd64.results.image-url)
- name: amd64-digest
value: $(tasks.build-api-amd64.results.image-digest)
- name: arm64-image
value: $(tasks.build-api-arm64.results.image-url)
- name: arm64-digest
value: $(tasks.build-api-arm64.results.image-digest)
workspaces: workspaces:
- name: source
workspace: source
- name: dockerconfig - name: dockerconfig
workspace: harbor-dockerconfig workspace: harbor-dockerconfig
- name: assert-latest - name: assert-latest
runAfter: runAfter:
- build-api - create-image-index
taskRef: taskRef:
name: lolympus-assert-latest name: lolympus-assert-latest
params: params:
@@ -80,8 +121,8 @@ spec:
params: params:
- name: revision - name: revision
value: $(params.git-revision) value: $(params.git-revision)
- name: image-tag - name: image-digest
value: $(params.image-tag) value: $(tasks.create-image-index.results.image-digest)
workspaces: workspaces:
- name: source - name: source
workspace: source workspace: source
+256 -43
View File
@@ -25,10 +25,10 @@ spec:
set -eu set -eu
SOURCE_DIR="$(workspaces.source.path)" SOURCE_DIR="$(workspaces.source.path)"
REVISION="$(params.revision)" REVISION="$(params.revision)"
AUTH_HOME="$$(mktemp -d)" AUTH_HOME="$(mktemp -d)"
trap 'rm -rf "$AUTH_HOME"' EXIT trap 'rm -rf "$AUTH_HOME"' EXIT
USERNAME="$$(cat "$(workspaces.credentials.path)/username")" USERNAME="$(cat "$(workspaces.credentials.path)/username")"
PASSWORD="$$(cat "$(workspaces.credentials.path)/password")" PASSWORD="$(cat "$(workspaces.credentials.path)/password")"
cat >"$AUTH_HOME/.netrc" <<EOF cat >"$AUTH_HOME/.netrc" <<EOF
machine git.dahyeon.us machine git.dahyeon.us
login $USERNAME login $USERNAME
@@ -39,7 +39,7 @@ spec:
find "$SOURCE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} + find "$SOURCE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
git clone --quiet --no-tags "$REPO_URL" "$SOURCE_DIR" git clone --quiet --no-tags "$REPO_URL" "$SOURCE_DIR"
git -C "$SOURCE_DIR" checkout --quiet --detach "$REVISION" git -C "$SOURCE_DIR" checkout --quiet --detach "$REVISION"
ACTUAL_REVISION="$$(git -C "$SOURCE_DIR" rev-parse HEAD)" ACTUAL_REVISION="$(git -C "$SOURCE_DIR" rev-parse HEAD)"
if [ "$ACTUAL_REVISION" != "$REVISION" ]; then if [ "$ACTUAL_REVISION" != "$REVISION" ]; then
echo "Expected revision $REVISION, got $ACTUAL_REVISION" >&2 echo "Expected revision $REVISION, got $ACTUAL_REVISION" >&2
exit 1 exit 1
@@ -59,8 +59,10 @@ spec:
env: env:
- name: CI - name: CI
value: "true" value: "true"
- name: COREPACK_HOME - name: NPM_CONFIG_CACHE
value: $(workspaces.source.path)/.ci/corepack value: $(workspaces.source.path)/.ci/npm-cache
- name: PATH
value: $(workspaces.source.path)/.ci/pnpm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
steps: steps:
- name: install - name: install
computeResources: computeResources:
@@ -69,7 +71,10 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
corepack pnpm install --frozen-lockfile mkdir -p .ci/pnpm .ci/npm-cache
npm install --global \
--prefix "$(workspaces.source.path)/.ci/pnpm" pnpm@10.4.1
pnpm install --frozen-lockfile
- name: lint - name: lint
computeResources: computeResources:
requests: {cpu: 100m, memory: 256Mi} requests: {cpu: 100m, memory: 256Mi}
@@ -77,9 +82,9 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
corepack pnpm --filter api exec eslint \ pnpm --filter api exec eslint \
"{src,apps,libs,test}/**/*.ts" --max-warnings=0 "{src,apps,libs,test}/**/*.ts" --max-warnings=0
corepack pnpm --filter web lint pnpm --filter web lint
- name: test - name: test
computeResources: computeResources:
requests: {cpu: 100m, memory: 512Mi} requests: {cpu: 100m, memory: 512Mi}
@@ -87,9 +92,9 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
corepack pnpm --filter api test -- --runInBand pnpm --filter api test --runInBand
corepack pnpm --filter web test pnpm --filter web test
corepack pnpm test:deploy:web node --test scripts/deploy-cloudflare-pages.test.mjs
- name: build - name: build
computeResources: computeResources:
requests: {cpu: 200m, memory: 512Mi} requests: {cpu: 200m, memory: 512Mi}
@@ -97,8 +102,8 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
corepack pnpm --filter api build pnpm --filter api build
corepack pnpm --filter web build:staging pnpm --filter web build:staging
- name: audit - name: audit
computeResources: computeResources:
requests: {cpu: 50m, memory: 128Mi} requests: {cpu: 50m, memory: 128Mi}
@@ -106,15 +111,19 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
corepack pnpm audit --prod --audit-level high pnpm audit --prod --audit-level high
--- ---
apiVersion: tekton.dev/v1 apiVersion: tekton.dev/v1
kind: Task kind: Task
metadata: metadata:
name: lolympus-build-image name: lolympus-build-platform
spec: spec:
description: Build and push the API image with rootless BuildKit. description: Clone an exact revision and build one native API platform with rootless BuildKit.
params: params:
- name: revision
type: string
- name: platform
type: string
- name: image - name: image
type: string type: string
results: results:
@@ -123,13 +132,64 @@ spec:
- name: image-digest - name: image-digest
description: Immutable digest returned by the registry. description: Immutable digest returned by the registry.
workspaces: workspaces:
- name: source - name: credentials
readOnly: true
- name: dockerconfig - name: dockerconfig
readOnly: true readOnly: true
volumes:
- name: build-source
emptyDir: {}
- name: buildkit-state
emptyDir: {}
steps: steps:
- name: clone-source
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests: {cpu: 100m, memory: 128Mi}
limits: {cpu: "1", memory: 1Gi}
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
workspaces:
- name: credentials
volumeMounts:
- name: build-source
mountPath: /workspace/build
env:
- name: REPO_URL
value: https://git.dahyeon.us/dahyeon/lolympus-tournament-support.git
script: |
#!/bin/sh
set -eu
SOURCE_DIR=/workspace/build/source
REVISION="$(params.revision)"
AUTH_HOME="$(mktemp -d)"
trap 'rm -rf "$AUTH_HOME"' EXIT
USERNAME="$(cat "$(workspaces.credentials.path)/username")"
PASSWORD="$(cat "$(workspaces.credentials.path)/password")"
cat >"$AUTH_HOME/.netrc" <<EOF
machine git.dahyeon.us
login $USERNAME
password $PASSWORD
EOF
chmod 0600 "$AUTH_HOME/.netrc"
export HOME="$AUTH_HOME"
rm -rf "$SOURCE_DIR"
git clone --quiet --no-tags "$REPO_URL" "$SOURCE_DIR"
git -C "$SOURCE_DIR" checkout --quiet --detach "$REVISION"
ACTUAL_REVISION="$(git -C "$SOURCE_DIR" rev-parse HEAD)"
if [ "$ACTUAL_REVISION" != "$REVISION" ]; then
echo "Expected revision $REVISION, got $ACTUAL_REVISION" >&2
exit 1
fi
- name: build-and-push - name: build-and-push
image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c
workingDir: $(workspaces.source.path) workingDir: /workspace/build
computeResources: computeResources:
requests: {cpu: "1", memory: 2Gi} requests: {cpu: "1", memory: 2Gi}
limits: {cpu: "4", memory: 8Gi} limits: {cpu: "4", memory: 8Gi}
@@ -143,7 +203,13 @@ spec:
type: Unconfined type: Unconfined
appArmorProfile: appArmorProfile:
type: Unconfined type: Unconfined
procMount: Unmasked workspaces:
- name: dockerconfig
volumeMounts:
- name: build-source
mountPath: /workspace/build
- name: buildkit-state
mountPath: /home/user/.local/share/buildkit
env: env:
- name: BUILDKITD_FLAGS - name: BUILDKITD_FLAGS
value: --oci-worker-no-process-sandbox value: --oci-worker-no-process-sandbox
@@ -152,23 +218,43 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
case "$(params.platform)" in
linux/amd64|linux/arm64) ;;
*)
echo "Unsupported platform: $(params.platform)" >&2
exit 1
;;
esac
cd /workspace/build/source
buildctl-daemonless.sh build \ buildctl-daemonless.sh build \
--frontend dockerfile.v0 \ --frontend dockerfile.v0 \
--local context=. \ --local context=. \
--local dockerfile=. \ --local dockerfile=. \
--opt filename=Dockerfile \ --opt filename=Dockerfile \
--opt platform=$(params.platform) \
--output "type=image,name=$(params.image),push=true" \ --output "type=image,name=$(params.image),push=true" \
--metadata-file "$(results.image-digest.path)" --metadata-file "$(results.image-digest.path)"
- name: record-digest - name: record-digest
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
workingDir: $(workspaces.source.path) workingDir: /workspace/build
computeResources: computeResources:
requests: {cpu: 50m, memory: 64Mi} requests: {cpu: 50m, memory: 64Mi}
limits: {cpu: 250m, memory: 256Mi} limits: {cpu: 250m, memory: 256Mi}
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- name: build-source
mountPath: /workspace/build
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
DIGEST="$$(yq -r '."containerimage.digest"' "$(results.image-digest.path)")" DIGEST="$(yq -r '."containerimage.digest"' "$(results.image-digest.path)")"
if [ -z "$DIGEST" ] || [ "$DIGEST" = "null" ]; then if [ -z "$DIGEST" ] || [ "$DIGEST" = "null" ]; then
echo "BuildKit did not return an image digest" >&2 echo "BuildKit did not return an image digest" >&2
exit 1 exit 1
@@ -178,6 +264,114 @@ spec:
--- ---
apiVersion: tekton.dev/v1 apiVersion: tekton.dev/v1
kind: Task kind: Task
metadata:
name: lolympus-create-image-index
spec:
description: Publish an OCI image index from the native amd64 and arm64 images.
params:
- name: image
type: string
- name: amd64-image
type: string
- name: amd64-digest
type: string
- name: arm64-image
type: string
- name: arm64-digest
type: string
results:
- name: image-url
description: Pushed multi-platform image repository and tag.
- name: image-digest
description: Immutable OCI image index digest returned by the registry.
workspaces:
- name: dockerconfig
readOnly: true
volumes:
- name: regctl-home
emptyDir: {}
steps:
- name: create-index
image: ghcr.io/regclient/regctl:v0.11.5-alpine@sha256:795e27a968ec0681cf1f4fd4bb83a880a1bc4698afb38efd5c961f9264820565
computeResources:
requests: {cpu: 50m, memory: 64Mi}
limits: {cpu: 500m, memory: 256Mi}
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- name: regctl-home
mountPath: /home/appuser
env:
- name: HOME
value: /home/appuser
- name: FINAL_IMAGE
value: $(params.image)
- name: AMD64_IMAGE
value: $(params.amd64-image)
- name: AMD64_DIGEST
value: $(params.amd64-digest)
- name: ARM64_IMAGE
value: $(params.arm64-image)
- name: ARM64_DIGEST
value: $(params.arm64-digest)
script: |
#!/bin/sh
set -eu
mkdir -p "$HOME/.docker"
cp "$(workspaces.dockerconfig.path)/config.json" "$HOME/.docker/config.json"
chmod 0600 "$HOME/.docker/config.json"
for DIGEST in "$AMD64_DIGEST" "$ARM64_DIGEST"; do
if ! printf '%s\n' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'; then
echo "Invalid image digest: $DIGEST" >&2
exit 1
fi
done
RESOLVED_AMD64="$(regctl image digest "$AMD64_IMAGE")"
RESOLVED_ARM64="$(regctl image digest "$ARM64_IMAGE")"
if [ "$RESOLVED_AMD64" != "$AMD64_DIGEST" ]; then
echo "amd64 tag resolved to $RESOLVED_AMD64, expected $AMD64_DIGEST" >&2
exit 1
fi
if [ "$RESOLVED_ARM64" != "$ARM64_DIGEST" ]; then
echo "arm64 tag resolved to $RESOLVED_ARM64, expected $ARM64_DIGEST" >&2
exit 1
fi
regctl index create "$FINAL_IMAGE" \
--ref "$AMD64_IMAGE@$AMD64_DIGEST" \
--desc-platform linux/amd64
regctl index add "$FINAL_IMAGE" \
--ref "$ARM64_IMAGE@$ARM64_DIGEST" \
--desc-platform linux/arm64
PLATFORMS="$(regctl manifest get "$FINAL_IMAGE" \
--format '{{range .Manifests}}{{printf "%s/%s\n" .Platform.OS .Platform.Architecture}}{{end}}' \
| sort)"
EXPECTED_PLATFORMS="$(printf 'linux/amd64\nlinux/arm64')"
if [ "$PLATFORMS" != "$EXPECTED_PLATFORMS" ]; then
echo "Unexpected image index platforms:" >&2
printf '%s\n' "$PLATFORMS" >&2
exit 1
fi
INDEX_DIGEST="$(regctl image digest "$FINAL_IMAGE")"
if ! printf '%s\n' "$INDEX_DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'; then
echo "Invalid image index digest: $INDEX_DIGEST" >&2
exit 1
fi
printf '%s' "$FINAL_IMAGE" >"$(results.image-url.path)"
printf '%s' "$INDEX_DIGEST" >"$(results.image-digest.path)"
---
apiVersion: tekton.dev/v1
kind: Task
metadata: metadata:
name: lolympus-assert-latest name: lolympus-assert-latest
spec: spec:
@@ -200,10 +394,10 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
AUTH_HOME="$$(mktemp -d)" AUTH_HOME="$(mktemp -d)"
trap 'rm -rf "$AUTH_HOME"' EXIT trap 'rm -rf "$AUTH_HOME"' EXIT
USERNAME="$$(cat "$(workspaces.credentials.path)/username")" USERNAME="$(cat "$(workspaces.credentials.path)/username")"
PASSWORD="$$(cat "$(workspaces.credentials.path)/password")" PASSWORD="$(cat "$(workspaces.credentials.path)/password")"
cat >"$AUTH_HOME/.netrc" <<EOF cat >"$AUTH_HOME/.netrc" <<EOF
machine git.dahyeon.us machine git.dahyeon.us
login $USERNAME login $USERNAME
@@ -211,7 +405,7 @@ spec:
EOF EOF
chmod 0600 "$AUTH_HOME/.netrc" chmod 0600 "$AUTH_HOME/.netrc"
export HOME="$AUTH_HOME" export HOME="$AUTH_HOME"
REMOTE_REVISION="$$(git ls-remote "$REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')" REMOTE_REVISION="$(git ls-remote "$REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$(params.revision)" ]; then if [ "$REMOTE_REVISION" != "$(params.revision)" ]; then
echo "Revision $(params.revision) was superseded by $REMOTE_REVISION" >&2 echo "Revision $(params.revision) was superseded by $REMOTE_REVISION" >&2
exit 1 exit 1
@@ -235,8 +429,10 @@ spec:
env: env:
- name: CI - name: CI
value: "true" value: "true"
- name: COREPACK_HOME - name: NPM_CONFIG_CACHE
value: $(workspaces.source.path)/.ci/corepack value: $(workspaces.source.path)/.ci/npm-cache
- name: PATH
value: $(workspaces.source.path)/.ci/pnpm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: CF_PAGES_PROJECT_NAME - name: CF_PAGES_PROJECT_NAME
value: lolympus value: lolympus
- name: CF_PAGES_STAGING_BRANCH - name: CF_PAGES_STAGING_BRANCH
@@ -247,18 +443,23 @@ spec:
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
corepack pnpm deploy:web:staging if ! command -v pnpm >/dev/null 2>&1; then
mkdir -p .ci/pnpm .ci/npm-cache
npm install --global \
--prefix "$(workspaces.source.path)/.ci/pnpm" pnpm@10.4.1
fi
pnpm deploy:web:staging
--- ---
apiVersion: tekton.dev/v1 apiVersion: tekton.dev/v1
kind: Task kind: Task
metadata: metadata:
name: lolympus-update-gitops name: lolympus-update-gitops
spec: spec:
description: Update the staging image tag in service-state. description: Update the staging image index digest in service-state.
params: params:
- name: revision - name: revision
type: string type: string
- name: image-tag - name: image-digest
type: string type: string
results: results:
- name: gitops-commit - name: gitops-commit
@@ -268,6 +469,14 @@ spec:
- name: credentials - name: credentials
readOnly: true readOnly: true
stepTemplate: stepTemplate:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
env: env:
- name: STATE_REPO_URL - name: STATE_REPO_URL
value: https://git.dahyeon.us/dahyeon/service-state.git value: https://git.dahyeon.us/dahyeon/service-state.git
@@ -284,10 +493,10 @@ spec:
set -eu set -eu
SOURCE_DIR="$(workspaces.source.path)" SOURCE_DIR="$(workspaces.source.path)"
STATE_DIR="$SOURCE_DIR/.gitops" STATE_DIR="$SOURCE_DIR/.gitops"
AUTH_HOME="$$(mktemp -d)" AUTH_HOME="$(mktemp -d)"
trap 'rm -rf "$AUTH_HOME"' EXIT trap 'rm -rf "$AUTH_HOME"' EXIT
USERNAME="$$(cat "$(workspaces.credentials.path)/username")" USERNAME="$(cat "$(workspaces.credentials.path)/username")"
PASSWORD="$$(cat "$(workspaces.credentials.path)/password")" PASSWORD="$(cat "$(workspaces.credentials.path)/password")"
cat >"$AUTH_HOME/.netrc" <<EOF cat >"$AUTH_HOME/.netrc" <<EOF
machine git.dahyeon.us machine git.dahyeon.us
login $USERNAME login $USERNAME
@@ -305,19 +514,23 @@ spec:
env: env:
- name: IMAGE_NAME - name: IMAGE_NAME
value: registry.dahyeon.us/lolympus/lolympus-tournament-support value: registry.dahyeon.us/lolympus/lolympus-tournament-support
- name: IMAGE_TAG - name: IMAGE_DIGEST
value: $(params.image-tag) value: $(params.image-digest)
script: | script: |
#!/bin/sh #!/bin/sh
set -eu set -eu
if ! printf '%s\n' "$IMAGE_DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'; then
echo "Invalid image index digest: $IMAGE_DIGEST" >&2
exit 1
fi
MANIFEST="$(workspaces.source.path)/.gitops/apps/lolympus-tournament-support/overlays/staging/kustomization.yaml" MANIFEST="$(workspaces.source.path)/.gitops/apps/lolympus-tournament-support/overlays/staging/kustomization.yaml"
MATCHES="$$(yq '[.images[] | select(.name == strenv(IMAGE_NAME))] | length' "$MANIFEST")" MATCHES="$(yq '[.images[] | select(.name == strenv(IMAGE_NAME))] | length' "$MANIFEST")"
if [ "$MATCHES" != "1" ]; then if [ "$MATCHES" != "1" ]; then
echo "Expected one image entry for $IMAGE_NAME, found $MATCHES" >&2 echo "Expected one image entry for $IMAGE_NAME, found $MATCHES" >&2
exit 1 exit 1
fi fi
yq -i \ yq -i \
'(.images[] | select(.name == strenv(IMAGE_NAME))).newTag = strenv(IMAGE_TAG)' \ '(.images[] | select(.name == strenv(IMAGE_NAME))) |= (del(.newTag) | .digest = strenv(IMAGE_DIGEST))' \
"$MANIFEST" "$MANIFEST"
- name: commit-and-push - name: commit-and-push
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26 image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
@@ -328,10 +541,10 @@ spec:
#!/bin/sh #!/bin/sh
set -eu set -eu
STATE_DIR="$(workspaces.source.path)/.gitops" STATE_DIR="$(workspaces.source.path)/.gitops"
AUTH_HOME="$$(mktemp -d)" AUTH_HOME="$(mktemp -d)"
trap 'rm -rf "$AUTH_HOME"' EXIT trap 'rm -rf "$AUTH_HOME"' EXIT
USERNAME="$$(cat "$(workspaces.credentials.path)/username")" USERNAME="$(cat "$(workspaces.credentials.path)/username")"
PASSWORD="$$(cat "$(workspaces.credentials.path)/password")" PASSWORD="$(cat "$(workspaces.credentials.path)/password")"
cat >"$AUTH_HOME/.netrc" <<EOF cat >"$AUTH_HOME/.netrc" <<EOF
machine git.dahyeon.us machine git.dahyeon.us
login $USERNAME login $USERNAME
@@ -345,14 +558,14 @@ spec:
git -C "$STATE_DIR" rev-parse HEAD >"$(results.gitops-commit.path)" git -C "$STATE_DIR" rev-parse HEAD >"$(results.gitops-commit.path)"
exit 0 exit 0
fi fi
REMOTE_REVISION="$$(git ls-remote "$SOURCE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')" REMOTE_REVISION="$(git ls-remote "$SOURCE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$(params.revision)" ]; then if [ "$REMOTE_REVISION" != "$(params.revision)" ]; then
echo "Revision $(params.revision) was superseded by $REMOTE_REVISION" >&2 echo "Revision $(params.revision) was superseded by $REMOTE_REVISION" >&2
exit 1 exit 1
fi fi
git -C "$STATE_DIR" add apps/lolympus-tournament-support/overlays/staging/kustomization.yaml git -C "$STATE_DIR" add apps/lolympus-tournament-support/overlays/staging/kustomization.yaml
git -C "$STATE_DIR" commit \ git -C "$STATE_DIR" commit \
-m "chore(lolympus): deploy staging $(params.image-tag)" -m "chore(lolympus): deploy staging $(params.image-digest)"
git -C "$STATE_DIR" pull --rebase origin main git -C "$STATE_DIR" pull --rebase origin main
git -C "$STATE_DIR" push origin HEAD:main git -C "$STATE_DIR" push origin HEAD:main
git -C "$STATE_DIR" rev-parse HEAD >"$(results.gitops-commit.path)" git -C "$STATE_DIR" rev-parse HEAD >"$(results.gitops-commit.path)"
@@ -36,6 +36,15 @@ spec:
securityContext: securityContext:
fsGroup: 1000 fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch fsGroupChangePolicy: OnRootMismatch
taskRunSpecs:
- pipelineTaskName: build-api-amd64
podTemplate:
nodeSelector:
kubernetes.io/arch: amd64
- pipelineTaskName: build-api-arm64
podTemplate:
nodeSelector:
kubernetes.io/arch: arm64
workspaces: workspaces:
- name: source - name: source
volumeClaimTemplate: volumeClaimTemplate:
+55
View File
@@ -0,0 +1,55 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: make-space-pipeline
automountServiceAccountToken: false
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: make-space-event-listener
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: make-space-event-listener
rules:
- apiGroups: [tekton.dev]
resources: [pipelineruns]
verbs: [create, get, list]
- apiGroups: [triggers.tekton.dev]
resources:
[
eventlisteners,
interceptors,
triggerbindings,
triggertemplates,
triggers,
]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [configmaps]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [serviceaccounts]
resourceNames: [make-space-pipeline]
verbs: [impersonate]
- apiGroups: [""]
resources: [events]
verbs: [create, patch]
- apiGroups: [""]
resources: [secrets]
resourceNames: [make-space-webhook]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: make-space-event-listener
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: make-space-event-listener
subjects:
- kind: ServiceAccount
name: make-space-event-listener
+45
View File
@@ -0,0 +1,45 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: make-space-ci-credentials
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: 8520b8c0-3796-4fd6-a03c-6f0508c8c42c
environmentSlug: prod
secretPath: /platform/tekton/make-space
recursive: false
targets:
- name: make-space-gitea
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: kubernetes.io/basic-auth
template:
engineVersion: v1
data:
username: "{{ .GITEA_USERNAME.Value }}"
password: "{{ .GITEA_TOKEN.Value }}"
- name: make-space-harbor
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: kubernetes.io/dockerconfigjson
template:
engineVersion: v1
data:
.dockerconfigjson: "{{ .HARBOR_DOCKER_CONFIG_JSON.Value }}"
- name: make-space-webhook
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
secretToken: "{{ .GITEA_WEBHOOK_SECRET.Value }}"
+21
View File
@@ -0,0 +1,21 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: make-space-main-webhook
spec:
ingressClassName: haproxy
tls:
- hosts: [tekton-hook.dahyeon.us]
# The existing lolympus Ingress owns issuance for this shared hostname.
secretName: lolympus-main-webhook-tls
rules:
- host: tekton-hook.dahyeon.us
http:
paths:
- path: /make-space
pathType: Prefix
backend:
service:
name: el-make-space-main
port:
number: 8080
+16
View File
@@ -0,0 +1,16 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: tekton-ci
resources:
- foundation.yaml
- infisical-secret.yaml
- tasks.yaml
- pipeline.yaml
- trigger.yaml
- ingress.yaml
labels:
- includeSelectors: false
pairs:
app.kubernetes.io/name: make-space
app.kubernetes.io/part-of: make-space-ci
app.kubernetes.io/managed-by: argocd
+145
View File
@@ -0,0 +1,145 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: make-space-staging
spec:
description: Validate an exact staging branch revision, publish an arm64 full-stack Leptos image, then update staging GitOps.
params:
- name: git-revision
type: string
results:
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
- name: gitops-commit
value: $(tasks.update-gitops.results.gitops-commit)
workspaces:
- name: source
- name: gitea-credentials
- name: harbor-dockerconfig
tasks:
- name: clone
taskRef:
name: make-space-clone
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: staging
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: quality
runAfter:
- clone
taskRef:
name: make-space-quality
workspaces:
- name: source
workspace: source
- name: build-arm64
runAfter:
- quality
taskRef:
name: make-space-build-arm64
params:
- name: revision
value: $(params.git-revision)
- name: image
value: registry.dahyeon.us/dahyeon/make-space:sha-$(params.git-revision)-$(context.pipelineRun.uid)
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: update-gitops
runAfter:
- build-arm64
taskRef:
name: make-space-update-gitops
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: staging
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: make-space-prod
spec:
description: Validate an exact prod branch revision, publish an arm64 full-stack Leptos image, then update production GitOps.
params:
- name: git-revision
type: string
results:
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
- name: gitops-commit
value: $(tasks.update-gitops.results.gitops-commit)
workspaces:
- name: source
- name: gitea-credentials
- name: harbor-dockerconfig
tasks:
- name: clone
taskRef:
name: make-space-clone
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: prod
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: quality
runAfter:
- clone
taskRef:
name: make-space-quality
workspaces:
- name: source
workspace: source
- name: build-arm64
runAfter:
- quality
taskRef:
name: make-space-build-arm64
params:
- name: revision
value: $(params.git-revision)
- name: image
value: registry.dahyeon.us/dahyeon/make-space:sha-$(params.git-revision)-$(context.pipelineRun.uid)
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: update-gitops
runAfter:
- build-arm64
taskRef:
name: make-space-update-gitops
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: prod
- name: image-digest
value: $(tasks.build-arm64.results.image-digest)
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
+422
View File
@@ -0,0 +1,422 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: make-space-clone
spec:
description: Clone the pushed source revision and verify the selected deployment branch.
params:
- name: revision
type: string
- name: environment
type: string
default: staging
workspaces:
- name: source
- name: credentials
readOnly: true
steps:
- name: clone
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: "1"
memory: 1Gi
env:
- name: REPO_URL
value: https://git.dahyeon.us/dahyeon/make-space.git
- name: REVISION
value: $(params.revision)
- name: DEPLOY_ENV
value: $(params.environment)
- name: SOURCE_DIR
value: $(workspaces.source.path)
- name: GITEA_CREDENTIALS_DIR
value: $(workspaces.credentials.path)
script: |
#!/bin/sh
set -eu
umask 0002
case "$DEPLOY_ENV" in staging|prod) ;; *) echo 'Invalid deployment environment' >&2; exit 1;; esac
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
test "$REVISION" != '0000000000000000000000000000000000000000'
case "$SOURCE_DIR" in /workspace/*) ;; *) echo 'Unexpected workspace path' >&2; exit 1;; esac
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
REMOTE_REVISION="$(git ls-remote "$REPO_URL" "refs/heads/$DEPLOY_ENV" | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
echo 'Source revision was superseded before checkout.' >&2
exit 1
fi
find "$SOURCE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
git clone --quiet --no-tags "$REPO_URL" "$SOURCE_DIR"
git -C "$SOURCE_DIR" checkout --quiet --detach "$REVISION"
test "$(git -C "$SOURCE_DIR" rev-parse HEAD)" = "$REVISION"
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: make-space-quality
spec:
description: Run JS scene/UI tests and Rust workspace unit tests before building the container image.
workspaces:
- name: source
stepTemplate:
workingDir: $(workspaces.source.path)
env:
- name: CI
value: "true"
steps:
- name: verify-js
image: docker.io/library/node:26.13.0-bookworm@sha256:fa52d1669505e29b58c042875b1d65c229e0787a3610fd52869b22b68e480853
computeResources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: "1"
memory: 1Gi
script: |
#!/bin/sh
set -eu
node --test app/js/scene.test.mjs app/js/ui.test.mjs
- name: verify-rust
image: docker.io/library/rust:1.99.1-trixie
computeResources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: "4"
memory: 6Gi
env:
- name: PATH
value: /usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: CARGO_HOME
value: /usr/local/cargo
script: |
#!/bin/sh
set -eu
cargo test --workspace --locked
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: make-space-build-arm64
spec:
description: Build and push the linux/arm64 full-stack Leptos image natively using rootless BuildKit.
params:
- name: revision
type: string
- name: image
type: string
results:
- name: image-url
description: Published repository and unique tag.
- name: image-digest
description: Immutable linux/arm64 image digest.
workspaces:
- name: credentials
readOnly: true
- name: dockerconfig
readOnly: true
volumes:
- name: build-source
emptyDir: {}
- name: buildkit-state
emptyDir: {}
steps:
- name: clone-source
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: "1"
memory: 1Gi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
workspaces:
- name: credentials
volumeMounts:
- name: build-source
mountPath: /workspace/build
env:
- name: REPO_URL
value: https://git.dahyeon.us/dahyeon/make-space.git
- name: REVISION
value: $(params.revision)
- name: GITEA_CREDENTIALS_DIR
value: $(workspaces.credentials.path)
script: |
#!/bin/sh
set -eu
umask 0002
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
test "$REVISION" != '0000000000000000000000000000000000000000'
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
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: build-and-push
image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c
computeResources:
requests:
cpu: "1"
memory: 2Gi
limits:
cpu: "4"
memory: 8Gi
securityContext:
privileged: false
allowPrivilegeEscalation: true
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: Unconfined
appArmorProfile:
type: Unconfined
workspaces:
- name: dockerconfig
volumeMounts:
- name: build-source
mountPath: /workspace/build
- name: buildkit-state
mountPath: /home/user/.local/share/buildkit
env:
- name: BUILDKITD_FLAGS
value: --oci-worker-no-process-sandbox
- name: DOCKER_CONFIG
value: $(workspaces.dockerconfig.path)
- name: IMAGE
value: $(params.image)
- name: METADATA_FILE
value: /workspace/build/build-metadata.json
script: |
#!/bin/sh
set -eu
printf '%s\n' "$IMAGE" | grep -Eq '^registry\.dahyeon\.us/dahyeon/make-space:sha-[0-9a-f]{40}-[a-zA-Z0-9-]+$'
buildctl-daemonless.sh build \
--frontend dockerfile.v0 \
--local context=/workspace/build/source \
--local dockerfile=/workspace/build/source \
--opt filename=Dockerfile \
--opt platform=linux/arm64 \
--output "type=image,name=$IMAGE,push=true" \
--metadata-file "$METADATA_FILE"
- name: record-digest
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 250m
memory: 256Mi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- name: build-source
mountPath: /workspace/build
readOnly: true
env:
- name: IMAGE
value: $(params.image)
- name: METADATA_FILE
value: /workspace/build/build-metadata.json
- name: DIGEST_RESULT_PATH
value: $(results.image-digest.path)
- name: IMAGE_RESULT_PATH
value: $(results.image-url.path)
script: |
#!/bin/sh
set -eu
DIGEST="$(yq -r '."containerimage.digest"' "$METADATA_FILE")"
printf '%s\n' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'
printf '%s' "$IMAGE" >"$IMAGE_RESULT_PATH"
printf '%s' "$DIGEST" >"$DIGEST_RESULT_PATH"
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: make-space-update-gitops
spec:
description: Publish the selected environment's app digest to service-state keeping replicas at 1.
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.
workspaces:
- name: source
- name: credentials
readOnly: true
stepTemplate:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
env:
- name: STATE_REPO_URL
value: https://git.dahyeon.us/dahyeon/service-state.git
- name: SOURCE_REPO_URL
value: https://git.dahyeon.us/dahyeon/make-space.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
value: $(workspaces.credentials.path)
steps:
- name: clone-state
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 512Mi
script: |
#!/bin/sh
set -eu
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
case "$STATE_DIR" in /workspace/*/.cache/gitops-state) ;; *) echo 'Unexpected GitOps path' >&2; exit 1;; esac
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
rm -rf "$STATE_DIR"
git clone --quiet --depth=1 --branch main "$STATE_REPO_URL" "$STATE_DIR"
- name: update-manifest
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 250m
memory: 256Mi
env:
- name: APP_IMAGE
value: registry.dahyeon.us/dahyeon/make-space
- name: IMAGE_DIGEST
value: $(params.image-digest)
- name: DEPLOYMENT_NAME
value: make-space
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}$'
MANIFEST="$STATE_DIR/apps/make-space/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."make-space.dahyeon.us/source-revision" = strenv(REVISION)' "$MANIFEST"
- name: commit-and-push
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 512Mi
env:
- name: GITOPS_RESULT_PATH
value: $(results.gitops-commit.path)
script: |
#!/bin/sh
set -eu
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
BASE_COMMIT="$(git -C "$STATE_DIR" rev-parse HEAD)"
REMOTE_STATE="$(git ls-remote "$STATE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_STATE" != "$BASE_COMMIT" ]; then
echo 'service-state advanced; rerun from the latest source. No automatic rebase or force push.' >&2
exit 1
fi
git -C "$STATE_DIR" config user.name make-space-tekton
git -C "$STATE_DIR" config user.email tekton@dahyeon.us
if git -C "$STATE_DIR" diff --quiet; then
git -C "$STATE_DIR" rev-parse HEAD >"$GITOPS_RESULT_PATH"
exit 0
fi
git -C "$STATE_DIR" add "apps/make-space/overlays/$DEPLOY_ENV/kustomization.yaml"
git -C "$STATE_DIR" commit -m "chore(make-space): deploy $DEPLOY_ENV $REVISION"
REMOTE_REVISION="$(git ls-remote "$SOURCE_REPO_URL" "refs/heads/$DEPLOY_ENV" | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
echo 'Source revision was superseded before GitOps push.' >&2
exit 1
fi
git -C "$STATE_DIR" push origin HEAD:main
git -C "$STATE_DIR" rev-parse HEAD >"$GITOPS_RESULT_PATH"
+101
View File
@@ -0,0 +1,101 @@
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
name: make-space-main
spec:
params:
- name: git-revision
value: $(body.after)
- name: environment
value: $(extensions.environment)
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: make-space-main
spec:
params:
- name: git-revision
- name: environment
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: make-space-$(tt.params.environment)-
labels:
app.kubernetes.io/name: make-space
app.kubernetes.io/part-of: make-space-ci
spec:
pipelineRef:
name: make-space-$(tt.params.environment)
params:
- name: git-revision
value: $(tt.params.git-revision)
taskRunTemplate:
serviceAccountName: make-space-pipeline
podTemplate:
nodeSelector:
kubernetes.io/arch: arm64
securityContext:
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
workspaces:
- name: source
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 10Gi
- name: gitea-credentials
secret:
secretName: make-space-gitea
items:
- key: username
path: username
- key: password
path: password
- name: harbor-dockerconfig
secret:
secretName: make-space-harbor
items:
- key: .dockerconfigjson
path: config.json
timeouts:
pipeline: 60m
tasks: 55m
---
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: make-space-main
spec:
serviceAccountName: make-space-event-listener
triggers:
- name: branch-push
interceptors:
- ref:
name: github
params:
- name: secretRef
value:
secretName: make-space-webhook
secretKey: secretToken
- name: eventTypes
value:
- push
- ref:
name: cel
params:
- name: filter
value: body.repository.full_name == 'dahyeon/make-space' && body.ref in ['refs/heads/staging', 'refs/heads/prod'] && body.after.matches('^[0-9a-f]{40}$') && body.after != '0000000000000000000000000000000000000000'
- name: overlays
value:
- key: environment
expression: "body.ref.split('/')[2]"
bindings:
- ref: make-space-main
template:
ref: make-space-main
+55
View File
@@ -0,0 +1,55 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: url-shortener-pipeline
automountServiceAccountToken: false
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: url-shortener-event-listener
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: url-shortener-event-listener
rules:
- apiGroups: [tekton.dev]
resources: [pipelineruns]
verbs: [create, get, list]
- apiGroups: [triggers.tekton.dev]
resources:
[
eventlisteners,
interceptors,
triggerbindings,
triggertemplates,
triggers,
]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [configmaps]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [serviceaccounts]
resourceNames: [url-shortener-pipeline]
verbs: [impersonate]
- apiGroups: [""]
resources: [events]
verbs: [create, patch]
- apiGroups: [""]
resources: [secrets]
resourceNames: [url-shortener-webhook]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: url-shortener-event-listener
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: url-shortener-event-listener
subjects:
- kind: ServiceAccount
name: url-shortener-event-listener
+109
View File
@@ -0,0 +1,109 @@
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: url-shortener-ci-credentials
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: 8520b8c0-3796-4fd6-a03c-6f0508c8c42c
environmentSlug: prod
secretPath: /platform/tekton/url-shortener
recursive: false
targets:
- name: url-shortener-gitea
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: kubernetes.io/basic-auth
template:
engineVersion: v1
data:
username: "{{ .GITEA_USERNAME.Value }}"
password: "{{ .GITEA_TOKEN.Value }}"
- name: url-shortener-harbor
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: kubernetes.io/dockerconfigjson
template:
engineVersion: v1
data:
.dockerconfigjson: "{{ .HARBOR_DOCKER_CONFIG_JSON.Value }}"
- name: url-shortener-cloudflare
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
CLOUDFLARE_API_TOKEN: "{{ .CLOUDFLARE_API_TOKEN.Value }}"
CLOUDFLARE_ACCOUNT_ID: "{{ .CLOUDFLARE_ACCOUNT_ID.Value }}"
- name: url-shortener-webhook
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
secretToken: "{{ .GITEA_WEBHOOK_SECRET.Value }}"
---
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: url-shortener-ci-edge-staging
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: 01c4ebe5-8c73-475c-ba29-56709483b0f1
environmentSlug: staging
secretPath: /
recursive: false
targets:
- name: url-shortener-edge-staging
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
INGEST_HMAC_SECRET: "{{ .INGEST_HMAC_SECRET.Value }}"
---
apiVersion: secrets.infisical.com/v1beta1
kind: InfisicalStaticSecret
metadata:
name: url-shortener-ci-edge-prod
spec:
infisicalAuthRef:
name: infisical-auth
namespace: infisical
syncOptions:
refreshInterval: 60s
instantUpdates: false
sources:
- projectId: 01c4ebe5-8c73-475c-ba29-56709483b0f1
environmentSlug: prod
secretPath: /
recursive: false
targets:
- name: url-shortener-edge-prod
namespace: tekton-ci
kind: Secret
creationPolicy: Owner
secretType: Opaque
template:
engineVersion: v1
data:
INGEST_HMAC_SECRET: "{{ .INGEST_HMAC_SECRET.Value }}"
+21
View File
@@ -0,0 +1,21 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: url-shortener-main-webhook
spec:
ingressClassName: haproxy
tls:
- hosts: [tekton-hook.dahyeon.us]
# The existing lolympus Ingress owns issuance for this shared hostname.
secretName: lolympus-main-webhook-tls
rules:
- host: tekton-hook.dahyeon.us
http:
paths:
- path: /url-shortener
pathType: Prefix
backend:
service:
name: el-url-shortener-main
port:
number: 8080
+16
View File
@@ -0,0 +1,16 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: tekton-ci
resources:
- foundation.yaml
- infisical-secret.yaml
- tasks.yaml
- pipeline.yaml
- trigger.yaml
- ingress.yaml
labels:
- includeSelectors: false
pairs:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/part-of: url-shortener-ci
app.kubernetes.io/managed-by: argocd
+253
View File
@@ -0,0 +1,253 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: url-shortener-staging
spec:
description: Validate an exact staging branch revision, publish a multiarch Rust API image, deploy staging Cloudflare resources, then update staging GitOps.
params:
- name: git-revision
type: string
results:
- name: image-digest
value: $(tasks.create-image-index.results.image-digest)
- name: gitops-commit
value: $(tasks.update-gitops.results.gitops-commit)
workspaces:
- name: source
- name: gitea-credentials
- name: harbor-dockerconfig
tasks:
- name: clone
taskRef:
name: url-shortener-clone
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: staging
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: quality
runAfter:
- clone
taskRef:
name: url-shortener-quality
workspaces:
- name: source
workspace: source
- name: build-amd64
runAfter:
- quality
taskRef:
name: url-shortener-build-platform
params:
- name: revision
value: $(params.git-revision)
- name: platform
value: linux/amd64
- name: image
value: registry.dahyeon.us/dahyeon/url-shortener:sha-$(params.git-revision)-$(context.pipelineRun.uid)-amd64
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: build-arm64
runAfter:
- quality
taskRef:
name: url-shortener-build-platform
params:
- name: revision
value: $(params.git-revision)
- name: platform
value: linux/arm64
- name: image
value: registry.dahyeon.us/dahyeon/url-shortener:sha-$(params.git-revision)-$(context.pipelineRun.uid)-arm64
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: create-image-index
runAfter:
- build-amd64
- build-arm64
taskRef:
name: url-shortener-create-image-index
params:
- name: image
value: registry.dahyeon.us/dahyeon/url-shortener:sha-$(params.git-revision)-$(context.pipelineRun.uid)
- name: amd64-image
value: $(tasks.build-amd64.results.image-url)
- name: amd64-digest
value: $(tasks.build-amd64.results.image-digest)
- name: arm64-image
value: $(tasks.build-arm64.results.image-url)
- name: arm64-digest
value: $(tasks.build-arm64.results.image-digest)
workspaces:
- name: dockerconfig
workspace: harbor-dockerconfig
- name: deploy-cloudflare
runAfter:
- create-image-index
taskRef:
name: url-shortener-deploy-cloudflare
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: staging
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: update-gitops
runAfter:
- deploy-cloudflare
taskRef:
name: url-shortener-update-gitops
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: staging
- name: image-digest
value: $(tasks.create-image-index.results.image-digest)
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: url-shortener-prod
spec:
description: Validate an exact prod branch revision, publish a multiarch Rust API image, deploy production Cloudflare resources, then update production GitOps.
params:
- name: git-revision
type: string
results:
- name: image-digest
value: $(tasks.create-image-index.results.image-digest)
- name: gitops-commit
value: $(tasks.update-gitops.results.gitops-commit)
workspaces:
- name: source
- name: gitea-credentials
- name: harbor-dockerconfig
tasks:
- name: clone
taskRef:
name: url-shortener-clone
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: prod
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: quality
runAfter:
- clone
taskRef:
name: url-shortener-quality
workspaces:
- name: source
workspace: source
- name: build-amd64
runAfter:
- quality
taskRef:
name: url-shortener-build-platform
params:
- name: revision
value: $(params.git-revision)
- name: platform
value: linux/amd64
- name: image
value: registry.dahyeon.us/dahyeon/url-shortener:sha-$(params.git-revision)-$(context.pipelineRun.uid)-amd64
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: build-arm64
runAfter:
- quality
taskRef:
name: url-shortener-build-platform
params:
- name: revision
value: $(params.git-revision)
- name: platform
value: linux/arm64
- name: image
value: registry.dahyeon.us/dahyeon/url-shortener:sha-$(params.git-revision)-$(context.pipelineRun.uid)-arm64
workspaces:
- name: credentials
workspace: gitea-credentials
- name: dockerconfig
workspace: harbor-dockerconfig
- name: create-image-index
runAfter:
- build-amd64
- build-arm64
taskRef:
name: url-shortener-create-image-index
params:
- name: image
value: registry.dahyeon.us/dahyeon/url-shortener:sha-$(params.git-revision)-$(context.pipelineRun.uid)
- name: amd64-image
value: $(tasks.build-amd64.results.image-url)
- name: amd64-digest
value: $(tasks.build-amd64.results.image-digest)
- name: arm64-image
value: $(tasks.build-arm64.results.image-url)
- name: arm64-digest
value: $(tasks.build-arm64.results.image-digest)
workspaces:
- name: dockerconfig
workspace: harbor-dockerconfig
- name: deploy-cloudflare
runAfter:
- create-image-index
taskRef:
name: url-shortener-deploy-cloudflare
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: prod
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
- name: update-gitops
runAfter:
- deploy-cloudflare
taskRef:
name: url-shortener-update-gitops
params:
- name: revision
value: $(params.git-revision)
- name: environment
value: prod
- name: image-digest
value: $(tasks.create-image-index.results.image-digest)
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
+649
View File
@@ -0,0 +1,649 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: url-shortener-clone
spec:
description: Clone the pushed source revision and verify the selected deployment branch.
params:
- name: revision
type: string
- name: environment
type: string
default: staging
workspaces:
- name: source
- name: credentials
readOnly: true
steps:
- name: clone
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: "1"
memory: 1Gi
env:
- name: REPO_URL
value: https://git.dahyeon.us/dahyeon/url-shortener.git
- name: REVISION
value: $(params.revision)
- name: DEPLOY_ENV
value: $(params.environment)
- name: SOURCE_DIR
value: $(workspaces.source.path)
- name: GITEA_CREDENTIALS_DIR
value: $(workspaces.credentials.path)
script: |
#!/bin/sh
set -eu
umask 0002
case "$DEPLOY_ENV" in staging|prod) ;; *) echo 'Invalid deployment environment' >&2; exit 1;; esac
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
test "$REVISION" != '0000000000000000000000000000000000000000'
case "$SOURCE_DIR" in /workspace/*) ;; *) echo 'Unexpected workspace path' >&2; exit 1;; esac
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
REMOTE_REVISION="$(git ls-remote "$REPO_URL" "refs/heads/$DEPLOY_ENV" | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
echo 'Source revision was superseded before checkout.' >&2
exit 1
fi
find "$SOURCE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
git clone --quiet --no-tags "$REPO_URL" "$SOURCE_DIR"
git -C "$SOURCE_DIR" checkout --quiet --detach "$REVISION"
test "$(git -C "$SOURCE_DIR" rev-parse HEAD)" = "$REVISION"
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: url-shortener-quality
spec:
description: Check the Rust API, React admin and Workers before credentials or publication are available.
workspaces:
- name: source
stepTemplate:
image: docker.io/library/node:26.13.0-bookworm@sha256:fa52d1669505e29b58c042875b1d65c229e0787a3610fd52869b22b68e480853
workingDir: $(workspaces.source.path)
env:
- name: CI
value: "true"
- name: NEW_RELIC_ENABLED
value: "false"
- name: NPM_CONFIG_CACHE
value: $(workspaces.source.path)/.cache/ci/npm
- name: PATH
value: $(workspaces.source.path)/.cache/ci/pnpm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: WRANGLER_SEND_METRICS
value: "false"
- name: WRANGLER_LOG_PATH
value: $(workspaces.source.path)/.cache/wrangler/logs
- name: XDG_CONFIG_HOME
value: $(workspaces.source.path)/.cache/wrangler/config
- name: MONGOMS_DOWNLOAD_DIR
value: $(workspaces.source.path)/.cache/mongodb
steps:
- name: install
computeResources:
requests:
cpu: 200m
memory: 512Mi
limits:
cpu: "2"
memory: 4Gi
script: |
#!/bin/sh
set -eu
umask 0002
mkdir -p .cache/ci/pnpm .cache/ci/npm
npm install --global --prefix "$(workspaces.source.path)/.cache/ci/pnpm" pnpm@12.16.1
pnpm install --frozen-lockfile
- name: verify
computeResources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: "3"
memory: 6Gi
script: |
#!/bin/sh
set -eu
pnpm check:js
pnpm test:deployment
pnpm format:check:js
- name: verify-rust
image: docker.io/library/rust:1.99.1-trixie
computeResources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: "3"
memory: 6Gi
env:
- name: PATH
value: /usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: CARGO_HOME
value: /usr/local/cargo
script: |
#!/bin/sh
set -eu
cargo fmt --all -- --check
cargo test --workspace --locked
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: url-shortener-build-platform
spec:
description: Build one app architecture natively using rootless BuildKit and a fresh clone.
params:
- name: revision
type: string
- name: platform
type: string
- name: image
type: string
results:
- name: image-url
description: Published repository and unique tag.
- name: image-digest
description: Immutable platform image digest.
workspaces:
- name: credentials
readOnly: true
- name: dockerconfig
readOnly: true
volumes:
- name: build-source
emptyDir: {}
- name: buildkit-state
emptyDir: {}
steps:
- name: clone-source
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: "1"
memory: 1Gi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
workspaces:
- name: credentials
volumeMounts:
- name: build-source
mountPath: /workspace/build
env:
- name: REPO_URL
value: https://git.dahyeon.us/dahyeon/url-shortener.git
- name: REVISION
value: $(params.revision)
- name: GITEA_CREDENTIALS_DIR
value: $(workspaces.credentials.path)
script: |
#!/bin/sh
set -eu
umask 0002
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
test "$REVISION" != '0000000000000000000000000000000000000000'
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
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: build-and-push
image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c
computeResources:
requests:
cpu: "1"
memory: 2Gi
limits:
cpu: "4"
memory: 8Gi
securityContext:
privileged: false
allowPrivilegeEscalation: true
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: Unconfined
appArmorProfile:
type: Unconfined
workspaces:
- name: dockerconfig
volumeMounts:
- name: build-source
mountPath: /workspace/build
- name: buildkit-state
mountPath: /home/user/.local/share/buildkit
env:
- name: BUILDKITD_FLAGS
value: --oci-worker-no-process-sandbox
- name: DOCKER_CONFIG
value: $(workspaces.dockerconfig.path)
- name: PLATFORM
value: $(params.platform)
- name: IMAGE
value: $(params.image)
- name: METADATA_FILE
value: /workspace/build/build-metadata.json
script: |
#!/bin/sh
set -eu
case "$PLATFORM" in linux/amd64|linux/arm64) ;; *) echo 'Unsupported platform' >&2; exit 1;; esac
printf '%s\n' "$IMAGE" | grep -Eq '^registry\.dahyeon\.us/dahyeon/url-shortener:sha-[0-9a-f]{40}-[a-zA-Z0-9-]+-(amd64|arm64)$'
case "$PLATFORM:$IMAGE" in
linux/amd64:*-amd64|linux/arm64:*-arm64) ;;
*) echo 'Platform tag mismatch' >&2; exit 1;;
esac
buildctl-daemonless.sh build \
--frontend dockerfile.v0 \
--local context=/workspace/build/source \
--local dockerfile=/workspace/build/source \
--opt filename=Dockerfile \
--opt "platform=$PLATFORM" \
--output "type=image,name=$IMAGE,push=true" \
--metadata-file "$METADATA_FILE"
- name: record-digest
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 250m
memory: 256Mi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- name: build-source
mountPath: /workspace/build
readOnly: true
env:
- name: IMAGE
value: $(params.image)
- name: METADATA_FILE
value: /workspace/build/build-metadata.json
- name: DIGEST_RESULT_PATH
value: $(results.image-digest.path)
- name: IMAGE_RESULT_PATH
value: $(results.image-url.path)
script: |
#!/bin/sh
set -eu
DIGEST="$(yq -r '."containerimage.digest"' "$METADATA_FILE")"
printf '%s\n' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'
printf '%s' "$IMAGE" >"$IMAGE_RESULT_PATH"
printf '%s' "$DIGEST" >"$DIGEST_RESULT_PATH"
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: url-shortener-create-image-index
spec:
description: Verify native digests and publish an immutable amd64 plus arm64 OCI image index.
params:
- name: image
type: string
- name: amd64-image
type: string
- name: amd64-digest
type: string
- name: arm64-image
type: string
- name: arm64-digest
type: string
results:
- name: image-url
description: Published multi-platform image tag.
- name: image-digest
description: Immutable multi-platform index digest.
workspaces:
- name: dockerconfig
readOnly: true
volumes:
- name: registry-config
emptyDir: {}
steps:
- name: create-index
image: ghcr.io/regclient/regctl:v0.11.5-alpine@sha256:795e27a968ec0681cf1f4fd4bb83a880a1bc4698afb38efd5c961f9264820565
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 256Mi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- name: registry-config
mountPath: /workspace/registry-config
env:
- name: DOCKER_CONFIG
value: $(workspaces.dockerconfig.path)
- name: REGCTL_CONFIG
value: /workspace/registry-config/config.json
- name: FINAL_IMAGE
value: $(params.image)
- name: AMD64_IMAGE
value: $(params.amd64-image)
- name: AMD64_DIGEST
value: $(params.amd64-digest)
- name: ARM64_IMAGE
value: $(params.arm64-image)
- name: ARM64_DIGEST
value: $(params.arm64-digest)
- name: IMAGE_RESULT_PATH
value: $(results.image-url.path)
- name: DIGEST_RESULT_PATH
value: $(results.image-digest.path)
script: |
#!/bin/sh
set -eu
printf '%s\n' "$FINAL_IMAGE" | grep -Eq '^registry\.dahyeon\.us/dahyeon/url-shortener:sha-[0-9a-f]{40}-[a-zA-Z0-9-]+$'
test "$AMD64_IMAGE" = "$FINAL_IMAGE-amd64"
test "$ARM64_IMAGE" = "$FINAL_IMAGE-arm64"
for DIGEST in "$AMD64_DIGEST" "$ARM64_DIGEST"; do
printf '%s\n' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'
done
test "$(regctl image digest "$AMD64_IMAGE")" = "$AMD64_DIGEST"
test "$(regctl image digest "$ARM64_IMAGE")" = "$ARM64_DIGEST"
regctl index create "$FINAL_IMAGE" --ref "$AMD64_IMAGE@$AMD64_DIGEST" --desc-platform linux/amd64
regctl index add "$FINAL_IMAGE" --ref "$ARM64_IMAGE@$ARM64_DIGEST" --desc-platform linux/arm64
PLATFORMS="$(regctl manifest get "$FINAL_IMAGE" --format '{{range .Manifests}}{{printf "%s/%s\n" .Platform.OS .Platform.Architecture}}{{end}}' | sort)"
test "$PLATFORMS" = "$(printf 'linux/amd64\nlinux/arm64')"
INDEX_DIGEST="$(regctl image digest "$FINAL_IMAGE")"
printf '%s\n' "$INDEX_DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'
printf '%s' "$FINAL_IMAGE" >"$IMAGE_RESULT_PATH"
printf '%s' "$INDEX_DIGEST" >"$DIGEST_RESULT_PATH"
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: url-shortener-deploy-cloudflare
spec:
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: deploy
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: REPO_URL
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
value: $(workspaces.source.path)/.cache/ci/pnpm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: WRANGLER_SEND_METRICS
value: "false"
- name: WRANGLER_LOG_PATH
value: $(workspaces.source.path)/.cache/wrangler/logs
- name: XDG_CONFIG_HOME
value: $(workspaces.source.path)/.cache/wrangler/config
envFrom:
- secretRef:
name: url-shortener-cloudflare
- secretRef:
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
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
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/$DEPLOY_ENV" | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
echo 'Source revision was superseded before Cloudflare deployment.' >&2
exit 1
fi
command -v pnpm >/dev/null
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 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.
workspaces:
- name: source
- name: credentials
readOnly: true
stepTemplate:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
env:
- name: STATE_REPO_URL
value: https://git.dahyeon.us/dahyeon/service-state.git
- name: SOURCE_REPO_URL
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
value: $(workspaces.credentials.path)
steps:
- name: clone-state
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 512Mi
script: |
#!/bin/sh
set -eu
printf '%s\n' "$REVISION" | grep -Eq '^[0-9a-f]{40}$'
case "$STATE_DIR" in /workspace/*/.cache/gitops-state) ;; *) echo 'Unexpected GitOps path' >&2; exit 1;; esac
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
rm -rf "$STATE_DIR"
git clone --quiet --depth=1 --branch main "$STATE_REPO_URL" "$STATE_DIR"
- name: update-manifest
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 250m
memory: 256Mi
env:
- name: APP_IMAGE
value: registry.dahyeon.us/dahyeon/url-shortener
- name: IMAGE_DIGEST
value: $(params.image-digest)
- name: DEPLOYMENT_NAME
value: url-shortener
- name: CLOUDFLARE_PROFILE
value: $(workspaces.source.path)/deploy/cloudflare/$(params.environment).json
- name: CLOUDFLARE_ACCOUNT_ID
valueFrom:
secretKeyRef:
name: url-shortener-cloudflare
key: CLOUDFLARE_ACCOUNT_ID
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")" = "$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/$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")"
case "$REPLICAS" in ''|*[!0-9]*) echo 'Invalid replica count' >&2; exit 1;; esac
yq -i '(.images[] | select(.name == strenv(APP_IMAGE))) |= (del(.newTag) | .digest = strenv(IMAGE_DIGEST))' "$MANIFEST"
if [ "$REPLICAS" -lt 2 ]; then
yq -i '(.replicas[] | select(.name == strenv(DEPLOYMENT_NAME))).count = 2' "$MANIFEST"
fi
yq -i '.commonAnnotations."url-shortener.dahyeon.us/source-revision" = strenv(REVISION)' "$MANIFEST"
yq -i '.data.CLOUDFLARE_ACCOUNT_ID = strenv(CLOUDFLARE_ACCOUNT_ID) | .data.CLOUDFLARE_D1_DATABASE_ID = strenv(CLOUDFLARE_D1_DATABASE_ID)' "$CONFIGMAP"
- name: commit-and-push
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
computeResources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 512Mi
env:
- name: GITOPS_RESULT_PATH
value: $(results.gitops-commit.path)
script: |
#!/bin/sh
set -eu
AUTH_DIR="$(mktemp -d)"
trap 'rm -rf "$AUTH_DIR"' EXIT
cat >"$AUTH_DIR/askpass" <<'EOF'
#!/bin/sh
case "$1" in
*Username*) cat "$GITEA_CREDENTIALS_DIR/username" ;;
*Password*) cat "$GITEA_CREDENTIALS_DIR/password" ;;
*) exit 1 ;;
esac
EOF
chmod 0700 "$AUTH_DIR/askpass"
export GIT_ASKPASS="$AUTH_DIR/askpass" GIT_TERMINAL_PROMPT=0
BASE_COMMIT="$(git -C "$STATE_DIR" rev-parse HEAD)"
REMOTE_STATE="$(git ls-remote "$STATE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_STATE" != "$BASE_COMMIT" ]; then
echo 'service-state advanced; rerun from the latest source. No automatic rebase or force push.' >&2
exit 1
fi
git -C "$STATE_DIR" config user.name url-shortener-tekton
git -C "$STATE_DIR" config user.email tekton@dahyeon.us
if git -C "$STATE_DIR" diff --quiet; then
git -C "$STATE_DIR" rev-parse HEAD >"$GITOPS_RESULT_PATH"
exit 0
fi
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"
REMOTE_REVISION="$(git ls-remote "$SOURCE_REPO_URL" "refs/heads/$DEPLOY_ENV" | awk 'NR == 1 {print $1}')"
if [ "$REMOTE_REVISION" != "$REVISION" ]; then
echo 'Source revision was superseded before GitOps push.' >&2
exit 1
fi
# A concurrent state update causes a non-fast-forward failure, never an overwrite.
git -C "$STATE_DIR" push origin HEAD:main
git -C "$STATE_DIR" rev-parse HEAD >"$GITOPS_RESULT_PATH"
+109
View File
@@ -0,0 +1,109 @@
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
name: url-shortener-main
spec:
params:
- name: git-revision
value: $(body.after)
- name: environment
value: $(extensions.environment)
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: url-shortener-main
spec:
params:
- name: git-revision
- name: environment
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: url-shortener-$(tt.params.environment)-
labels:
app.kubernetes.io/name: url-shortener
app.kubernetes.io/part-of: url-shortener-ci
spec:
pipelineRef:
name: url-shortener-$(tt.params.environment)
params:
- name: git-revision
value: $(tt.params.git-revision)
taskRunTemplate:
serviceAccountName: url-shortener-pipeline
podTemplate:
nodeSelector:
kubernetes.io/arch: amd64
securityContext:
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
taskRunSpecs:
- pipelineTaskName: build-arm64
podTemplate:
nodeSelector:
kubernetes.io/arch: arm64
securityContext:
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
workspaces:
- name: source
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 10Gi
- name: gitea-credentials
secret:
secretName: url-shortener-gitea
items:
- key: username
path: username
- key: password
path: password
- name: harbor-dockerconfig
secret:
secretName: url-shortener-harbor
items:
- key: .dockerconfigjson
path: config.json
timeouts:
pipeline: 60m
tasks: 55m
---
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: url-shortener-main
spec:
serviceAccountName: url-shortener-event-listener
triggers:
- name: branch-push
interceptors:
- ref:
name: github
params:
- name: secretRef
value:
secretName: url-shortener-webhook
secretKey: secretToken
- name: eventTypes
value:
- push
- ref:
name: cel
params:
- name: filter
value: body.repository.full_name == 'dahyeon/url-shortener' && body.ref in ['refs/heads/staging', 'refs/heads/prod'] && body.after.matches('^[0-9a-f]{40}$') && body.after != '0000000000000000000000000000000000000000'
- name: overlays
value:
- key: environment
expression: "body.ref.split('/')[2]"
bindings:
- ref: url-shortener-main
template:
ref: url-shortener-main