mirror of
https://github.com/bvanroll/cicdTest.git
synced 2025-08-28 19:42:41 +00:00
tga werke
This commit is contained in:
54
deploy.yaml
54
deploy.yaml
@@ -1,3 +1,5 @@
|
||||
#TODO ZORG ERVOOR DAT DEZE DEPLOYMENTS ENKEL DE CORRECTE ITEMS DEPLOYEN
|
||||
|
||||
# ---
|
||||
# apiVersion: v1
|
||||
# kind: Namespace
|
||||
@@ -5,32 +7,32 @@
|
||||
# name: istio-project-1
|
||||
# labels:
|
||||
# istio-injection: enabled #zorgt voor auto sidecar injection
|
||||
# ---
|
||||
# apiVersion: apps/v1
|
||||
# kind: Deployment
|
||||
# metadata:
|
||||
# name: server-a
|
||||
# namespace: istio-project-1
|
||||
# spec:
|
||||
# replicas: 1
|
||||
# selector:
|
||||
# matchLabels:
|
||||
# server: "http"
|
||||
# app: "project-1" #app label bepaald groepering pods in kiali dashboard dus makkelijker te gebruiken
|
||||
# expose: "true"
|
||||
# template:
|
||||
# metadata:
|
||||
# labels:
|
||||
# server: "http"
|
||||
# app: "project-1"
|
||||
# expose: "true"
|
||||
# spec:
|
||||
# containers:
|
||||
# - name: front-end
|
||||
# image: beppev/server-a:master
|
||||
# imagePullPolicy: "Always"
|
||||
# ports:
|
||||
# - containerPort: 5000
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: server-a
|
||||
namespace: istio-project-1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
server: "http"
|
||||
app: "project-1" #app label bepaald groepering pods in kiali dashboard dus makkelijker te gebruiken
|
||||
expose: "true"
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
server: "http"
|
||||
app: "project-1"
|
||||
expose: "true"
|
||||
spec:
|
||||
containers:
|
||||
- name: front-end
|
||||
image: beppev/server-a:master
|
||||
imagePullPolicy: "Always"
|
||||
ports:
|
||||
- containerPort: 5000
|
||||
# ---
|
||||
# apiVersion: apps/v1
|
||||
# kind: Deployment
|
||||
|
14
infra.yaml
Normal file
14
infra.yaml
Normal 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
|
@@ -57,50 +57,105 @@ subjects:
|
||||
name: service-acc
|
||||
namespace: default
|
||||
---
|
||||
# TODO add git clone task
|
||||
apiVersion: tekton.dev/v1alpha1
|
||||
kind: PipelineResource
|
||||
kind: Task
|
||||
metadata:
|
||||
name: git-master
|
||||
#namespace: stage-tekton-pipeline
|
||||
name: git-clone
|
||||
spec:
|
||||
type: git
|
||||
workspaces:
|
||||
- name: output
|
||||
description: The git repo will be cloned onto the volume backing this workspace
|
||||
params:
|
||||
- name: revision
|
||||
value: master
|
||||
- name: url
|
||||
value: git://github.com/beppevanrolleghem/cicdTest
|
||||
- name: url
|
||||
description: git url to clone
|
||||
type: string
|
||||
- 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
|
||||
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
|
||||
metadata:
|
||||
name: build-and-push
|
||||
#namespace: stage-tekton-pipeline
|
||||
spec:
|
||||
inputs:
|
||||
resources:
|
||||
- name: git-source
|
||||
type: git
|
||||
params:
|
||||
- name: context
|
||||
description: The path to the build context, used by Kaniko - within the workspace
|
||||
default: .
|
||||
- name: image-name
|
||||
description: dockerhub url
|
||||
- name: version
|
||||
description: image-version (for instance latest or beta)
|
||||
params:
|
||||
- name: context
|
||||
description: The path to the build context, used by Kaniko - within the workspace
|
||||
default: .
|
||||
type: string
|
||||
- name: image-name
|
||||
description: dockerhub url
|
||||
type: string
|
||||
- name: version
|
||||
description: image-version (for instance latest or beta)
|
||||
type: string
|
||||
workspaces:
|
||||
- name: source
|
||||
mountpath: /source
|
||||
steps:
|
||||
- name: build-and-push
|
||||
image: gcr.io/kaniko-project/executor
|
||||
@@ -110,135 +165,143 @@ spec:
|
||||
command:
|
||||
- /kaniko/executor
|
||||
args:
|
||||
- "--dockerfile=$(inputs.resources.git-source.path)/$(inputs.params.context)/dockerfile"
|
||||
- "--destination=beppev/$(inputs.params.image-name):$(inputs.params.version)"
|
||||
- "--context=$(inputs.resources.git-source.path)/$(inputs.params.context)/"
|
||||
- "--dockerfile=/source/$(params.context)/dockerfile"
|
||||
- "--destination=beppev/$(params.image-name):$(params.version)"
|
||||
- "--context=/source/$(params.context)/"
|
||||
---
|
||||
apiVersion: tekton.dev/v1alpha1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: destroy-application
|
||||
name: execute-yaml
|
||||
#namespace: stage-tekton-pipeline
|
||||
spec:
|
||||
inputs:
|
||||
resources:
|
||||
- name: git-source
|
||||
type: git
|
||||
steps:
|
||||
- name: delete-old-deployment
|
||||
image: lachlanevenson/k8s-kubectl
|
||||
command: ["kubectl"]
|
||||
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
|
||||
params:
|
||||
- name: yaml-location
|
||||
default: deploy.yaml
|
||||
- name: command
|
||||
default: apply
|
||||
workspaces:
|
||||
- name: source
|
||||
mountpath: /source
|
||||
steps:
|
||||
- name: deploy-new-app
|
||||
image: lachlanevenson/k8s-kubectl
|
||||
command: ["kubectl"]
|
||||
args:
|
||||
- "apply"
|
||||
- "$(params.command)"
|
||||
- "-f"
|
||||
- "$(inputs.resources.git-source.path)/deploy.yaml"
|
||||
- "/source/$(params.yaml-location)"
|
||||
---
|
||||
apiVersion: tekton.dev/v1alpha1
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Pipeline
|
||||
metadata:
|
||||
name: application-pipeline
|
||||
#namespace: stage-tekton-pipeline
|
||||
spec:
|
||||
resources:
|
||||
- name: git-master
|
||||
type: git
|
||||
- name: git-experimental
|
||||
type: git
|
||||
params:
|
||||
- name: git-url
|
||||
description: url of the github repository to clone
|
||||
- name: branch
|
||||
description: name of the master branch of the repository
|
||||
workspaces:
|
||||
- name: workspace
|
||||
tasks:
|
||||
# - name: destroy-application #@TODO make it so that the delete can be skipped if error
|
||||
# taskRef:
|
||||
# name: destroy-application
|
||||
# resources:
|
||||
# inputs:
|
||||
# - name: git-source
|
||||
# resource: git-master
|
||||
- name: build-and-push-a
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
params:
|
||||
- name: context
|
||||
value: "serverA"
|
||||
- name: image-name
|
||||
value: "server-a"
|
||||
- name: version
|
||||
value: "master"
|
||||
resources:
|
||||
inputs:
|
||||
- name: git-source
|
||||
resource: git-master
|
||||
- name: build-and-push-b-stable
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
params:
|
||||
- name: context
|
||||
value: "serverB"
|
||||
- name: image-name
|
||||
value: "server-b"
|
||||
- name: version
|
||||
value: "master"
|
||||
resources:
|
||||
inputs:
|
||||
- name: git-source
|
||||
resource: git-master
|
||||
- name: build-and-push-b-experimental
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
params:
|
||||
- name: context
|
||||
value: "serverB"
|
||||
- name: image-name
|
||||
value: "server-b"
|
||||
- name: version
|
||||
value: "experimental"
|
||||
resources:
|
||||
inputs:
|
||||
- name: git-source
|
||||
resource: git-experimental
|
||||
- name: build-and-push-d
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
params:
|
||||
- name: context
|
||||
value: "serverD"
|
||||
- name: image-name
|
||||
value: "server-d"
|
||||
- name: version
|
||||
value: "master"
|
||||
resources:
|
||||
inputs:
|
||||
- name: git-source
|
||||
resource: git-master
|
||||
- name: deploy-application #@TODO make it so that the delete can be skipped if error
|
||||
taskRef:
|
||||
name: deploy-application
|
||||
runAfter:
|
||||
- build-and-push-d
|
||||
- build-and-push-b-experimental
|
||||
- build-and-push-a
|
||||
- build-and-push-b-stable
|
||||
#- destroy-application
|
||||
resources:
|
||||
inputs:
|
||||
- name: git-source
|
||||
resource: git-master
|
||||
# DO NOT FORGET TO SET REGCREDS FOR DOCKER
|
||||
- name: clone-master
|
||||
taskRef:
|
||||
name: git-clone
|
||||
workspaces:
|
||||
- name: output
|
||||
workspace: workspace
|
||||
params:
|
||||
- name: url
|
||||
value: $(inputs.params.git-url)
|
||||
- name: revision
|
||||
value: $(inputs.params.master-branch)
|
||||
- name: build-and-push-a
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
workspaces:
|
||||
- name: source
|
||||
workspace: workspace
|
||||
params:
|
||||
- name: context
|
||||
value: "server-a"
|
||||
- name: image-name
|
||||
value: "server-a"
|
||||
- name: version
|
||||
value: "$(inputs.params.master-branch)"
|
||||
- name: build-and-push-b-stable
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
workspaces:
|
||||
- name: source
|
||||
workspace: workspace
|
||||
params:
|
||||
- name: context
|
||||
value: "server-b"
|
||||
- name: image-name
|
||||
value: "server-b"
|
||||
- name: version
|
||||
value: "$(inputs.params.master-branch)"
|
||||
- name: build-and-push-d
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
workspaces:
|
||||
- name: source
|
||||
workspace: workspace
|
||||
params:
|
||||
- name: context
|
||||
value: "server-d"
|
||||
- name: image-name
|
||||
value: "server-d"
|
||||
- name: version
|
||||
value: "$(inputs.params.master-branch)"
|
||||
- name: clone-experimental-branch
|
||||
taskRef:
|
||||
name: git-clone
|
||||
workspaces:
|
||||
- name: output
|
||||
workspace: workspace
|
||||
runAfter:
|
||||
- build-and-push-a
|
||||
- build-and-push-b-stable
|
||||
- build-and-push-d
|
||||
params:
|
||||
- name: url
|
||||
value: $(inputs.params.git-url)
|
||||
- name: revision
|
||||
value: $(inputs.params.experimental-branch)
|
||||
- name: build-and-push-b-experimental
|
||||
taskRef:
|
||||
name: build-and-push
|
||||
workspaces:
|
||||
- name: source
|
||||
workspace: workspace
|
||||
runAfter:
|
||||
- clone-experimental-branch
|
||||
params:
|
||||
- name: context
|
||||
value: "server-b"
|
||||
- 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
|
||||
|
@@ -19,6 +19,17 @@ spec:
|
||||
- name: source
|
||||
value: github
|
||||
---
|
||||
kind: PersistentVolumeClaim
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: workspace-pvc
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteMany
|
||||
resources:
|
||||
requests:
|
||||
storage: 500Mi
|
||||
---
|
||||
apiVersion: tekton.dev/v1alpha1
|
||||
kind: TriggerTemplate
|
||||
metadata:
|
||||
@@ -40,14 +51,12 @@ spec:
|
||||
spec:
|
||||
serviceAccountName: service-acc
|
||||
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.
|
||||
resources:
|
||||
- name: git-master
|
||||
resourceRef:
|
||||
name: git-master
|
||||
- name: git-experimental
|
||||
resourceRef:
|
||||
name: git-experimental
|
||||
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.
|
||||
params:
|
||||
- name: git-url
|
||||
value: $(inputs.params.gitrepositoryurl)
|
||||
- name: branch
|
||||
value: $(inputs.params.gitrevision)
|
||||
---
|
||||
kind: ClusterRole
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
|
Reference in New Issue
Block a user