commit 3288087310c723cb18913d75109c67f9e900963a Author: eding Date: Sun Feb 8 01:20:35 2026 +0100 chore: pipelines init diff --git a/pipelines/build-pipeline.yaml b/pipelines/build-pipeline.yaml new file mode 100644 index 0000000..da2615d --- /dev/null +++ b/pipelines/build-pipeline.yaml @@ -0,0 +1,23 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: EventListener +metadata: + name: cicd-listener + namespace: tekton-pipelines +spec: + serviceAccountName: tekton-triggers-sa # Needs RBAC to start PipelineRuns + triggers: + - name: github-push + interceptors: + - ref: + name: github + params: + - name: secretRef + value: + secretName: webhook-secret + secretKey: token + - name: eventTypes + value: ["push"] + bindings: + - ref: git-binding # Maps JSON payload to Params + template: + ref: build-template # Creates the PipelineRun \ No newline at end of file diff --git a/tasks/cleanup-preview.yaml b/tasks/cleanup-preview.yaml new file mode 100644 index 0000000..9c6845c --- /dev/null +++ b/tasks/cleanup-preview.yaml @@ -0,0 +1,13 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: cleanup-preview +spec: + params: + - name: app-name + - name: pr-number + steps: + - name: delete-ns + image: bitnami/kubectl:latest + script: | + kubectl delete namespace preview-$(params.app-name)-$(params.pr-number) --ignore-not-found \ No newline at end of file diff --git a/tasks/git-clone.yaml b/tasks/git-clone.yaml new file mode 100644 index 0000000..4e2c5f6 --- /dev/null +++ b/tasks/git-clone.yaml @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: git-clone + namespace: tekton-pipelines +spec: + workspaces: + - name: output + params: + - name: url + type: string + - name: revision + type: string + default: main + steps: + - name: clone + image: alpine/git + script: | + git clone $(params.url) $(workspaces.output.path) + cd $(workspaces.output.path) + git checkout $(params.revision) \ No newline at end of file diff --git a/tasks/manage-preview.yaml b/tasks/manage-preview.yaml new file mode 100644 index 0000000..ab2be8e --- /dev/null +++ b/tasks/manage-preview.yaml @@ -0,0 +1,68 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: manage-preview + namespace: tekton-pipelines +spec: + params: + - name: app-name + - name: pr-number + - name: action # "apply" or "delete" + - name: image-tag + default: "latest" + workspaces: + - name: source # Workspace containing the app's code (to find preview/values.yaml) + steps: + - name: preview-logic + image: bitnami/kubectl:latest + workingDir: $(workspaces.source.path) + script: | + # Use a specific naming convention for the PR namespace + NS="$(params.app-name)-pr-$(params.pr-number)" + + if [ "$(params.action)" = "delete" ]; then + echo "Cleaning up PR environment..." + kubectl delete namespace $NS --ignore-not-found + exit 0 + fi + + echo "Deploying PR environment to namespace: $NS" + kubectl create namespace $NS --dry-run=client -o yaml | kubectl apply -f - + + # Check if the app repo has custom preview values + VALUES_REF_YAML="" + if [ -f "preview/values.yaml" ]; then + kubectl create configmap preview-values --from-file=values.yaml=preview/values.yaml \ + -n $NS --dry-run=client -o yaml | kubectl apply -f - + VALUES_REF_YAML="- kind: ConfigMap\n name: preview-values" + fi + + # Apply the HelmRelease for this specific PR + cat <