From 9a81ee8dc60002ec1b6efd033c670ae04237108f Mon Sep 17 00:00:00 2001 From: Christoper Tan Date: Tue, 22 Aug 2023 16:18:01 -0700 Subject: [PATCH] updated the react-demo pipeline and created triggers --- tekton/base/pipelines/react.yaml | 38 ++++++++- tekton/base/tasks/kustomization.yaml | 1 + tekton/base/tasks/react-update.yaml | 34 ++++++++ tekton/base/triggers/kustomization.yaml | 1 + tekton/base/triggers/trigger-react-build.yaml | 80 +++++++++++++++++++ test.yaml | 0 6 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 tekton/base/tasks/react-update.yaml create mode 100644 tekton/base/triggers/trigger-react-build.yaml delete mode 100644 test.yaml diff --git a/tekton/base/pipelines/react.yaml b/tekton/base/pipelines/react.yaml index 0286829c..80c0b451 100644 --- a/tekton/base/pipelines/react.yaml +++ b/tekton/base/pipelines/react.yaml @@ -13,11 +13,17 @@ spec: - description: The git branch to clone. name: branchName type: string - - name: pathToContext + - description: Path to the file that contains the application + name: pathToContext type: string - - name: imageTag + - description: A tag to differentiate versions of images + name: imageTag type: string - default: v1 + default: latest + - description: Whether or not runDeploy will run. Will run if set to 'true' + name: runDeploy + type: string + default: false tasks: - name: fetch-repo params: @@ -31,6 +37,7 @@ spec: workspaces: - name: output workspace: shared-data + - name: react-workspace params: - name: CONTEXT_DIR @@ -43,6 +50,7 @@ spec: workspaces: - name: source workspace: shared-data + - name: react-build params: - name: CONTEXT_DIR @@ -60,7 +68,12 @@ spec: workspaces: - name: source workspace: shared-data + - name: react-deploy + when: + - input: "$(params.runDeploy)" + operator: in + values: ["true"] params: - name: APP_NAME value: $(params.appName) @@ -73,6 +86,25 @@ spec: taskRef: kind: Task name: t-react-deploy + + - name: react-update + when: + - input: "$(params.runDeploy)" + operator: notin + values: ["true"] + params: + - name: APP_NAME + value: $(params.appName) + - name: TAG + value: $(params.imageTag) + - name: NAMESPACE + value: $(context.pipelineRun.namespace) + runAfter: + - react-build + taskRef: + kind: Task + name: t-react-update + workspaces: - description: | This workspace will receive the cloned git repo and be passed diff --git a/tekton/base/tasks/kustomization.yaml b/tekton/base/tasks/kustomization.yaml index fe87d41b..7808c1fa 100644 --- a/tekton/base/tasks/kustomization.yaml +++ b/tekton/base/tasks/kustomization.yaml @@ -9,6 +9,7 @@ resources: - git-clone.yaml - react-workspace.yaml - react-deploy.yaml +- react-update.yaml - mvn-build.yaml - mvn-sonar-scan.yaml - npm-sonar-scan.yaml diff --git a/tekton/base/tasks/react-update.yaml b/tekton/base/tasks/react-update.yaml new file mode 100644 index 00000000..e635fadc --- /dev/null +++ b/tekton/base/tasks/react-update.yaml @@ -0,0 +1,34 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: react-update + labels: + app.kubernetes.io/version: "0.2" + annotations: + tekton.dev/pipelines.minVersion: "0.12.1" + tekton.dev/categories: Build Tools + tekton.dev/tags: build-tool + tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le" +spec: + params: + - name: APP_NAME + type: string + - name: TAG + type: string + description: Image tag of the imagestream + - name: NAMESPACE + type: string + description: Namespace tobe deploy + steps: + - name: deploy + args: + - set + - image + - deploymentconfig/$(params.APP_NAME) + - $(params.APP_NAME)=$(params.APP_NAME):$(params.TAG) + - '--namespace=$(params.NAMESPACE)' + command: + - oc + image: openshift/origin-cli:latest + resources: {} + \ No newline at end of file diff --git a/tekton/base/triggers/kustomization.yaml b/tekton/base/triggers/kustomization.yaml index 3d1cc1de..8f4db28d 100644 --- a/tekton/base/triggers/kustomization.yaml +++ b/tekton/base/triggers/kustomization.yaml @@ -6,5 +6,6 @@ resources: - ingress.yaml # switch to use the default serviceAccount/pipeline - rbac.yaml + - trigger-react-build.yaml - trigger-flask-web.yaml - trigger-maven-build.yaml diff --git a/tekton/base/triggers/trigger-react-build.yaml b/tekton/base/triggers/trigger-react-build.yaml new file mode 100644 index 00000000..9494bfe1 --- /dev/null +++ b/tekton/base/triggers/trigger-react-build.yaml @@ -0,0 +1,80 @@ +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerTemplate +metadata: + name: react-build-trigger +spec: + params: + - name: appName + default: simple-react + - name: repoUrl + default: https://github.com/bcgov/pipeline-templates.git + - name: branchName + default: main + - name: pathToContext + default: ./tekton/demo/simple-react + - name: imageTag + default: v1 + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: react-build-run- + spec: + pipelineRef: + name: p-react-build + params: + - name: appName + value: $(tt.params.appName) + - name: repoUrl + value: $(tt.params.repoUrl) + - name: branchName + value: $(tt.params.branchName) + - name: pathToContext + value: $(tt.params.pathToContext) + - name: imageTag + value: $(tt.params.imageTag) + workspaces: + - name: shared-data + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: EventListener +metadata: + name: react-build-event-listener +spec: + serviceAccountName: pipeline + triggers: + - name: github-listener + interceptors: + - github: + secretRef: + secretName: github-webhook-secret + secretKey: secretToken + eventTypes: + - pull_request + - push + bindings: + - ref: react-build-trigger-binding + template: + ref: react-build-trigger +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + name: react-build-trigger-binding +spec: + params: + - name: branchName + value: $(body.ref) + - name: repoUrl + value: $(body.repository.url) + - name: contenttype + value: $(header.Content-Type) + - name: imageTag + value: $(body.head_commit.message) diff --git a/test.yaml b/test.yaml deleted file mode 100644 index e69de29b..00000000