mmmmmmmmmmmmm, denk dak het heb deze keer

This commit is contained in:
2020-03-20 00:08:32 +01:00
parent 68e5e79439
commit 42f3e849ee
17 changed files with 191 additions and 396 deletions

View File

@@ -1,7 +1,7 @@
apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
name: is-not-equal
name: is-equal
namespace: tekton-pipeline-1
spec:
params:
@@ -15,8 +15,8 @@ spec:
#!/bin/sh
if [ $(params.left) = $(params.right) ]; then
echo "$(params.left) == $(params.right)"
exit 1
exit 0
else
echo "$(params.left) != $(params.right)"
exit 0
exit 1
fi

View File

@@ -0,0 +1,22 @@
apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
name: is-not-equal
namespace: tekton-pipeline-1
spec:
params:
- name: left
type: string
- name: right
type: string
check:
image: alpine
script: |
#!/bin/sh
if [ $(params.left) = $(params.right) ]; then
echo "$(params.left) == $(params.right)"
exit 1
else
echo "$(params.left) != $(params.right)"
exit 0
fi

View File

@@ -2,12 +2,10 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: stage-application-pipeline
name: application-pipeline
namespace: tekton-pipeline-1
spec:
params:
- name: git-repo-full-name
description: full name of the github repo (used for status updates)
- name: git-repo-name
description: name of the git repo (used to determine the name of the image)
- name: git-url
@@ -15,12 +13,16 @@ spec:
- name: revision
description: revision to checkout
- name: branch
description: name of the branch to checkout
description: name of the master branch of the repository
- name: git-repo-full-name
description: full name of the github repo (used for status updates)
workspaces:
- name: workspace
tasks:
- name: clone
taskRef:
taskRef:
name: git-clone
workspaces:
- name: output
@@ -31,8 +33,7 @@ spec:
- name: revision
value: $(params.revision)
- name: set-begun-status
- name: set-status-build-and-push
taskRef:
name: github-set-status
runAfter:
@@ -42,50 +43,67 @@ spec:
value: $(params.git-repo-full-name)
- name: SHA
value: $(params.revision)
- name: TARGET_URL
value: tekton.llocal.host/dashboard
- name: STATE
value: pending
- name: TARGET_URL
value: http://tekton.llocal.host/dashboard
- name: DESCRIPTION
value: "Build of maven file has started"
value: "Build and push has started"
- name: build-and-push-maven
- name: build-and-push
taskRef:
name: build-maven
name: build-and-push
runAfter:
- clone
params:
- name: image-name
value: $(params.git-repo-name)
- name: image-tag
value: $(params.branch)
Timeout: "1h30m00s"
workspaces:
- name: source
workspace: workspace
params:
- name: context
value: "src"
- name: image-name
value: "$(params.git-repo-name)"
- name: version
value: "$(params.branch)"
- name: set-build-finshed-status
- name: set-status-deploy
taskRef:
name: github-set-status
runAfter:
- build-and-push-maven
- build-and-push
params:
- name: REPO_FULL_NAME
value: $(params.git-repo-full-name)
- name: SHA
value: $(params.revision)
- name: TARGET_URL
value: tekton.llocal.host/dashboard
- name: STATE
value: pending
value: $(tasks.build-and-push.results.state)
- name: TARGET_URL
value: http://ingress.llocal.host/$(params.git-repo-name)
- name: DESCRIPTION
value: "build and push has finished, now starting deployment"
value: $(tasks.build-and-push.results.description)
- name: deploy-app
taskRef:
name: deploy-app
name: deploy-yaml-file
runAfter:
- build-and-push-maven
- build-and-push
conditions:
- conditionRef: is-not-equal
params:
- name: left
value: "error"
- name: right
value: "$(tasks.build-and-push.results.state)"
- conditionRef: is-not-equal
params:
- name: left
value: "failure"
- name: right
value: "$(tasks.build-and-push.results.state)"
workspaces:
- name: source
workspace: workspace
@@ -94,8 +112,9 @@ spec:
value: "$(params.git-repo-name)"
- name: deploy-version
value: "$(params.branch)"
- name: set-deploy-finished-status
- name: set-status-finished
taskRef:
name: github-set-status
runAfter:
@@ -105,9 +124,9 @@ spec:
value: $(params.git-repo-full-name)
- name: SHA
value: $(params.revision)
- name: TARGET_URL
value: tekton.llocal.host/dashboard
- name: STATE
value: success
value: $(tasks.deploy-app.results.state)
- name: TARGET_URL
value: http://tekton.llocal.host/$(params.git-repo-name)
- name: DESCRIPTION
value: "deploy finished"
value: "$(tasks.deploy-app.results.description)"

View File

@@ -2,7 +2,7 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: infra-pipeline
name: infrastructure-pipeline
namespace: tekton-pipeline-1
spec:
params:
@@ -51,7 +51,7 @@ spec:
- name: deploy-infrastructure
taskRef:
name: deploy-app
name: deploy-to-cluster
runAfter:
- clone-git-repo
workspaces:
@@ -61,7 +61,7 @@ spec:
- name: yaml-location
value: infra/
conditions:
- conditionRef: "is-not-equal"
- conditionRef: "is-equal"
params:
- name: "left"
value: "master"

View File

@@ -1,125 +0,0 @@
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: stage-application-pipeline
namespace: tekton-pipeline-1
spec:
params:
- name: git-repo-name
description: name of the git repo (used to determine the name of the image)
- name: git-url
description: url of the git repository to clone
- name: revision
description: revision to checkout
- name: branch
description: name of the master branch of the repository
- name: git-repo-full-name
description: full name of the github repo (used for status updates)
- name: sha
description: used for github status updates
workspaces:
- name: workspace
tasks:
- name: clone
taskRef:
name: git-clone
workspaces:
- name: output
workspace: workspace
params:
- name: url
value: $(params.git-url)
- name: revision
value: $(params.revision)
# - name: set-status-building
# taskRef:
# name: github-set-status
# runAfter:
# - clone
# params:
# - name: REPO_FULL_NAME
# value: $(params.git-repo-full-name)
# - name: SHA
# value: $(params.sha)
# - name: STATE
# value: pending
# - name: TARGET_URL
# value: http://ingress.llocal.host/$(params.git-repo-name)
# - name: DESCRIPTION
# value: "Build and push has started"
- name: build-and-push
taskRef:
name: build-and-push
conditions:
- conditionRef: "is-not-equal"
params:
- name: "left"
value: "stage-infra"
- name: "right"
value: "$(params.git-repo-name)"
runAfter:
- clone
Timeout: "1h30m00s"
workspaces:
- name: source
workspace: workspace
params:
- name: context
value: "src"
- name: image-name
value: "$(params.git-repo-name)"
- name: version
value: "$(params.branch)"
# - name: set-status-building
# taskRef:
# name: github-set-status
# runAfter:
# - build-and-push
# params:
# - name: REPO_FULL_NAME
# value: $(params.git-repo-full-name)
# - name: SHA
# value: $(params.sha)
# - name: STATE
# value: pending
# - name: TARGET_URL
# value: http://ingress.llocal.host/$(params.git-repo-name)
# - name: DESCRIPTION
# value: "Build and push has completed, starting deploy-app"
- name: deploy-app
taskRef:
name: deploy-app
runAfter:
- build-and-push
workspaces:
- name: source
workspace: workspace
params:
- name: deploy-name
value: "$(params.git-repo-name)"
- name: deploy-version
value: "$(params.branch)"
- name: set-status-building
taskRef:
name: github-set-status
runAfter:
- deploy-app
params:
- name: REPO_FULL_NAME
value: $(params.git-repo-full-name)
- name: SHA
value: $(params.sha)
- name: STATE
value: success
- name: TARGET_URL
value: http://tekton.llocal.host/$(params.git-repo-name)
- name: DESCRIPTION
value: "Deploy finished"

View File

