diff --git a/Tekton/conditions/is-equal.yaml b/Tekton/conditions/is-equal.yaml new file mode 100644 index 0000000..92d4ef2 --- /dev/null +++ b/Tekton/conditions/is-equal.yaml @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1alpha1 +kind: Condition +metadata: + name: is-equal +spec: + params: + - name: left + type: string + - name: right + type: string + check: + image: alpine + script: | + #!/bin/sh + if [ $(params.left) = $(params.right) ]; then + echo "$(params.left) == $(params.right)" + exit 0 + else + echo "$(params.left) != $(params.right)" + exit 1 + fi \ No newline at end of file diff --git a/Tekton/pipeline/pipeline.yaml b/Tekton/pipeline/pipeline.yaml index 1957241..52c91f4 100644 --- a/Tekton/pipeline/pipeline.yaml +++ b/Tekton/pipeline/pipeline.yaml @@ -28,6 +28,13 @@ spec: - name: build-and-push taskRef: name: build-and-push + conditions: + - conditionRef: "file-exists" + params: + - name: "left" + value: "stage-infra" + - name: "right" + value: "$(inputs.params.git-repo-name)" runAfter: - clone workspaces: diff --git a/Tekton/resources/secrets.yaml b/Tekton/resources/secrets.yaml index 6af12ab..e7824d2 100644 --- a/Tekton/resources/secrets.yaml +++ b/Tekton/resources/secrets.yaml @@ -3,7 +3,6 @@ apiVersion: v1 kind: Secret metadata: name: github-secret - namespace: tekton-pipeline-istio-project-1 stringData: - token: GITHUBSECRETTOKEN + token: SECRETSTRING secret: random-string-data diff --git a/Tekton/runs/task/webhook-backend.yaml b/Tekton/runs/task/webhook-backend.yaml new file mode 100644 index 0000000..36fc88a --- /dev/null +++ b/Tekton/runs/task/webhook-backend.yaml @@ -0,0 +1,27 @@ +--- +# https://medium.com/@nikhilthomas1/cloud-native-cicd-on-openshift-with-openshift-pipelines-tektoncd-pipelines-part-3-github-1db6dd8e8ca7 +apiVersion: tekton.dev/v1alpha1 +kind: TaskRun +metadata: + name: create-repo-webhook-backend +spec: + taskRef: + name: create-webhook + inputs: + params: + - name: GitHubOrg + value: "beppevanrolleghem" + - name: GitHubUser + value: "beppevanrolleghem" + - name: GitHubRepo + value: "stage-backend" + - name: GitHubSecretName + value: webhook-secret + - name: GitHubAccessTokenKey + value: token + - name: GitHubSecretStringKey + value: secret + - name: ExternalDomain + value: "104.155.67.175:8080" + timeout: 1000s + serviceAccountName: service-acc \ No newline at end of file diff --git a/Tekton/runs/task/webhook-frontend.yaml b/Tekton/runs/task/webhook-frontend.yaml new file mode 100644 index 0000000..8e10e43 --- /dev/null +++ b/Tekton/runs/task/webhook-frontend.yaml @@ -0,0 +1,27 @@ +--- +# https://medium.com/@nikhilthomas1/cloud-native-cicd-on-openshift-with-openshift-pipelines-tektoncd-pipelines-part-3-github-1db6dd8e8ca7 +apiVersion: tekton.dev/v1alpha1 +kind: TaskRun +metadata: + name: create-repo-webhook-frontend +spec: + taskRef: + name: create-webhook + inputs: + params: + - name: GitHubOrg + value: "beppevanrolleghem" + - name: GitHubUser + value: "beppevanrolleghem" + - name: GitHubRepo + value: "stage-frontend" + - name: GitHubSecretName + value: webhook-secret + - name: GitHubAccessTokenKey + value: token + - name: GitHubSecretStringKey + value: secret + - name: ExternalDomain + value: "104.155.67.175:8080" + timeout: 1000s + serviceAccountName: service-acc \ No newline at end of file diff --git a/Tekton/runs/task/create-repo-webhook.yaml b/Tekton/runs/task/webhook-infra.yaml similarity index 86% rename from Tekton/runs/task/create-repo-webhook.yaml rename to Tekton/runs/task/webhook-infra.yaml index fbb83bc..ecf09a4 100644 --- a/Tekton/runs/task/create-repo-webhook.yaml +++ b/Tekton/runs/task/webhook-infra.yaml @@ -3,7 +3,7 @@ apiVersion: tekton.dev/v1alpha1 kind: TaskRun metadata: - name: create-repo-webhook + name: create-repo-webhook-infra spec: taskRef: name: create-webhook @@ -14,7 +14,7 @@ spec: - name: GitHubUser value: "beppevanrolleghem" - name: GitHubRepo - value: "cicdTest" + value: "stage-infra" - name: GitHubSecretName value: webhook-secret - name: GitHubAccessTokenKey @@ -22,6 +22,6 @@ spec: - name: GitHubSecretStringKey value: secret - name: ExternalDomain - value: "ingress.llocal.host" + value: "104.155.67.175:8080" timeout: 1000s serviceAccountName: service-acc \ No newline at end of file diff --git a/Tekton/runs/task/webhook-mirror.yaml b/Tekton/runs/task/webhook-mirror.yaml new file mode 100644 index 0000000..5d5d784 --- /dev/null +++ b/Tekton/runs/task/webhook-mirror.yaml @@ -0,0 +1,27 @@ +--- +# https://medium.com/@nikhilthomas1/cloud-native-cicd-on-openshift-with-openshift-pipelines-tektoncd-pipelines-part-3-github-1db6dd8e8ca7 +apiVersion: tekton.dev/v1alpha1 +kind: TaskRun +metadata: + name: create-repo-webhook-mirror +spec: + taskRef: + name: create-webhook + inputs: + params: + - name: GitHubOrg + value: "beppevanrolleghem" + - name: GitHubUser + value: "beppevanrolleghem" + - name: GitHubRepo + value: "stage-mirror-service" + - name: GitHubSecretName + value: webhook-secret + - name: GitHubAccessTokenKey + value: token + - name: GitHubSecretStringKey + value: secret + - name: ExternalDomain + value: "104.155.67.175:8080" + timeout: 1000s + serviceAccountName: service-acc \ No newline at end of file diff --git a/Tekton/tasks/create-webhook.yaml b/Tekton/tasks/create-webhook.yaml index 9fa4f9f..9e46030 100644 --- a/Tekton/tasks/create-webhook.yaml +++ b/Tekton/tasks/create-webhook.yaml @@ -44,7 +44,7 @@ spec: set -e echo "Create Webhook" if [ $(inputs.params.GitHubDomain) = "github.com" ];then - curl -v -d "{\"name\": \"web\",\"active\": true,\"events\": $(inputs.params.WebhookEvents),\"config\": {\"url\": \"https://$(inputs.params.ExternalDomain)\",\"content_type\": \"json\",\"insecure_ssl\": \"1\" ,\"secret\": \"$(cat /var/secret/$(inputs.params.GitHubSecretStringKey))\"}}" -X POST -u $(inputs.params.GitHubUser):$(cat /var/secret/$(inputs.params.GitHubAccessTokenKey)) -L https://api.github.com/repos/$(inputs.params.GitHubOrg)/$(inputs.params.GitHubRepo)/hooks + curl -v -d "{\"name\": \"web\",\"active\": true,\"events\": $(inputs.params.WebhookEvents),\"config\": {\"url\": \"https://$(inputs.params.ExternalDomain)\",\"content_type\": \"json\",\"insecure_ssl\": \"0\" ,\"secret\": \"$(cat /var/secret/$(inputs.params.GitHubSecretStringKey))\"}}" -X POST -u $(inputs.params.GitHubUser):$(cat /var/secret/$(inputs.params.GitHubAccessTokenKey)) -L https://api.github.com/repos/$(inputs.params.GitHubOrg)/$(inputs.params.GitHubRepo)/hooks else curl -d "{\"name\": \"web\",\"active\": true,\"events\": $(inputs.params.WebhookEvents),\"config\": {\"url\": \"https://$(inputs.params.ExternalDomain)/\",\"content_type\": \"json\",\"insecure_ssl\": \"1\" ,\"secret\": \"$(cat /var/secret/$(inputs.params.GitHubSecretStringKey))\"}}" -X POST -u $(inputs.params.GitHubUser):$(cat /var/secret/$(inputs.params.GitHubAccessTokenKey)) -L https://$(inputs.params.GitHubDomain)/api/v3/repos/$(inputs.params.GitHubOrg)/$(inputs.params.GitHubRepo)/hooks fi \ No newline at end of file diff --git a/Tekton/triggers/event-listener.yaml b/Tekton/triggers/event-listener.yaml index 1b342e4..2d80256 100644 --- a/Tekton/triggers/event-listener.yaml +++ b/Tekton/triggers/event-listener.yaml @@ -12,7 +12,6 @@ spec: - name: github-trigger-binding template: name: github-trigger-template - --- apiVersion: v1 kind: Service diff --git a/Tekton/triggers/trigger-binding.yaml b/Tekton/triggers/trigger-binding.yaml index 62791d9..9391766 100644 --- a/Tekton/triggers/trigger-binding.yaml +++ b/Tekton/triggers/trigger-binding.yaml @@ -10,4 +10,6 @@ spec: - name: gitrepositoryurl value: $(body.repository.clone_url) - name: gitreponame - value: $(body.repository.name) \ No newline at end of file + value: $(body.repository.name) + - name: pipelinename + value: "pipeline for commit $(body.)" \ No newline at end of file diff --git a/Tekton/triggers/trigger-template.yaml b/Tekton/triggers/trigger-template.yaml index 58ce84b..97156c3 100644 --- a/Tekton/triggers/trigger-template.yaml +++ b/Tekton/triggers/trigger-template.yaml @@ -12,11 +12,13 @@ spec: description: The git repository url - name: gitreponame description: the name of the git repository + - name: pipelinename + description: name the pipelinerun will have resourcetemplates: - apiVersion: tekton.dev/v1alpha1 kind: PipelineRun metadata: - name: application-pipeline-run + name: $(inputs.params.pipelinename) spec: serviceAccountName: service-acc pipelineRef: