From c3c152bc1ad5dfa27ad015194c90b44ba33e22d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Wed, 17 Apr 2024 12:00:00 +0000 Subject: [PATCH] ci: Add scheduled eventlistener MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- .tekton/scheduled-eventlistener.yaml | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 .tekton/scheduled-eventlistener.yaml diff --git a/.tekton/scheduled-eventlistener.yaml b/.tekton/scheduled-eventlistener.yaml new file mode 100644 index 00000000..b3bcedbf --- /dev/null +++ b/.tekton/scheduled-eventlistener.yaml @@ -0,0 +1,108 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: ruby-tracer-scheduled-ci-pipeline-template +spec: + params: + - description: The ISO-8601 date and time converted to RFC 1123 subdomain names + name: date-time-normalized + - description: The full sha of the git commit + name: git-commit-sha + - description: The short 7 digit sha of the git commit + name: git-commit-short-sha + resourcetemplates: + - apiVersion: tekton.dev/v1 + kind: PipelineRun + metadata: + # After variable resolution, this has to be maximum 63 character long, + # lower case, RFC 1123 subdomain name. The regex used for validation is + # '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' + name: ruby-tracer-scheduled-ci-pipeline-$(tt.params.date-time-normalized)-$(tt.params.git-commit-short-sha) + spec: + params: + - name: revision + value: master + - name: git-commit-sha + value: $(tt.params.git-commit-sha) + pipelineRef: + name: github-pr-ruby-tracer-ci-pipeline + workspaces: + - name: ruby-tracer-ci-pipeline-pvc + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +--- +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerBinding +metadata: + name: ruby-tracer-scheduled-binding +spec: + params: + - name: date-time-normalized + value: $(extensions.normalized_date_time) + - name: git-commit-sha + value: $(body.git_master_head_commit_sha) + - name: git-commit-short-sha + value: $(extensions.truncated_sha) +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: ruby-tracer-scheduled-ci-cronjob +spec: + schedule: "5 1 * * Mon-Fri" + jobTemplate: + spec: + template: + spec: + containers: + - name: git + # alpine/git:2.43.0 + image: alpine/git@sha256:6ff4de047dcc8f0c7d75d2efff63fbc189e87d2f458305f2cc8f165ff83309cf + command: + - sh + - -c + - | + wget -O- \ + --header 'Content-Type: application/json' \ + --post-data '{ + "git_master_head_commit_sha":"'"$(git ls-remote https://github.com/instana/ruby-sensor master | cut -f1)"'", + "date_time":"'"$(date -u -Iminutes )"'" + }' \ + 'http://el-ruby-tracer-scheduled-pipeline-listener.default.svc.cluster.local:8080' + restartPolicy: OnFailure +--- +apiVersion: triggers.tekton.dev/v1beta1 +kind: EventListener +metadata: + name: ruby-tracer-scheduled-pipeline-listener +spec: + serviceAccountName: tekton-triggers-eventlistener-serviceaccount + triggers: + - name: ruby-tracer-scheduled-pipeline-triggger + interceptors: + - name: add-truncated-sha + ref: + name: "cel" + params: + - name: "overlays" + value: + - key: truncated_sha + expression: "body.git_master_head_commit_sha.truncate(7)" + - name: add-normalized-date-time + ref: + name: "cel" + params: + - name: "overlays" + value: + - key: normalized_date_time + # The date-time converted to RFC 1123 subdomain names + expression: 'body.date_time.split("+")[0].lowerAscii().translate(":", "-")' + bindings: + - ref: ruby-tracer-scheduled-binding + template: + ref: ruby-tracer-scheduled-ci-pipeline-template