Skip to content

Instantly share code, notes, and snippets.

@AnthonyAmanse
Last active April 14, 2020 06:54
Show Gist options
  • Save AnthonyAmanse/48a6ebe25da1787199e7129fd15c03c6 to your computer and use it in GitHub Desktop.
Save AnthonyAmanse/48a6ebe25da1787199e7129fd15c03c6 to your computer and use it in GitHub Desktop.
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: pixel-build-and-deploy
spec:
params:
- name: NAMESPACE
description: The namespace is used by OpenShift's internal image registry to store the built image.
- name: DEPLOYMENT
description: Name of the Deployment and the container name in the Deployment.
- name: SERVICE_ACCOUNT
description: The ServiceAccount under which to run the Pipeline.
- name: COMMIT_SHA
description: Head commit sha
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
generateName: pixel-build-and-deploy-
spec:
serviceAccountName: $(params.SERVICE_ACCOUNT)
pipelineRef:
name: pixel-pipeline
resources:
- name: source-repo
resourceRef:
name: pixel-git
- name: image-name
resourceSpec:
type: image
params:
- name: url
value: image-registry.openshift-image-registry.svc:5000/pixel/pixel-backend:$(params.COMMIT_SHA)
params:
- name: DEPLOYMENT
value: $(params.DEPLOYMENT)
workspaces:
- name: local-maven-repo
persistentVolumeClaim:
claimName: maven-repo-pvc2
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: pixel-build-and-deploy
spec:
params:
- name: NAMESPACE
value: default
- name: DEPLOYMENT
value: pixel-backend
- name: SERVICE_ACCOUNT
value: pipeline
- name: COMMIT_SHA
value: $(body.head_commit.id)
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pixel
rules:
# Permissions for every EventListener deployment to function
- apiGroups: ["triggers.tekton.dev"]
resources: ["eventlisteners", "triggerbindings", "triggertemplates"]
verbs: ["get"]
- apiGroups: [""]
# secrets are only needed for Github/Gitlab interceptors, serviceaccounts only for per trigger authorization
resources: ["configmaps", "secrets", "serviceaccounts"]
verbs: ["get", "list", "watch"]
# Permissions to create resources in associated TriggerTemplates
- apiGroups: ["tekton.dev"]
resources: ["pipelineruns", "pipelineresources", "taskruns"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pixel
namespace: pixel
subjects:
- kind: ServiceAccount
name: pipeline
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pixel
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
name: pixel
spec:
serviceAccountName: pipeline
triggers:
- name: pullrequest-build-and-deploy
interceptors:
- github:
secretRef:
secretName: github-webhook-secret
secretKey: github-webhook-secret
eventTypes:
- push
template:
name: pixel-build-and-deploy
bindings:
- name: pixel-build-and-deploy
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
eventlistener: pixel
name: el-pixel
spec:
port:
targetPort: http-listener
to:
kind: Service
name: el-pixel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment