From 72be76f1180b30300418582768169e49e8fc921d Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Thu, 29 Apr 2021 13:57:58 +0100 Subject: [PATCH] Deploy the tekton catalog nightly to gcr.io Create a pipeline to deploy the catalog to gcr.io. Add a new trigger/template to the CD event listener, and set up a cronjob to trigger nightly. Fixes: https://github.com/tektoncd/catalog/issues/577 Signed-off-by: Andrea Frittoli --- tekton/cronjobs/bases/catalog/README.md | 1 + .../cronjobs/bases/catalog/kustomization.yaml | 2 + .../bases/catalog/trigger-resource-cd.yaml | 67 ++++++++ .../dogfooding/catalog/kustomization.yaml | 2 + .../catalog/tekton-upstream/README.md | 4 + .../catalog/tekton-upstream/cronjob.yaml | 24 +++ .../tekton-upstream/kustomization.yaml | 5 + .../dogfooding/cleanup/kustomization.yaml | 2 +- tekton/cronjobs/dogfooding/kustomization.yaml | 1 + tekton/resources/cd/catalog-template.yaml | 161 ++++++++++++++++++ tekton/resources/cd/eventlistener.yaml | 16 ++ tekton/resources/cd/kustomization.yaml | 1 + 12 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 tekton/cronjobs/bases/catalog/README.md create mode 100644 tekton/cronjobs/bases/catalog/kustomization.yaml create mode 100644 tekton/cronjobs/bases/catalog/trigger-resource-cd.yaml create mode 100644 tekton/cronjobs/dogfooding/catalog/kustomization.yaml create mode 100644 tekton/cronjobs/dogfooding/catalog/tekton-upstream/README.md create mode 100644 tekton/cronjobs/dogfooding/catalog/tekton-upstream/cronjob.yaml create mode 100644 tekton/cronjobs/dogfooding/catalog/tekton-upstream/kustomization.yaml create mode 100644 tekton/resources/cd/catalog-template.yaml diff --git a/tekton/cronjobs/bases/catalog/README.md b/tekton/cronjobs/bases/catalog/README.md new file mode 100644 index 0000000000..1e09b6ff11 --- /dev/null +++ b/tekton/cronjobs/bases/catalog/README.md @@ -0,0 +1 @@ +Cron Job template to deploy a catalog from a git repo to a container registry diff --git a/tekton/cronjobs/bases/catalog/kustomization.yaml b/tekton/cronjobs/bases/catalog/kustomization.yaml new file mode 100644 index 0000000000..0571151fa1 --- /dev/null +++ b/tekton/cronjobs/bases/catalog/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- trigger-resource-cd.yaml diff --git a/tekton/cronjobs/bases/catalog/trigger-resource-cd.yaml b/tekton/cronjobs/bases/catalog/trigger-resource-cd.yaml new file mode 100644 index 0000000000..e3665b0fa2 --- /dev/null +++ b/tekton/cronjobs/bases/catalog/trigger-resource-cd.yaml @@ -0,0 +1,67 @@ +# Copyright 2019 The Tekton Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + name: catalog-publish-trigger +spec: + schedule: "12 * * * *" # Houly at *:12 + jobTemplate: + spec: + template: + spec: + volumes: + - name: workspace + emptyDir: {} + containers: + - name: trigger + image: curlimages/curl + command: + - /bin/sh + args: + - -ce + - | + curl -v -d @- "$SINK_URL" < "${DOCKER_CONFIG_FOLDER}/config.json" + { + "auths": { + "$REGISTRY": { + "auth": "$(echo "_json_key:$(cat ${SERVICE_ACCOUNT_FILE})" | base64 -w 0)" + } + } + } + EOF + params: + - name: serviceAccountFilename + value: "$(params.serviceAccountFilename)" + - name: registry + value: "$(params.registry)" + workspaces: + - name: serviceaccount + workspace: serviceaccount + - name: dockerfile + workspace: shared + - name: publish + runAfter: ['create-dockerfile'] + workspaces: + - name: catalog + workspace: shared + - name: dockerconfig + workspace: shared + params: + - name: REGISTRY + value: "$(params.registry)" + - name: PATH + value: "$(params.registryPath)" + - name: TAG + value: "$(tasks.git-clone.results.commit)" + taskRef: + name: tekton-catalog-publish +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerTemplate +metadata: + name: publish-catalog +spec: + params: + - name: gitRepository + description: URL of the repository that holds the catalog + - name: gitRevision + description: Git revision + - name: registry + description: The registry to publish to + - name: registryPath + description: The base path in the registry + - name: catalogDescription + description: A descriptive name for the catalog + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: publish-catalog-$(tt.params.catalogDescription)- + spec: + pipelineRef: + name: catalog-publish + params: + - name: gitRepository + value: "$(tt.params.gitRepository)" + - name: gitRevision + value: "$(tt.params.gitRevision)" + - name: registry + value: "$(tt.params.registry)" + - name: registryPath + value: "$(tt.params.registryPath)" + - name: serviceAccountFilename + value: "release.json" + workspaces: + - name: shared + volumeClaimTemplate: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + - name: serviceaccount + secret: + secretName: "release-secret" diff --git a/tekton/resources/cd/eventlistener.yaml b/tekton/resources/cd/eventlistener.yaml index 8e350bc857..fc5ccc05d6 100644 --- a/tekton/resources/cd/eventlistener.yaml +++ b/tekton/resources/cd/eventlistener.yaml @@ -76,6 +76,22 @@ spec: - ref: cleanup-details template: ref: cleanup-runs + - name: catalog + interceptors: + - cel: + filter: >- + 'trigger-template' in body && + body['trigger-template'] == 'catalog' + bindings: + - ref: deploy-source-git + - name: registry + value: "$(body.params.catalog.registry)" + - name: registryPath + value: "$(body.params.catalog.registryPath)" + - name: catalogDescription + value: "$(body.params.catalog.description)" + template: + ref: publish-catalog --- apiVersion: triggers.tekton.dev/v1alpha1 kind: EventListener diff --git a/tekton/resources/cd/kustomization.yaml b/tekton/resources/cd/kustomization.yaml index e9e6581289..b06367c02c 100644 --- a/tekton/resources/cd/kustomization.yaml +++ b/tekton/resources/cd/kustomization.yaml @@ -25,4 +25,5 @@ resources: - tekton-template.yaml - cleanup-template.yaml - notification-template.yaml +- catalog-template.yaml - serviceaccount.yaml \ No newline at end of file