@@ -25,10 +25,17 @@ spec:
env:
- name: "DOCKER_CONFIG"
value: "/tekton/home/.docker/"
command:
- /kaniko/executor
args:
- "--dockerfile=/source/$(params.context)/dockerfile"
- "--destination=beppev/$(params.image-name):$(params.version)"
- "--context=/source/$(params.context)/"
- "--skip-tls-verify" #for speed reasons
script: |
#!/usr/bin/env bash
/kaniko/executor \
--dockerfile=/source/$(params.context)/dockerfile \
--destination=beppev/$(params.image-name):$(params.version) \
--context=/source/$(params.context)/ --skip-tls-verify
if [ "$?" = 0 ]; then
echo "pending" | tee /tekton/results/state
echo "build and push successful" | tee /tekton/results/description
else
echo "failure" | tee /tekton/results/state
echo "build and push were not successful use kubectl or tkn or tekton dashboard to see logs" | tee /tekton/results/description
fi
exit 0

View File

@@ -1,39 +1,35 @@
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: jib-gradle
name: build-gradle
namespace: tekton-pipeline-1
spec:
inputs:
params:
- name: build-type
description: build type used to check to actually execute this step
default: gradle
- name: DIRECTORY
description: The directory containing the app, relative to the source repository root
default: .
- name: CACHE
description: The name of the volume for caching Gradle artifacts, local Maven repository, and base image layers
default: empty-dir-volume
- name: INSECUREREGISTRY
description: Whether to allow insecure registry
default: "false"
resources:
params:
- name: build-type
description: build type used to check to actually execute this step
default: gradle
- name: DIRECTORY
description: The directory containing the app, relative to the source repository root
default: .
- name: CACHE
description: The name of the volume for caching Gradle artifacts, local Maven repository, and base image layers
default: empty-dir-volume
- name: INSECUREREGISTRY
description: Whether to allow insecure registry
default: "false"
- name: image-name
description: name of the image after push
- name: image-tag
description: tag of the image after push
workspaces:
- name: source
type: git
outputs:
resources:
- name: image
type: image
mountPath: /source
steps:
- name: build-and-push
image: gcr.io/cloud-builders/gradle
script: |
#!/bin/sh
if [ $(inputs.params.build-type) != gradle]
then
exit 0
fi
cd /source
set -o errexit
# Adds Gradle init script that applies the Jib Gradle plugin.
echo "initscript {
@@ -53,21 +49,25 @@ spec:
--init-script=/tekton/home/init-script.gradle \
-Duser.home=/tekton/home \
-Dgradle.user.home=/tekton/home/.gradle \
-Djib.allowInsecureRegistries=$(inputs.params.INSECUREREGISTRY) \
-Djib.to.image=$(outputs.resources.image.url)
-Djib.allowInsecureRegistries=$(params.INSECUREREGISTRY) \
-Djib.to.image=docker.io/beppev/$(params.image-name):$(params.image-tag) \
-Djib.from.auth.username=beppev
-Djib.from.auth.password=Azerty123
-Djib.to.auth.username=beppev
-Djib.to.auth.password=Azerty123
exit 0
workingDir: /workspace/source/$(inputs.params.DIRECTORY)
workingDir: /workspace/source/$(params.DIRECTORY)
volumeMounts:
- name: $(inputs.params.CACHE)
- name: $(params.CACHE)
mountPath: /tekton/home/.gradle/caches
subPath: gradle-caches
- name: $(inputs.params.CACHE)
- name: $(params.CACHE)
mountPath: /tekton/home/.gradle/wrapper
subPath: gradle-wrapper
- name: $(inputs.params.CACHE)
- name: $(params.CACHE)
mountPath: /tekton/home/.m2
subPath: m2-cache
- name: $(inputs.params.CACHE)
- name: $(params.CACHE)
mountPath: /tekton/home/.cache
subPath: jib-cache
securityContext:

View File

@@ -3,7 +3,7 @@
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: deploy-app
name: deploy-yaml-file
namespace: tekton-pipeline-1
spec:
params:
@@ -19,15 +19,27 @@ spec:
- name: source
mountpath: /source
steps:
- name: update-yaml
image: alpine
script: |
sed -i -e 's;DEPLOY_NAME;$(params.deploy-name);g' /source/$(params.yaml-location)
sed -i -e 's;DEPLOY_VERSION;$(params.deploy-version);g' /source/$(params.yaml-location)
- name: deploy-new-app
image: lachlanevenson/k8s-kubectl
command: ["kubectl"]
args:
- "$(params.command)"
- "-f"
- "/source/$(params.yaml-location)"
script: |
sed -i -e 's;DEPLOY_NAME;$(params.deploy-name);g' /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
echo "failure" | tee /tekton/results/state
echo "replacing deploy name in yaml file failed, please check if the yaml file is in the correct location ($(params.yaml-location))" | tee /tekton/results/description
exit 0
fi
sed -i -e 's;DEPLOY_VERSION;$(params.deploy-version);g' /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
echo "failure" | tee /tekton/results/state
echo "replacing deploy version in yaml file failed, please check if the yaml file is in the correct location ($(params.yaml-location))" | tee /tekton/results/description
exit 0
fi
kubectl $(params.command) -f /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
echo "failure" | tee /tekton/results/state
echo "failure applying yaml file to cluster ($(params.yaml-location))" | tee /tekton/results/description
else
echo "success" | tee /tekton/results/state
echo "deployed the yaml files to the cluster"
fi
exit 0

View File

@@ -0,0 +1,28 @@
---
apiVersion: tekton.dev/v1alpha1
kind: Task #this can be used to deploy a folder aswell as a file, but no replacing the names or versions
metadata:
name: deploy-to-cluster
namespace: tekton-pipeline-1
spec:
params:
- name: yaml-location
default: infra/
- name: command
default: apply
workspaces:
- name: source
mountpath: /source
steps:
- name: deploy-new-app
image: lachlanevenson/k8s-kubectl
script: |
kubectl $(params.command) -f /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
echo "failure" | tee /tekton/results/state
echo "failure applying yaml file to cluster ($(params.yaml-location))" | tee /tekton/results/description
else
echo "success" | tee /tekton/results/state
echo "deployed the yaml files to the cluster"
fi
exit 0

View File

@@ -1,48 +0,0 @@
---
apiVersion: tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: back-end-trigger-template
namespace: tekton-pipeline-1
spec:
params:
- name: gitrevision
description: The git revision
default: master
- name: gitrepositoryurl
description: The git repository url
- name: gitreponame
description: the name of the git repository
- name: branch
description: the name of the branch pushed to
- name: gitrepofullname
description: used for github status updates
- name: sha
description: used for github status updates
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
generateName: back-end-pipeline-run-
spec:
serviceAccountName: service-acc
pipelineRef:
name: stage-application-pipeline
Timeout: "2h30m00s"
workspaces:
- name: workspace
persistentVolumeClaim:
claimName: workspace
params:
- name: git-url
value: $(params.gitrepositoryurl)
- name: branch
value: $(params.branch)
- name: git-repo-name
value: $(params.gitreponame)
- name: revision
value: $(params.gitrevision)
- name: sha
value: $(params.sha)
- name: git-repo-full-name
value: $(params.gitrepofullname)

View File

