Compare commits

...
3 Commits
Author SHA1 Message Date
dahyeon 73d42eb61d feat: automate lolympus staging delivery 2026-07-18 07:52:56 +00:00
dahyeon 0a43455acf feat: add lolympus Tekton build tasks 2026-07-18 07:52:56 +00:00
dahyeon 361d8d4b02 feat: add isolated Tekton CI foundation
Define namespace quotas, least-privilege EventListener RBAC, tokenless PipelineRun service account, and Infisical-backed purpose-specific credentials.
2026-07-18 07:52:56 +00:00
7 changed files with 751 additions and 0 deletions

No files matched your search

@@ -0,0 +1,108 @@
apiVersion: v1
kind: ResourceQuota
metadata:
name: lolympus-ci
spec:
hard:
pods: "20"
persistentvolumeclaims: "10"
requests.cpu: "8"
requests.memory: 16Gi
requests.storage: 100Gi
limits.cpu: "16"
limits.memory: 32Gi
count/pipelineruns.tekton.dev: "20"
count/taskruns.tekton.dev: "100"
---
apiVersion: v1
kind: LimitRange
metadata:
name: lolympus-ci
spec:
limits:
- type: Container
defaultRequest:
cpu: 100m
memory: 256Mi
default:
cpu: "2"
memory: 4Gi
---
apiVersion: v1
kind: ServiceAccount
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
- 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,89 @@
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 API image digest.
value: $(tasks.build-api.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
runAfter:
- quality
taskRef:
name: lolympus-build-image
params:
- name: image
value: registry.dahyeon.us/lolympus/lolympus-tournament-support:$(params.image-tag)
workspaces:
- name: source
workspace: source
- name: dockerconfig
workspace: harbor-dockerconfig
- name: assert-latest
runAfter:
- build-api
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-tag
value: $(params.image-tag)
workspaces:
- name: source
workspace: source
- name: credentials
workspace: gitea-credentials
+358
View File
@@ -0,0 +1,358 @@
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: COREPACK_HOME
value: $(workspaces.source.path)/.ci/corepack
steps:
- name: install
computeResources:
requests: {cpu: 200m, memory: 512Mi}
limits: {cpu: "2", memory: 4Gi}
script: |
#!/bin/sh
set -eu
corepack pnpm install --frozen-lockfile
- name: lint
computeResources:
requests: {cpu: 100m, memory: 256Mi}
limits: {cpu: "2", memory: 2Gi}
script: |
#!/bin/sh
set -eu
corepack pnpm --filter api exec eslint \
"{src,apps,libs,test}/**/*.ts" --max-warnings=0
corepack pnpm --filter web lint
- name: test
computeResources:
requests: {cpu: 100m, memory: 512Mi}
limits: {cpu: "3", memory: 4Gi}
script: |
#!/bin/sh
set -eu
corepack pnpm --filter api test -- --runInBand
corepack pnpm --filter web test
corepack pnpm test:deploy:web
- name: build
computeResources:
requests: {cpu: 200m, memory: 512Mi}
limits: {cpu: "3", memory: 4Gi}
script: |
#!/bin/sh
set -eu
corepack pnpm --filter api build
corepack pnpm --filter web build:staging
- name: audit
computeResources:
requests: {cpu: 50m, memory: 128Mi}
limits: {cpu: "1", memory: 1Gi}
script: |
#!/bin/sh
set -eu
corepack pnpm audit --prod --audit-level high
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: lolympus-build-image
spec:
description: Build and push the API image with rootless BuildKit.
params:
- 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: source
- name: dockerconfig
readOnly: true
steps:
- name: build-and-push
image: docker.io/moby/buildkit:v0.31.1-rootless@sha256:946cf909534b789c9b84af75e6d4f8cb23c3b9cb387daec5ba0f4878a3e4647c
workingDir: $(workspaces.source.path)
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
procMount: Unmasked
env:
- name: BUILDKITD_FLAGS
value: --oci-worker-no-process-sandbox
- name: DOCKER_CONFIG
value: $(workspaces.dockerconfig.path)
script: |
#!/bin/sh
set -eu
buildctl-daemonless.sh build \
--frontend dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--opt filename=Dockerfile \
--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: $(workspaces.source.path)
computeResources:
requests: {cpu: 50m, memory: 64Mi}
limits: {cpu: 250m, memory: 256Mi}
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-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: COREPACK_HOME
value: $(workspaces.source.path)/.ci/corepack
- name: CF_PAGES_PROJECT_NAME
value: lolympus
- name: CF_PAGES_STAGING_BRANCH
value: staging
envFrom:
- secretRef:
name: lolympus-cloudflare
script: |
#!/bin/sh
set -eu
corepack pnpm deploy:web:staging
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: lolympus-update-gitops
spec:
description: Update the staging image tag in service-state.
params:
- name: revision
type: string
- name: image-tag
type: string
results:
- name: gitops-commit
description: Commit pushed to service-state.
workspaces:
- name: source
- name: credentials
readOnly: true
stepTemplate:
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_TAG
value: $(params.image-tag)
script: |
#!/bin/sh
set -eu
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))).newTag = strenv(IMAGE_TAG)' \
"$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-tag)"
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,97 @@
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
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