tga werke

This commit is contained in:
2020-03-12 11:07:35 +01:00
parent 692c79cefb
commit 49ca01e818
18 changed files with 269 additions and 181 deletions

View File

@@ -1,3 +1,5 @@
#TODO ZORG ERVOOR DAT DEZE DEPLOYMENTS ENKEL DE CORRECTE ITEMS DEPLOYEN
# --- # ---
# apiVersion: v1 # apiVersion: v1
# kind: Namespace # kind: Namespace
@@ -5,32 +7,32 @@
# name: istio-project-1 # name: istio-project-1
# labels: # labels:
# istio-injection: enabled #zorgt voor auto sidecar injection # istio-injection: enabled #zorgt voor auto sidecar injection
# --- ---
# apiVersion: apps/v1 apiVersion: apps/v1
# kind: Deployment kind: Deployment
# metadata: metadata:
# name: server-a name: server-a
# namespace: istio-project-1 namespace: istio-project-1
# spec: spec:
# replicas: 1 replicas: 1
# selector: selector:
# matchLabels: matchLabels:
# server: "http" server: "http"
# app: "project-1" #app label bepaald groepering pods in kiali dashboard dus makkelijker te gebruiken app: "project-1" #app label bepaald groepering pods in kiali dashboard dus makkelijker te gebruiken
# expose: "true" expose: "true"
# template: template:
# metadata: metadata:
# labels: labels:
# server: "http" server: "http"
# app: "project-1" app: "project-1"
# expose: "true" expose: "true"
# spec: spec:
# containers: containers:
# - name: front-end - name: front-end
# image: beppev/server-a:master image: beppev/server-a:master
# imagePullPolicy: "Always" imagePullPolicy: "Always"
# ports: ports:
# - containerPort: 5000 - containerPort: 5000
# --- # ---
# apiVersion: apps/v1 # apiVersion: apps/v1
# kind: Deployment # kind: Deployment

14
infra.yaml Normal file
View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: expose-service
spec:
selector:
expose: "true"
ports:
- name: http
protocol: TCP
port: 5000
targetPort: 5000
nodePort: 30036
type: NodePort

View File