@@ -3,7 +3,7 @@
apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
name: event-listener-frontend
name: event-listener-github
namespace: tekton-pipeline-1
spec:
serviceAccountName: service-acc
@@ -17,26 +17,17 @@ spec:
bindings:
- name: github-trigger-binding
template:
name: front-end-trigger-template
- name: gitlab
interceptors:
- gitlab:
eventTypes:
- Push Hook
bindings:
- name: gitlab-trigger-binding
template:
name: front-end-trigger-template
name: github-trigger-template
---
apiVersion: v1
kind: Service
metadata:
name: frontend-event-listener
name: github-event-listener
namespace: tekton-pipeline-1
spec:
type: NodePort
selector:
eventlistener: event-listener-frontend
eventlistener: event-listener-github
ports:
- protocol: TCP
port: 8080
@@ -45,21 +36,11 @@ spec:
apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
name: event-listener-backend
name: event-listener-gitlab
namespace: tekton-pipeline-1
spec:
serviceAccountName: service-acc
triggers:
- name: github
interceptors:
- github:
eventTypes:
- pull_request
- push
bindings:
- name: github-trigger-binding
template:
name: back-end-trigger-template
- name: gitlab
interceptors:
- gitlab:
@@ -68,17 +49,17 @@ spec:
bindings:
- name: gitlab-trigger-binding
template:
name: back-end-trigger-template
name: github-trigger-template
---
apiVersion: v1
kind: Service
metadata:
name: backend-event-listener
name: gitlab-event-listener
namespace: tekton-pipeline-1
spec:
type: NodePort
selector:
eventlistener: event-listener-backend
eventlistener: event-listener-gitlab
ports:
- protocol: TCP
port: 8080
@@ -86,49 +67,6 @@ spec:
---
apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
name: event-listener-mirror
namespace: tekton-pipeline-1
spec:
serviceAccountName: service-acc
triggers:
- name: github
interceptors:
- github:
eventTypes:
- pull_request
- push
bindings:
- name: github-trigger-binding
template:
name: mirror-trigger-template
- name: gitlab
interceptors:
- gitlab:
eventTypes:
- Push Hook
bindings:
- name: gitlab-trigger-binding
template:
name: mirror-trigger-template
---
apiVersion: v1
kind: Service
metadata:
name: mirror-event-listener
namespace: tekton-pipeline-1
spec:
type: NodePort
selector:
eventlistener: event-listener-mirror
ports:
- protocol: TCP
port: 8080
targetPort:
---
apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
name: event-listener-infra
namespace: tekton-pipeline-1
@@ -195,17 +133,13 @@ spec:
- host: pipeline.llocal.host
http:
paths:
- path: /stage-frontend
- path: /stage-github
backend:
serviceName: el-event-listener-frontend
serviceName: el-event-listener-github
servicePort: 8080
- path: /stage-backend
- path: /stage-gitlab
backend:
serviceName: el-event-listener-backend
servicePort: 8080
- path: /stage-mirror-service
backend:
serviceName: el-event-listener-mirror
serviceName: el-event-listener-gitlab
servicePort: 8080
- path: /stage-infra
backend:

View File

@@ -15,6 +15,4 @@ spec:
- name: branch
value: $(body.repository.default_branch)
- name: gitrepofullname
value: $(body.repository.full_name)
- name: sha
value: $(body.head_commit.id)
value: $(body.repository.full_name)

View File

@@ -2,7 +2,7 @@
apiVersion: tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: front-end-trigger-template
name: github-trigger-template
namespace: tekton-pipeline-1
spec:
params:
@@ -17,17 +17,15 @@ spec:
description: the name of the branch pushed to
- name: gitrepofullname
description: used for github status updates
- name: sha
description: used for github status updates
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
generateName: front-end-pipeline-run-
generateName: application-pipeline-run-
spec:
serviceAccountName: service-acc
pipelineRef:
name: stage-application-pipeline
name: application-pipeline
Timeout: "2h30m00s"
workspaces:
- name: workspace

View File

@@ -17,8 +17,6 @@ spec:
description: the name of the branch pushed to
- name: gitrepofullname
description: used for github status updates
- name: sha
description: used for github status updates
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
kind: PipelineRun

View File

@@ -1,48 +0,0 @@
---
apiVersion: tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: mirror-trigger-template
namespace: tekton-pipeline-1
spec:
params:
- name: gitrevision
description: The git revision
default: master
- name: gitrepositoryurl
description: The git repository url
- name: gitreponame
description: the name of the git repository
- name: branch
description: the name of the branch pushed to
- name: gitrepofullname
description: used for github status updates
- name: sha
description: used for github status updates
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
generateName: mirror-pipeline-run-
spec:
serviceAccountName: service-acc
pipelineRef:
name: stage-application-pipeline
Timeout: "2h30m00s"
workspaces:
- name: workspace
persistentVolumeClaim:
claimName: workspace
params:
- name: git-url
value: $(params.gitrepositoryurl)
- name: branch
value: $(params.branch)
- name: git-repo-name
value: $(params.gitreponame)
- name: revision
value: $(params.gitrevision)
- name: sha
value: $(params.sha)
- name: git-repo-full-name
value: $(params.gitrepofullname)