Compare commits
66
Commits
464aa8be40
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a653c0508 | ||
|
|
a326fe8878 | ||
|
|
ede18d4ec4 | ||
|
|
4336d923aa | ||
|
|
ccf2190592 | ||
|
|
87a1d04da1 | ||
|
|
c313573442 | ||
|
|
c305d03dc5 | ||
|
|
eba6763eee | ||
|
|
618b5182d8 | ||
|
|
dcc476b6fa | ||
|
|
554c09cae9 | ||
|
|
b0b1f3630b | ||
|
|
8c947b6482 | ||
|
|
be032170db | ||
|
|
83efb25978 | ||
|
|
bb34391305 | ||
|
|
c6e886012f | ||
|
|
b44398719c | ||
|
|
ca3817f8da | ||
|
|
b9fe1bcf5e | ||
|
|
c1ce3e8f18 | ||
|
|
c2e201ab82 | ||
|
|
2ee964931d | ||
|
|
a8cb2d22d9 | ||
|
|
0cc28fda66 | ||
|
|
c4d2e340a9 | ||
|
|
6c3857628b | ||
|
|
ae8d1ab9a7 | ||
|
|
7ccc70c0e1 | ||
|
|
21e46316dc | ||
|
|
8a50b69b2a | ||
|
|
51adf81529 | ||
|
|
1ae6a3ced1 | ||
|
|
d38e1d2522 | ||
|
|
ee78781f58 | ||
|
|
155ad7e449 | ||
|
|
d31cb21004 | ||
|
|
fcea6e7107 | ||
|
|
3d4d541d48 | ||
|
|
4206a20dc5 | ||
|
|
a02e372e85 | ||
|
|
3ec9732190 | ||
|
|
b941de2e0e | ||
|
|
aae1888bea | ||
|
|
0108a18e9c | ||
|
|
17e90dae80 | ||
|
|
d909a86b0e | ||
|
|
176c214f86 | ||
|
|
5f119e0429 | ||
|
|
68025438ed | ||
|
|
c63751b700 | ||
|
|
5edb902c0a | ||
|
|
979745c7a0 | ||
|
|
966e109d28 | ||
|
|
54f5c63727 | ||
|
|
7eadf3d6cc | ||
|
|
f05f0f2af9 | ||
|
|
2ed6b93bbe | ||
|
|
5422fef4fb | ||
|
|
52233a7a78 | ||
|
|
47b4440245 | ||
|
|
5295851a12 | ||
|
|
73d42eb61d | ||
|
|
0a43455acf | ||
|
|
361d8d4b02 |
No files matched your search
@@ -9,5 +9,8 @@ Argo CD는 아래 경로에서 서비스 배포 대상을 찾습니다.
|
|||||||
|
|
||||||
애플리케이션 목록:
|
애플리케이션 목록:
|
||||||
|
|
||||||
|
- `blog`
|
||||||
- `lolympus-tournament-support`
|
- `lolympus-tournament-support`
|
||||||
|
- `make-space`
|
||||||
- `persona-lenz`
|
- `persona-lenz`
|
||||||
|
- `url-shortener`
|
||||||
@@ -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)
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: blog
|
||||||
|
automountServiceAccountToken: false
|
||||||
@@ -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
|
||||||
@@ -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 }}"
|
||||||
@@ -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
|
||||||
@@ -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 }}"
|
||||||
@@ -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:c1a1d5cb997e361d9d3ab51671b7fe651c06fd4a07696d4a9336268a5d20c709
|
||||||
|
replicas:
|
||||||
|
- name: blog
|
||||||
|
count: 1
|
||||||
|
patches:
|
||||||
|
- path: deployment-patch.yaml
|
||||||
|
commonAnnotations:
|
||||||
|
blog.dahyeon.us/source-revision: 4c6ab802b46f41d610c4add8586442b9e9c8c200
|
||||||
|
blog.dahyeon.us/cdn-release: 63ea8e2aae86023e
|
||||||
|
blog.dahyeon.us/cdn-manifest: blog-staging/_releases/63ea8e2aae86023e/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
|
||||||
@@ -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.
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: make-space
|
||||||
|
automountServiceAccountToken: false
|
||||||
@@ -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
|
||||||
@@ -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는 배포하지 않습니다.
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
```
|
||||||
@@ -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
|
||||||
@@ -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 }}"
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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"
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: lolympus-pipeline
|
||||||
|
automountServiceAccountToken: false
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: lolympus-event-listener
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: Role
|
||||||
|
metadata:
|
||||||
|
name: lolympus-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:
|
||||||
|
- lolympus-pipeline
|
||||||
|
verbs:
|
||||||
|
- impersonate
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- events
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- patch
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- secrets
|
||||||
|
resourceNames:
|
||||||
|
- lolympus-webhook
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: RoleBinding
|
||||||
|
metadata:
|
||||||
|
name: lolympus-event-listener
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Role
|
||||||
|
name: lolympus-event-listener
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: lolympus-event-listener
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
apiVersion: secrets.infisical.com/v1beta1
|
||||||
|
kind: InfisicalStaticSecret
|
||||||
|
metadata:
|
||||||
|
name: lolympus-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/lolympus-tournament-support
|
||||||
|
recursive: false
|
||||||
|
targets:
|
||||||
|
- name: lolympus-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: lolympus-harbor
|
||||||
|
namespace: tekton-ci
|
||||||
|
kind: Secret
|
||||||
|
creationPolicy: Owner
|
||||||
|
secretType: kubernetes.io/dockerconfigjson
|
||||||
|
template:
|
||||||
|
engineVersion: v1
|
||||||
|
data:
|
||||||
|
.dockerconfigjson: "{{ .HARBOR_DOCKER_CONFIG_JSON.Value }}"
|
||||||
|
- name: lolympus-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: lolympus-webhook
|
||||||
|
namespace: tekton-ci
|
||||||
|
kind: Secret
|
||||||
|
creationPolicy: Owner
|
||||||
|
secretType: Opaque
|
||||||
|
template:
|
||||||
|
engineVersion: v1
|
||||||
|
data:
|
||||||
|
secretToken: "{{ .GITEA_WEBHOOK_SECRET.Value }}"
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: lolympus-main-webhook
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||||
|
spec:
|
||||||
|
ingressClassName: haproxy
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- tekton-hook.dahyeon.us
|
||||||
|
secretName: lolympus-main-webhook-tls
|
||||||
|
rules:
|
||||||
|
- host: tekton-hook.dahyeon.us
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: el-lolympus-main
|
||||||
|
port:
|
||||||
|
number: 8080
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
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: lolympus-tournament-support
|
||||||
|
app.kubernetes.io/part-of: lolympus-ci
|
||||||
|
app.kubernetes.io/managed-by: argocd
|
||||||
|
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: Pipeline
|
||||||
|
metadata:
|
||||||
|
name: lolympus-staging
|
||||||
|
spec:
|
||||||
|
description: Validate, publish, and deploy a main-branch revision to staging.
|
||||||
|
params:
|
||||||
|
- name: git-revision
|
||||||
|
type: string
|
||||||
|
- name: image-tag
|
||||||
|
type: string
|
||||||
|
results:
|
||||||
|
- name: image-digest
|
||||||
|
description: Immutable multi-platform API image index digest.
|
||||||
|
value: $(tasks.create-image-index.results.image-digest)
|
||||||
|
- name: gitops-commit
|
||||||
|
description: service-state commit applied to staging.
|
||||||
|
value: $(tasks.update-gitops.results.gitops-commit)
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
- name: gitea-credentials
|
||||||
|
- name: harbor-dockerconfig
|
||||||
|
tasks:
|
||||||
|
- name: clone
|
||||||
|
taskRef:
|
||||||
|
name: lolympus-clone
|
||||||
|
params:
|
||||||
|
- name: revision
|
||||||
|
value: $(params.git-revision)
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: source
|
||||||
|
- name: credentials
|
||||||
|
workspace: gitea-credentials
|
||||||
|
- name: quality
|
||||||
|
runAfter:
|
||||||
|
- clone
|
||||||
|
taskRef:
|
||||||
|
name: lolympus-quality
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: source
|
||||||
|
- name: build-api-amd64
|
||||||
|
runAfter:
|
||||||
|
- quality
|
||||||
|
taskRef:
|
||||||
|
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:
|
||||||
|
- name: image
|
||||||
|
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:
|
||||||
|
- name: dockerconfig
|
||||||
|
workspace: harbor-dockerconfig
|
||||||
|
- name: assert-latest
|
||||||
|
runAfter:
|
||||||
|
- create-image-index
|
||||||
|
taskRef:
|
||||||
|
name: lolympus-assert-latest
|
||||||
|
params:
|
||||||
|
- name: revision
|
||||||
|
value: $(params.git-revision)
|
||||||
|
workspaces:
|
||||||
|
- name: credentials
|
||||||
|
workspace: gitea-credentials
|
||||||
|
- name: deploy-web
|
||||||
|
runAfter:
|
||||||
|
- assert-latest
|
||||||
|
taskRef:
|
||||||
|
name: lolympus-deploy-cloudflare
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: source
|
||||||
|
- name: update-gitops
|
||||||
|
runAfter:
|
||||||
|
- deploy-web
|
||||||
|
taskRef:
|
||||||
|
name: lolympus-update-gitops
|
||||||
|
params:
|
||||||
|
- name: revision
|
||||||
|
value: $(params.git-revision)
|
||||||
|
- name: image-digest
|
||||||
|
value: $(tasks.create-image-index.results.image-digest)
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: source
|
||||||
|
- name: credentials
|
||||||
|
workspace: gitea-credentials
|
||||||
@@ -0,0 +1,571 @@
|
|||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: Task
|
||||||
|
metadata:
|
||||||
|
name: lolympus-clone
|
||||||
|
spec:
|
||||||
|
description: Clone and verify the exact source revision from Gitea.
|
||||||
|
params:
|
||||||
|
- name: revision
|
||||||
|
type: string
|
||||||
|
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/lolympus-tournament-support.git
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
SOURCE_DIR="$(workspaces.source.path)"
|
||||||
|
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"
|
||||||
|
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"
|
||||||
|
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
|
||||||
|
---
|
||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: Task
|
||||||
|
metadata:
|
||||||
|
name: lolympus-quality
|
||||||
|
spec:
|
||||||
|
description: Install dependencies, lint, test, build, and audit the monorepo.
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
stepTemplate:
|
||||||
|
image: docker.io/library/node:26-bookworm-slim@sha256:2d49d876e96237d76de412761cf05dbfe5aee325cc4406a4d41d5824c5bb8beb
|
||||||
|
workingDir: $(workspaces.source.path)
|
||||||
|
env:
|
||||||
|
- name: CI
|
||||||
|
value: "true"
|
||||||
|
- name: NPM_CONFIG_CACHE
|
||||||
|
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:
|
||||||
|
- name: install
|
||||||
|
computeResources:
|
||||||
|
requests: {cpu: 200m, memory: 512Mi}
|
||||||
|
limits: {cpu: "2", memory: 4Gi}
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
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
|
||||||
|
computeResources:
|
||||||
|
requests: {cpu: 100m, memory: 256Mi}
|
||||||
|
limits: {cpu: "2", memory: 2Gi}
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
pnpm --filter api exec eslint \
|
||||||
|
"{src,apps,libs,test}/**/*.ts" --max-warnings=0
|
||||||
|
pnpm --filter web lint
|
||||||
|
- name: test
|
||||||
|
computeResources:
|
||||||
|
requests: {cpu: 100m, memory: 512Mi}
|
||||||
|
limits: {cpu: "3", memory: 4Gi}
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
pnpm --filter api test --runInBand
|
||||||
|
pnpm --filter web test
|
||||||
|
node --test scripts/deploy-cloudflare-pages.test.mjs
|
||||||
|
- name: build
|
||||||
|
computeResources:
|
||||||
|
requests: {cpu: 200m, memory: 512Mi}
|
||||||
|
limits: {cpu: "3", memory: 4Gi}
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
pnpm --filter api build
|
||||||
|
pnpm --filter web build:staging
|
||||||
|
- name: audit
|
||||||
|
computeResources:
|
||||||
|
requests: {cpu: 50m, memory: 128Mi}
|
||||||
|
limits: {cpu: "1", memory: 1Gi}
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
pnpm audit --prod --audit-level high
|
||||||
|
---
|
||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: Task
|
||||||
|
metadata:
|
||||||
|
name: lolympus-build-platform
|
||||||
|
spec:
|
||||||
|
description: Clone an exact revision and build one native API platform with rootless BuildKit.
|
||||||
|
params:
|
||||||
|
- name: revision
|
||||||
|
type: string
|
||||||
|
- name: platform
|
||||||
|
type: string
|
||||||
|
- name: image
|
||||||
|
type: string
|
||||||
|
results:
|
||||||
|
- name: image-url
|
||||||
|
description: Pushed image repository and tag.
|
||||||
|
- name: image-digest
|
||||||
|
description: Immutable digest returned by the registry.
|
||||||
|
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/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
|
||||||
|
image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c
|
||||||
|
workingDir: /workspace/build
|
||||||
|
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)
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
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 \
|
||||||
|
--frontend dockerfile.v0 \
|
||||||
|
--local context=. \
|
||||||
|
--local dockerfile=. \
|
||||||
|
--opt filename=Dockerfile \
|
||||||
|
--opt platform=$(params.platform) \
|
||||||
|
--output "type=image,name=$(params.image),push=true" \
|
||||||
|
--metadata-file "$(results.image-digest.path)"
|
||||||
|
- name: record-digest
|
||||||
|
image: docker.io/mikefarah/yq:4.47.2@sha256:76def1f56f456ecc1c3173ea275218ee17139bc2018c5a07887b15afd88ec03e
|
||||||
|
workingDir: /workspace/build
|
||||||
|
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
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
DIGEST="$(yq -r '."containerimage.digest"' "$(results.image-digest.path)")"
|
||||||
|
if [ -z "$DIGEST" ] || [ "$DIGEST" = "null" ]; then
|
||||||
|
echo "BuildKit did not return an image digest" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
printf '%s' "$(params.image)" >"$(results.image-url.path)"
|
||||||
|
printf '%s' "$DIGEST" >"$(results.image-digest.path)"
|
||||||
|
---
|
||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
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:
|
||||||
|
name: lolympus-assert-latest
|
||||||
|
spec:
|
||||||
|
description: Stop superseded main-branch runs before external deployment.
|
||||||
|
params:
|
||||||
|
- name: revision
|
||||||
|
type: string
|
||||||
|
workspaces:
|
||||||
|
- name: credentials
|
||||||
|
readOnly: true
|
||||||
|
steps:
|
||||||
|
- name: assert
|
||||||
|
image: docker.io/alpine/git:2.49.1@sha256:c0280cf9572316299b08544065d3bf35db65043d5e3963982ec50647d2746e26
|
||||||
|
computeResources:
|
||||||
|
requests: {cpu: 50m, memory: 64Mi}
|
||||||
|
limits: {cpu: 500m, memory: 256Mi}
|
||||||
|
env:
|
||||||
|
- name: REPO_URL
|
||||||
|
value: https://git.dahyeon.us/dahyeon/lolympus-tournament-support.git
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
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"
|
||||||
|
REMOTE_REVISION="$(git ls-remote "$REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
|
||||||
|
if [ "$REMOTE_REVISION" != "$(params.revision)" ]; then
|
||||||
|
echo "Revision $(params.revision) was superseded by $REMOTE_REVISION" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
---
|
||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: Task
|
||||||
|
metadata:
|
||||||
|
name: lolympus-deploy-cloudflare
|
||||||
|
spec:
|
||||||
|
description: Build and deploy the staging frontend to Cloudflare Pages.
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
steps:
|
||||||
|
- name: deploy
|
||||||
|
image: docker.io/library/node:26-bookworm-slim@sha256:2d49d876e96237d76de412761cf05dbfe5aee325cc4406a4d41d5824c5bb8beb
|
||||||
|
workingDir: $(workspaces.source.path)
|
||||||
|
computeResources:
|
||||||
|
requests: {cpu: 200m, memory: 512Mi}
|
||||||
|
limits: {cpu: "2", memory: 4Gi}
|
||||||
|
env:
|
||||||
|
- name: CI
|
||||||
|
value: "true"
|
||||||
|
- name: NPM_CONFIG_CACHE
|
||||||
|
value: $(workspaces.source.path)/.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
|
||||||
|
value: lolympus
|
||||||
|
- name: CF_PAGES_STAGING_BRANCH
|
||||||
|
value: staging
|
||||||
|
envFrom:
|
||||||
|
- secretRef:
|
||||||
|
name: lolympus-cloudflare
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
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
|
||||||
|
kind: Task
|
||||||
|
metadata:
|
||||||
|
name: lolympus-update-gitops
|
||||||
|
spec:
|
||||||
|
description: Update the staging image index digest in service-state.
|
||||||
|
params:
|
||||||
|
- name: revision
|
||||||
|
type: string
|
||||||
|
- name: image-digest
|
||||||
|
type: string
|
||||||
|
results:
|
||||||
|
- name: gitops-commit
|
||||||
|
description: Commit pushed to service-state.
|
||||||
|
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/lolympus-tournament-support.git
|
||||||
|
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
|
||||||
|
SOURCE_DIR="$(workspaces.source.path)"
|
||||||
|
STATE_DIR="$SOURCE_DIR/.gitops"
|
||||||
|
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 "$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: IMAGE_NAME
|
||||||
|
value: registry.dahyeon.us/lolympus/lolympus-tournament-support
|
||||||
|
- name: IMAGE_DIGEST
|
||||||
|
value: $(params.image-digest)
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
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"
|
||||||
|
MATCHES="$(yq '[.images[] | select(.name == strenv(IMAGE_NAME))] | length' "$MANIFEST")"
|
||||||
|
if [ "$MATCHES" != "1" ]; then
|
||||||
|
echo "Expected one image entry for $IMAGE_NAME, found $MATCHES" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
yq -i \
|
||||||
|
'(.images[] | select(.name == strenv(IMAGE_NAME))) |= (del(.newTag) | .digest = strenv(IMAGE_DIGEST))' \
|
||||||
|
"$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}
|
||||||
|
script: |
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
STATE_DIR="$(workspaces.source.path)/.gitops"
|
||||||
|
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"
|
||||||
|
git -C "$STATE_DIR" config user.name "lolympus-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 >"$(results.gitops-commit.path)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
REMOTE_REVISION="$(git ls-remote "$SOURCE_REPO_URL" refs/heads/main | awk 'NR == 1 {print $1}')"
|
||||||
|
if [ "$REMOTE_REVISION" != "$(params.revision)" ]; then
|
||||||
|
echo "Revision $(params.revision) was superseded by $REMOTE_REVISION" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
git -C "$STATE_DIR" add apps/lolympus-tournament-support/overlays/staging/kustomization.yaml
|
||||||
|
git -C "$STATE_DIR" commit \
|
||||||
|
-m "chore(lolympus): deploy staging $(params.image-digest)"
|
||||||
|
git -C "$STATE_DIR" pull --rebase origin main
|
||||||
|
git -C "$STATE_DIR" push origin HEAD:main
|
||||||
|
git -C "$STATE_DIR" rev-parse HEAD >"$(results.gitops-commit.path)"
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
apiVersion: triggers.tekton.dev/v1beta1
|
||||||
|
kind: TriggerBinding
|
||||||
|
metadata:
|
||||||
|
name: lolympus-main
|
||||||
|
spec:
|
||||||
|
params:
|
||||||
|
- name: git-revision
|
||||||
|
value: $(body.after)
|
||||||
|
---
|
||||||
|
apiVersion: triggers.tekton.dev/v1beta1
|
||||||
|
kind: TriggerTemplate
|
||||||
|
metadata:
|
||||||
|
name: lolympus-main
|
||||||
|
spec:
|
||||||
|
params:
|
||||||
|
- name: git-revision
|
||||||
|
resourcetemplates:
|
||||||
|
- apiVersion: tekton.dev/v1
|
||||||
|
kind: PipelineRun
|
||||||
|
metadata:
|
||||||
|
generateName: lolympus-staging-
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: lolympus-tournament-support
|
||||||
|
app.kubernetes.io/part-of: lolympus-ci
|
||||||
|
spec:
|
||||||
|
pipelineRef:
|
||||||
|
name: lolympus-staging
|
||||||
|
params:
|
||||||
|
- name: git-revision
|
||||||
|
value: $(tt.params.git-revision)
|
||||||
|
- name: image-tag
|
||||||
|
value: sha-$(tt.params.git-revision)
|
||||||
|
taskRunTemplate:
|
||||||
|
serviceAccountName: lolympus-pipeline
|
||||||
|
podTemplate:
|
||||||
|
securityContext:
|
||||||
|
fsGroup: 1000
|
||||||
|
fsGroupChangePolicy: OnRootMismatch
|
||||||
|
taskRunSpecs:
|
||||||
|
- pipelineTaskName: build-api-amd64
|
||||||
|
podTemplate:
|
||||||
|
nodeSelector:
|
||||||
|
kubernetes.io/arch: amd64
|
||||||
|
- pipelineTaskName: build-api-arm64
|
||||||
|
podTemplate:
|
||||||
|
nodeSelector:
|
||||||
|
kubernetes.io/arch: arm64
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
volumeClaimTemplate:
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
storageClassName: local-path
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Gi
|
||||||
|
- name: gitea-credentials
|
||||||
|
secret:
|
||||||
|
secretName: lolympus-gitea
|
||||||
|
items:
|
||||||
|
- key: username
|
||||||
|
path: username
|
||||||
|
- key: password
|
||||||
|
path: password
|
||||||
|
- name: harbor-dockerconfig
|
||||||
|
secret:
|
||||||
|
secretName: lolympus-harbor
|
||||||
|
items:
|
||||||
|
- key: .dockerconfigjson
|
||||||
|
path: config.json
|
||||||
|
timeouts:
|
||||||
|
pipeline: 45m
|
||||||
|
tasks: 40m
|
||||||
|
---
|
||||||
|
apiVersion: triggers.tekton.dev/v1beta1
|
||||||
|
kind: EventListener
|
||||||
|
metadata:
|
||||||
|
name: lolympus-main
|
||||||
|
spec:
|
||||||
|
serviceAccountName: lolympus-event-listener
|
||||||
|
triggers:
|
||||||
|
- name: main-push
|
||||||
|
interceptors:
|
||||||
|
- ref:
|
||||||
|
name: github
|
||||||
|
params:
|
||||||
|
- name: secretRef
|
||||||
|
value:
|
||||||
|
secretName: lolympus-webhook
|
||||||
|
secretKey: secretToken
|
||||||
|
- name: eventTypes
|
||||||
|
value:
|
||||||
|
- push
|
||||||
|
- ref:
|
||||||
|
name: cel
|
||||||
|
params:
|
||||||
|
- name: filter
|
||||||
|
value: >-
|
||||||
|
body.repository.full_name == 'dahyeon/lolympus-tournament-support' &&
|
||||||
|
body.ref == 'refs/heads/main' &&
|
||||||
|
body.after.matches('^[0-9a-f]{40}$')
|
||||||
|
bindings:
|
||||||
|
- ref: lolympus-main
|
||||||
|
template:
|
||||||
|
ref: lolympus-main
|
||||||
@@ -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
|
||||||
@@ -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 }}"
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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"
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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 }}"
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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"
|
||||||
@@ -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
|
||||||
Reference in new issue
Block a user