Browse Source

add tekton listener

pull/1/head
Nicolas Massé 2 years ago
parent
commit
864c56910b
  1. 14
      README.md
  2. 4
      infrastructure/templates/_helpers.tpl
  3. 182
      infrastructure/templates/eshop-dev.yaml

14
README.md

@ -31,3 +31,17 @@ oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:opens
cp infrastructure.yaml.sample infrastructure.yaml cp infrastructure.yaml.sample infrastructure.yaml
oc apply -f infrastructure.yaml -n openshift-gitops oc apply -f infrastructure.yaml -n openshift-gitops
``` ```
* Print the relevant information to create the webhook.
```sh
oc get route -n eshop-dev el-eshoponweb -o go-template='https://{{.spec.host}}/{{"\n"}}'
oc get secret -n eshop-dev github-webbook-secret -o go-template --template='{{.data.secretToken|base64decode}}{{"\n"}}'
```
* Add a webhook on the **eShopOnWeb** GitHub repository.
* Payload URL: *url above*
* Content-Type: Application/json
* Secret: *secret printed above*

4
infrastructure/templates/_helpers.tpl

@ -3,3 +3,7 @@
{{- define "acs-admin-password" -}} {{- define "acs-admin-password" -}}
{{- trunc 16 (sha256sum (cat .Values.masterKey "acs-admin-password")) -}} {{- trunc 16 (sha256sum (cat .Values.masterKey "acs-admin-password")) -}}
{{- end -}} {{- end -}}
{{- define "github-tekton-webhook-secret" -}}
{{- trunc 32 (sha256sum (cat .Values.masterKey "github-tekton-webhook-secret")) -}}
{{- end -}}

182
infrastructure/templates/eshop-dev.yaml

@ -7,6 +7,8 @@ metadata:
openshift.io/display-name: "" openshift.io/display-name: ""
labels: labels:
kubernetes.io/metadata.name: eshop-dev kubernetes.io/metadata.name: eshop-dev
# Enable HTTPS on Tekton EventListeners
operator.tekton.dev/enable-annotation: disabled
name: eshop-dev name: eshop-dev
spec: spec:
finalizers: finalizers:
@ -131,7 +133,7 @@ metadata:
annotations: annotations:
argocd.argoproj.io/sync-wave: "20" argocd.argoproj.io/sync-wave: "20"
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
name: eshoponweb-ci name: eshop-ci
namespace: eshop-dev namespace: eshop-dev
spec: spec:
params: params:
@ -217,7 +219,7 @@ metadata:
annotations: annotations:
argocd.argoproj.io/sync-wave: "20" argocd.argoproj.io/sync-wave: "20"
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
name: eshoponweb-cd name: eshop-cd
namespace: eshop-dev namespace: eshop-dev
spec: spec:
params: params:
@ -272,3 +274,179 @@ spec:
kind: ClusterTask kind: ClusterTask
name: openshift-client name: openshift-client
--- ---
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
annotations:
argocd.argoproj.io/sync-wave: "20"
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
name: eshoponweb
namespace: eshop-dev
spec:
serviceAccountName: pipeline
triggers:
- triggerRef: eshop-web
- triggerRef: eshop-api
---
apiVersion: triggers.tekton.dev/v1beta1
kind: Trigger
metadata:
annotations:
argocd.argoproj.io/sync-wave: "20"
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
name: eshop-web
namespace: eshop-dev
spec:
serviceAccountName: pipeline
interceptors:
- name: GitHub push events
ref:
name: "github"
params:
- name: "secretRef"
value:
secretName: github-webbook-secret
secretKey: secretToken
- name: "eventTypes"
value: ["push"]
- name: Filter on repository name
ref:
name: "cel"
kind: ClusterInterceptor
apiVersion: triggers.tekton.dev
params:
- name: filter
value: body.repository.full_name == 'eShopOnWeb-OpenShift/eShopOnWeb'
bindings:
- name: NAME
value: web
- name: GIT_REPO
value: $(body.repository.clone_url)
- name: GIT_REVISION
value: $(body.head_commit.id)
- name: IMAGE_NAME
value: image-registry.openshift-image-registry.svc:5000/eshop-dev/eshop-web
- name: DOTNET_STARTUP_PROJECT
value: src/Web/Web.csproj
template:
ref: eshoponweb
---
apiVersion: triggers.tekton.dev/v1beta1
kind: Trigger
metadata:
annotations:
argocd.argoproj.io/sync-wave: "20"
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
name: eshop-api
namespace: eshop-dev
spec:
serviceAccountName: pipeline
interceptors:
- name: GitHub push events
ref:
name: "github"
params:
- name: "secretRef"
value:
secretName: github-webbook-secret
secretKey: secretToken
- name: "eventTypes"
value: ["push"]
- name: Filter on repository name
ref:
name: "cel"
kind: ClusterInterceptor
apiVersion: triggers.tekton.dev
params:
- name: filter
value: body.repository.full_name == 'eShopOnWeb-OpenShift/eShopOnWeb'
bindings:
- name: NAME
value: api
- name: GIT_REPO
value: $(body.repository.clone_url)
- name: GIT_REVISION
value: $(body.head_commit.id)
- name: IMAGE_NAME
value: image-registry.openshift-image-registry.svc:5000/eshop-dev/eshop-api
- name: DOTNET_STARTUP_PROJECT
value: src/PublicApi/PublicApi.csproj
template:
ref: eshoponweb
---
apiVersion: v1
kind: Secret
metadata:
annotations:
argocd.argoproj.io/sync-wave: "20"
name: github-webbook-secret
namespace: eshop-dev
type: Opaque
data:
secretToken: {{ include "github-tekton-webhook-secret" . | b64enc | quote }}
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
annotations:
argocd.argoproj.io/sync-wave: "20"
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
name: eshoponweb
namespace: eshop-dev
spec:
params:
- name: NAME
- name: GIT_REPO
- name: GIT_REVISION
- name: IMAGE_NAME
- name: DOTNET_STARTUP_PROJECT
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
argocd.argoproj.io/sync-options: Prune=false
generateName: eshop-ci-$(tt.params.NAME)-
spec:
serviceAccountName: pipeline
pipelineRef:
name: eshop-ci
params:
- name: GIT_REPO
value: $(tt.params.GIT_REPO)
- name: GIT_REVISION
value: $(tt.params.GIT_REVISION)
- name: IMAGE_NAME
value: $(tt.params.IMAGE_NAME)
- name: DOTNET_STARTUP_PROJECT
value: $(tt.params.DOTNET_STARTUP_PROJECT)
workspaces:
- name: workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
---
kind: Route
apiVersion: route.openshift.io/v1
metadata:
annotations:
argocd.argoproj.io/sync-wave: "20"
name: el-eshoponweb
namespace: eshop-dev
labels:
app.kubernetes.io/managed-by: EventListener
app.kubernetes.io/part-of: Triggers
eventlistener: eshoponweb
spec:
to:
kind: Service
name: el-eshoponweb
tls:
termination: edge
insecureEdgeTerminationPolicy: Redirect
port:
targetPort: http-listener

Loading…
Cancel
Save