mirror of
https://github.com/bvanroll/cicdTest.git
synced 2025-08-28 19:42:41 +00:00
245 lines
5.6 KiB
YAML
245 lines
5.6 KiB
YAML
---
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: stage-tekton-pipeline
|
|
labels:
|
|
istio-injection: enabled #zorgt voor auto sidecar injection
|
|
---
|
|
apiVersion: v1
|
|
kind: ServiceAccount
|
|
metadata:
|
|
name: service-acc
|
|
namespace: stage-tekton-pipeline
|
|
secrets:
|
|
- name: regcred
|
|
---
|
|
apiVersion: rbac.authorization.k8s.io/v1
|
|
kind: ClusterRole
|
|
metadata:
|
|
name: allow-creation
|
|
rules:
|
|
- apiGroups:
|
|
- ""
|
|
- "apps"
|
|
- "deploy"
|
|
- "networking.istio.io"
|
|
# deze zullen we ook moeten aanpassen elke pipeline die we maken, maar, deze pipelines zijn nu specifiek per branch, dus dit zou geen probleem leveren.
|
|
resources:
|
|
- pods
|
|
- serviceaccounts
|
|
- namespaces
|
|
- services
|
|
- deployments
|
|
- deployments.apps
|
|
- destinationrules
|
|
- gateways
|
|
- virtualservices
|
|
verbs:
|
|
- list
|
|
- watch
|
|
- get
|
|
- create
|
|
- update
|
|
- patch
|
|
- delete
|
|
---
|
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
|
kind: ClusterRoleBinding
|
|
metadata:
|
|
name: allow-creation-binding
|
|
roleRef:
|
|
apiGroup: rbac.authorization.k8s.io
|
|
kind: ClusterRole
|
|
name: allow-creation
|
|
subjects:
|
|
- kind: ServiceAccount
|
|
name: service-acc
|
|
namespace: stage-tekton-pipeline
|
|
---
|
|
apiVersion: tekton.dev/v1alpha1
|
|
kind: PipelineResource
|
|
metadata:
|
|
name: git-master
|
|
namespace: stage-tekton-pipeline
|
|
spec:
|
|
type: git
|
|
params:
|
|
- name: revision
|
|
value: master
|
|
- name: url
|
|
value: git://github.com/beppevanrolleghem/cicdTest
|
|
---
|
|
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/v1alpha1
|
|
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)
|
|
steps:
|
|
- name: build-and-push
|
|
image: gcr.io/kaniko-project/executor
|
|
env:
|
|
- name: "DOCKER_CONFIG"
|
|
value: "/tekton/home/.docker/"
|
|
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)/"
|
|
---
|
|
apiVersion: tekton.dev/v1alpha1
|
|
kind: Task
|
|
metadata:
|
|
name: destroy-application
|
|
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
|
|
steps:
|
|
- name: deploy-new-app
|
|
image: lachlanevenson/k8s-kubectl
|
|
command: ["kubectl"]
|
|
args:
|
|
- "apply"
|
|
- "-f"
|
|
- "$(inputs.resources.git-source.path)/deploy.yaml"
|
|
---
|
|
apiVersion: tekton.dev/v1alpha1
|
|
kind: Pipeline
|
|
metadata:
|
|
name: application-pipeline
|
|
namespace: stage-tekton-pipeline
|
|
spec:
|
|
resources:
|
|
- name: git-master
|
|
type: git
|
|
- name: git-experimental
|
|
type: git
|
|
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
|