Skip to content

Commit

Permalink
Deploy the tekton catalog nightly to gcr.io
Browse files Browse the repository at this point in the history
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: tektoncd/catalog#577

Signed-off-by: Andrea Frittoli <[email protected]>
  • Loading branch information
afrittoli committed May 4, 2021
1 parent 5e01511 commit 2d7807c
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 1 deletion.
1 change: 1 addition & 0 deletions tekton/cronjobs/bases/catalog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cron Job template to deploy a catalog from a git repo to a container registry
2 changes: 2 additions & 0 deletions tekton/cronjobs/bases/catalog/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- trigger-resource-cd.yaml
68 changes: 68 additions & 0 deletions tekton/cronjobs/bases/catalog/trigger-resource-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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
- |
cat <<EOF > /workspace/post-body.json
{
"trigger-template": "catalog",
"params": {
"git": {
"repository": "$GIT_REPOSITORY",
"revision": "$GIT_REVISION"
},
"catalog": {
"registry": "$REGISTRY_URL",
"registryPath": "$REGISTRY_PATH",
"description": "$CATALOG_DESCRIPTION"
}
}
}
EOF
curl -d @/workspace/post-body.json $SINK_URL
volumeMounts:
- mountPath: /workspace
name: workspace
env:
- name: SINK_URL
value: "http://el-tekton-cd.default.svc.cluster.local:8080"
- name: GIT_REPOSITORY
value: "github.com/tektoncd/catalog"
- name: GIT_REVISION
value: "main"
- name: REGISTRY_URL
value: "replace"
- name: REGISTRY_PATH
value: "replace"
- name: CATALOG_DESCRIPTION
value: "tekton"
restartPolicy: Never
4 changes: 4 additions & 0 deletions tekton/cronjobs/dogfooding/catalog/tekton-upstream/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Tekton Catalog CD - gcr.io/tekton-releases

Cron Job to daily deploy the Tekton catalog to the
gcr.io/tekton-releases container registry project as bundles.
24 changes: 24 additions & 0 deletions tekton/cronjobs/dogfooding/catalog/tekton-upstream/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: catalog-publish-trigger
spec:
schedule: "30 * * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: trigger
env:
- name: GIT_REPOSITORY
value: "https://github.com/tektoncd/catalog"
- name: GIT_REVISION
value: "main"
- name: REGISTRY_URL
value: "gcr.io"
- name: REGISTRY_PATH
value: "tekton-releases/catalog/upstream"
- name: CATALOG_DESCRIPTION
value: "tekton"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bases:
- ../../../bases/catalog
patchesStrategicMerge:
- cronjob.yaml
nameSuffix: "-tekton-upstream"
2 changes: 1 addition & 1 deletion tekton/cronjobs/dogfooding/cleanup/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ resources:
- bastion-z-nightly
- tekton-ci-nightly
- tekton-nightly-nightly
- bastion-p-nightly
- bastion-p-nightly
1 change: 1 addition & 0 deletions tekton/cronjobs/dogfooding/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ resources:
- releases
- tekton
- nightly-tests
- catalog
161 changes: 161 additions & 0 deletions tekton/resources/cd/catalog-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Copyright 2021 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: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: catalog-publish
spec:
params:
- name: gitRepository
description: The git URL of the catalog to publish
type: string
default: https://github.com/tektoncd/catalog
- name: gitRevision
description: The git revision of the catalog to publish
type: string
default: main
- name: registry
description: The registry to publish to
type: string
- name: registryPath
description: The base path in the registry
type: string
- name: serviceAccountFilename
description: The name of the GKE service account file on the serviceaccount workspace
type: string
workspaces:
- name: shared
description: Shared workspace for tasks
- name: serviceaccount
description: Hosts a GKE service account file
tasks:
- name: git-clone
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared
params:
- name: url
value: "$(params.gitRepository)"
- name: revision
value: "$(params.gitRevision)"
- name: create-dockerfile
runAfter: ['git-clone']
taskSpec:
workspaces:
- name: serviceaccount
- name: dockerfile
params:
- name: serviceAccountFilename
- name: registry
steps:
- name: gke-serviceaccount-to-dockerfile
image: debian:bullseye-slim
env:
- name: DOCKER_CONFIG_FOLDER
value: $(workspaces.dockerfile.path)
- name: SERVICE_ACCOUNT_FILE
value: $(workspaces.serviceaccount.path)/$(params.serviceAccountFilename)
- name: REGISTRY
value: $(params.registry)
script: |
set -e
# This step transforms sensitive information
# Make sure we don't write it to the logs
set +x
cat <<EOF > "${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"
16 changes: 16 additions & 0 deletions tekton/resources/cd/eventlistener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tekton/resources/cd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ resources:
- tekton-template.yaml
- cleanup-template.yaml
- notification-template.yaml
- catalog-template.yaml
- serviceaccount.yaml

0 comments on commit 2d7807c

Please sign in to comment.