diff --git a/README.md b/README.md index 47901dd..46906c0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Argo CD는 아래 경로에서 서비스 배포 대상을 찾습니다. 애플리케이션 목록: - `lolympus-tournament-support` +- `make-space` - `persona-lenz` - `url-shortener` diff --git a/apps/make-space/README.md b/apps/make-space/README.md new file mode 100644 index 0000000..defc2ff --- /dev/null +++ b/apps/make-space/README.md @@ -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. diff --git a/apps/make-space/base/deployment.yaml b/apps/make-space/base/deployment.yaml new file mode 100644 index 0000000..1f9f97a --- /dev/null +++ b/apps/make-space/base/deployment.yaml @@ -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 diff --git a/apps/make-space/base/kustomization.yaml b/apps/make-space/base/kustomization.yaml new file mode 100644 index 0000000..c41d380 --- /dev/null +++ b/apps/make-space/base/kustomization.yaml @@ -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 diff --git a/apps/make-space/base/poddisruptionbudget.yaml b/apps/make-space/base/poddisruptionbudget.yaml new file mode 100644 index 0000000..ebfc24e --- /dev/null +++ b/apps/make-space/base/poddisruptionbudget.yaml @@ -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 diff --git a/apps/make-space/base/serviceaccount.yaml b/apps/make-space/base/serviceaccount.yaml new file mode 100644 index 0000000..402806c --- /dev/null +++ b/apps/make-space/base/serviceaccount.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: make-space +automountServiceAccountToken: false diff --git a/apps/make-space/base/services.yaml b/apps/make-space/base/services.yaml new file mode 100644 index 0000000..ca582ae --- /dev/null +++ b/apps/make-space/base/services.yaml @@ -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 diff --git a/apps/make-space/overlays/prod/configmap.yaml b/apps/make-space/overlays/prod/configmap.yaml new file mode 100644 index 0000000..e730f3d --- /dev/null +++ b/apps/make-space/overlays/prod/configmap.yaml @@ -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 diff --git a/apps/make-space/overlays/prod/deployment-patch.yaml b/apps/make-space/overlays/prod/deployment-patch.yaml new file mode 100644 index 0000000..957a9a8 --- /dev/null +++ b/apps/make-space/overlays/prod/deployment-patch.yaml @@ -0,0 +1,9 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: make-space +spec: + template: + metadata: + labels: + app.kubernetes.io/environment: prod diff --git a/apps/make-space/overlays/prod/infisical-secret.yaml b/apps/make-space/overlays/prod/infisical-secret.yaml new file mode 100644 index 0000000..1e33ed7 --- /dev/null +++ b/apps/make-space/overlays/prod/infisical-secret.yaml @@ -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 diff --git a/apps/make-space/overlays/prod/ingress.yaml b/apps/make-space/overlays/prod/ingress.yaml new file mode 100644 index 0000000..bb2ae3e --- /dev/null +++ b/apps/make-space/overlays/prod/ingress.yaml @@ -0,0 +1,23 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: make-space + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod +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 diff --git a/apps/make-space/overlays/prod/kustomization.yaml b/apps/make-space/overlays/prod/kustomization.yaml new file mode 100644 index 0000000..6d13799 --- /dev/null +++ b/apps/make-space/overlays/prod/kustomization.yaml @@ -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 + newTag: prod +replicas: + - name: make-space + count: 1 +patches: + - path: deployment-patch.yaml +commonAnnotations: + make-space.dahyeon.us/source-revision: bootstrap diff --git a/apps/make-space/overlays/staging/configmap.yaml b/apps/make-space/overlays/staging/configmap.yaml new file mode 100644 index 0000000..1fc85dc --- /dev/null +++ b/apps/make-space/overlays/staging/configmap.yaml @@ -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 diff --git a/apps/make-space/overlays/staging/deployment-patch.yaml b/apps/make-space/overlays/staging/deployment-patch.yaml new file mode 100644 index 0000000..fc837ce --- /dev/null +++ b/apps/make-space/overlays/staging/deployment-patch.yaml @@ -0,0 +1,9 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: make-space +spec: + template: + metadata: + labels: + app.kubernetes.io/environment: staging diff --git a/apps/make-space/overlays/staging/infisical-secret.yaml b/apps/make-space/overlays/staging/infisical-secret.yaml new file mode 100644 index 0000000..92890d9 --- /dev/null +++ b/apps/make-space/overlays/staging/infisical-secret.yaml @@ -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 diff --git a/apps/make-space/overlays/staging/ingress.yaml b/apps/make-space/overlays/staging/ingress.yaml new file mode 100644 index 0000000..f89f588 --- /dev/null +++ b/apps/make-space/overlays/staging/ingress.yaml @@ -0,0 +1,23 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: make-space + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod +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 diff --git a/apps/make-space/overlays/staging/kustomization.yaml b/apps/make-space/overlays/staging/kustomization.yaml new file mode 100644 index 0000000..f11b617 --- /dev/null +++ b/apps/make-space/overlays/staging/kustomization.yaml @@ -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 + newTag: staging +replicas: + - name: make-space + count: 1 +patches: + - path: deployment-patch.yaml +commonAnnotations: + make-space.dahyeon.us/source-revision: bootstrap diff --git a/ci/make-space/foundation.yaml b/ci/make-space/foundation.yaml new file mode 100644 index 0000000..81dfc2f --- /dev/null +++ b/ci/make-space/foundation.yaml @@ -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 diff --git a/ci/make-space/infisical-secret.yaml b/ci/make-space/infisical-secret.yaml new file mode 100644 index 0000000..1fda91b --- /dev/null +++ b/ci/make-space/infisical-secret.yaml @@ -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 }}" diff --git a/ci/make-space/ingress.yaml b/ci/make-space/ingress.yaml new file mode 100644 index 0000000..d560495 --- /dev/null +++ b/ci/make-space/ingress.yaml @@ -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 diff --git a/ci/make-space/kustomization.yaml b/ci/make-space/kustomization.yaml new file mode 100644 index 0000000..d39f0b5 --- /dev/null +++ b/ci/make-space/kustomization.yaml @@ -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 diff --git a/ci/make-space/pipeline.yaml b/ci/make-space/pipeline.yaml new file mode 100644 index 0000000..b052314 --- /dev/null +++ b/ci/make-space/pipeline.yaml @@ -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 diff --git a/ci/make-space/tasks.yaml b/ci/make-space/tasks.yaml new file mode 100644 index 0000000..df0adf7 --- /dev/null +++ b/ci/make-space/tasks.yaml @@ -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" diff --git a/ci/make-space/trigger.yaml b/ci/make-space/trigger.yaml new file mode 100644 index 0000000..3eacd7e --- /dev/null +++ b/ci/make-space/trigger.yaml @@ -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