@@ -57,50 +57,105 @@ subjects:
name: service-acc name: service-acc
namespace: default namespace: default
--- ---
# TODO add git clone task
apiVersion: tekton.dev/v1alpha1 apiVersion: tekton.dev/v1alpha1
kind: PipelineResource kind: Task
metadata: metadata:
name: git-master name: git-clone
#namespace: stage-tekton-pipeline
spec: spec:
type: git workspaces:
- name: output
description: The git repo will be cloned onto the volume backing this workspace
params: params:
- name: revision - name: url
value: master description: git url to clone
- name: url type: string
value: git://github.com/beppevanrolleghem/cicdTest - name: revision
description: git revision to checkout (branch, tag, sha, ref…)
type: string
default: master
- name: submodules
description: defines if the resource should initialize and fetch the submodules
type: string
default: "true"
- name: depth
description: performs a shallow clone where only the most recent commit(s) will be fetched
type: string
default: "1"
- name: sslVerify
description: defines if http.sslVerify should be set to true or false in the global git config
type: string
default: "true"
- name: subdirectory
description: subdirectory inside the "output" workspace to clone the git repo into
type: string
default: "src"
- name: deleteExisting
description: clean out the contents of the repo's destination directory (if it already exists) before trying to clone the repo there
type: string
default: "true"
results:
- name: commit
description: The precise commit SHA that was fetched by this Task
steps:
- name: clone
image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:latest
script: |
CHECKOUT_DIR="$(workspaces.output.path)/$(inputs.params.subdirectory)"
cleandir() {
# Delete any existing contents of the repo directory if it exists.
#
# We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/"
# or the root of a mounted volume.
if [[ -d "$CHECKOUT_DIR" ]] ; then
# Delete non-hidden files and directories
rm -rf "$CHECKOUT_DIR"/*
# Delete files and directories starting with . but excluding ..
rm -rf "$CHECKOUT_DIR"/.[!.]*
# Delete files and directories starting with .. plus any other character
rm -rf "$CHECKOUT_DIR"/..?*
fi
}
if [[ "$(inputs.params.deleteExisting)" == "true" ]] ; then
cleandir
ls -lah "$CHECKOUT_DIR"
fi
/ko-app/git-init \
-url "$(inputs.params.url)" \
-revision "$(inputs.params.revision)" \
-path "$CHECKOUT_DIR" \
-sslVerify "$(inputs.params.sslVerify)" \
-submodules "$(inputs.params.submodules)" \
-depth "$(inputs.params.depth)"
cd "$CHECKOUT_DIR"
RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')"
EXIT_CODE="$?"
if [ "$EXIT_CODE" != 0 ]
then
exit $EXIT_CODE
fi
# Make sure we don't add a trailing newline to the result!
echo -n "$RESULT_SHA" > $(results.commit.path)
--- ---
apiVersion: tekton.dev/v1alpha1 apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: git-experimental
#namespace: stage-tekton-pipeline
spec:
type: git
params:
- name: revision
value: experimental
- name: url
value: git://github.com/beppevanrolleghem/cicdTest
---
apiVersion: tekton.dev/v1beta1
kind: Task kind: Task
metadata: metadata:
name: build-and-push name: build-and-push
#namespace: stage-tekton-pipeline
spec: spec:
inputs: params:
resources: - name: context
- name: git-source description: The path to the build context, used by Kaniko - within the workspace
type: git default: .
params: type: string
- name: context - name: image-name
description: The path to the build context, used by Kaniko - within the workspace description: dockerhub url
default: . type: string
- name: image-name - name: version
description: dockerhub url description: image-version (for instance latest or beta)
- name: version type: string
description: image-version (for instance latest or beta) workspaces:
- name: source
mountpath: /source
steps: steps:
- name: build-and-push - name: build-and-push
image: gcr.io/kaniko-project/executor image: gcr.io/kaniko-project/executor
@@ -110,135 +165,143 @@ spec:
command: command:
- /kaniko/executor - /kaniko/executor
args: args:
- "--dockerfile=$(inputs.resources.git-source.path)/$(inputs.params.context)/dockerfile" - "--dockerfile=/source/$(params.context)/dockerfile"
- "--destination=beppev/$(inputs.params.image-name):$(inputs.params.version)" - "--destination=beppev/$(params.image-name):$(params.version)"
- "--context=$(inputs.resources.git-source.path)/$(inputs.params.context)/" - "--context=/source/$(params.context)/"
--- ---
apiVersion: tekton.dev/v1alpha1 apiVersion: tekton.dev/v1alpha1
kind: Task kind: Task
metadata: metadata:
name: destroy-application name: execute-yaml
#namespace: stage-tekton-pipeline #namespace: stage-tekton-pipeline
spec: spec:
inputs: params:
resources: - name: yaml-location
- name: git-source default: deploy.yaml
type: git - name: command
steps: default: apply
- name: delete-old-deployment workspaces:
image: lachlanevenson/k8s-kubectl - name: source
command: ["kubectl"] mountpath: /source
args:
- "delete"
- "--ignore-not-found"
- "-f"
- "$(inputs.resources.git-source.path)/deploy.yaml"
---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: deploy-application
#namespace: stage-tekton-pipeline
spec:
inputs:
resources:
- name: git-source
type: git
steps: steps:
- name: deploy-new-app - name: deploy-new-app
image: lachlanevenson/k8s-kubectl image: lachlanevenson/k8s-kubectl
command: ["kubectl"] command: ["kubectl"]
args: args:
- "apply" - "$(params.command)"
- "-f" - "-f"
- "$(inputs.resources.git-source.path)/deploy.yaml" - "/source/$(params.yaml-location)"
--- ---
apiVersion: tekton.dev/v1alpha1 apiVersion: tekton.dev/v1beta1
kind: Pipeline kind: Pipeline
metadata: metadata:
name: application-pipeline name: application-pipeline
#namespace: stage-tekton-pipeline #namespace: stage-tekton-pipeline
spec: spec:
resources: params:
- name: git-master - name: git-url
type: git description: url of the github repository to clone
- name: git-experimental - name: branch
type: git description: name of the master branch of the repository
workspaces:
- name: workspace
tasks: tasks:
# - name: destroy-application #@TODO make it so that the delete can be skipped if error - name: clone-master
# taskRef: taskRef:
# name: destroy-application name: git-clone
# resources: workspaces:
# inputs: - name: output
# - name: git-source workspace: workspace
# resource: git-master params:
- name: build-and-push-a - name: url
taskRef: value: $(inputs.params.git-url)
name: build-and-push - name: revision
params: value: $(inputs.params.master-branch)
- name: context - name: build-and-push-a
value: "serverA" taskRef:
- name: image-name name: build-and-push
value: "server-a" workspaces:
- name: version - name: source
value: "master" workspace: workspace
resources: params:
inputs: - name: context
- name: git-source value: "server-a"
resource: git-master - name: image-name
- name: build-and-push-b-stable value: "server-a"
taskRef: - name: version
name: build-and-push value: "$(inputs.params.master-branch)"
params: - name: build-and-push-b-stable
- name: context taskRef:
value: "serverB" name: build-and-push
- name: image-name workspaces:
value: "server-b" - name: source
- name: version workspace: workspace
value: "master" params:
resources: - name: context
inputs: value: "server-b"
- name: git-source - name: image-name
resource: git-master value: "server-b"
- name: build-and-push-b-experimental - name: version
taskRef: value: "$(inputs.params.master-branch)"
name: build-and-push - name: build-and-push-d
params: taskRef:
- name: context name: build-and-push
value: "serverB" workspaces:
- name: image-name - name: source
value: "server-b" workspace: workspace
- name: version params:
value: "experimental" - name: context
resources: value: "server-d"
inputs: - name: image-name
- name: git-source value: "server-d"
resource: git-experimental - name: version
- name: build-and-push-d value: "$(inputs.params.master-branch)"
taskRef: - name: clone-experimental-branch
name: build-and-push taskRef:
params: name: git-clone
- name: context workspaces:
value: "serverD" - name: output
- name: image-name workspace: workspace
value: "server-d" runAfter:
- name: version - build-and-push-a
value: "master" - build-and-push-b-stable
resources: - build-and-push-d
inputs: params:
- name: git-source - name: url
resource: git-master value: $(inputs.params.git-url)
- name: deploy-application #@TODO make it so that the delete can be skipped if error - name: revision
taskRef: value: $(inputs.params.experimental-branch)
name: deploy-application - name: build-and-push-b-experimental
runAfter: taskRef:
- build-and-push-d name: build-and-push
- build-and-push-b-experimental workspaces:
- build-and-push-a - name: source
- build-and-push-b-stable workspace: workspace
#- destroy-application runAfter:
resources: - clone-experimental-branch
inputs: params:
- name: git-source - name: context
resource: git-master value: "server-b"
# DO NOT FORGET TO SET REGCREDS FOR DOCKER - name: image-name
value: "server-b"
- name: version
value: "$(inputs.params.experimental-branch)"
- name: deploy-infra
taskRef:
name: execute-yaml
workspaces:
- name: source
workspace: workspace
runAfter:
- build-and-push-b-experimental
params:
- name: yaml-location
value: "infra.yaml"
- name: execute-yaml #@TODO make it so that the delete can be skipped if error
taskRef:
name: execute-yaml
workspaces:
- name: source
workspace: workspace
runAfter:
- deploy-infra

View File

@@ -19,6 +19,17 @@ spec:
- name: source - name: source
value: github value: github
--- ---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: workspace-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Mi
---
apiVersion: tekton.dev/v1alpha1 apiVersion: tekton.dev/v1alpha1
kind: TriggerTemplate kind: TriggerTemplate
metadata: metadata:
@@ -41,13 +52,11 @@ spec:
serviceAccountName: service-acc serviceAccountName: service-acc
pipelineRef: pipelineRef:
name: application-pipeline #gebruik dit om de pipeline aan te passen naar andere versies, zolang ze zich in dezelfde #namespace bevinden kunnen we deze pipeline hergebruiken om deployments op de cluster uit te voeren. service-mesh agnostisch. name: application-pipeline #gebruik dit om de pipeline aan te passen naar andere versies, zolang ze zich in dezelfde #namespace bevinden kunnen we deze pipeline hergebruiken om deployments op de cluster uit te voeren. service-mesh agnostisch.
resources: params:
- name: git-master - name: git-url
resourceRef: value: $(inputs.params.gitrepositoryurl)
name: git-master - name: branch
- name: git-experimental value: $(inputs.params.gitrevision)
resourceRef:
name: git-experimental
--- ---
kind: ClusterRole kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1