This commit is contained in:
2020-02-18 12:55:03 +01:00
parent e64a0f080e
commit 8a75cef351
11 changed files with 310 additions and 4 deletions

View File

@@ -0,0 +1,86 @@
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: application-pipeline
spec:
resources:
- name: git-source
type: git
params:
- name: pathToYamlFile
description: path to deploy.yaml for final application deploy
default: config.yaml
- name: pathToContext
description: The path to the build context, used by Kaniko - within the workspace
default: .
- name: imageUrl-a
description: Url of image repository a
default: deploy_target
- name: imageTag-a
description: Tag to apply to the built image a
default: latest
- name: pathToContext-a
description: The path to the build context, used by Kaniko - within the workspace
default: .
- name: imageUrl-b
description: Url of image repository
default: deploy_target
- name: imageTag-b
description: Tag to apply to the built image
default: latest
- name: pathToContext-b
description: The path to the build context, used by Kaniko - within the workspace
default: .
tasks:
- name: build-and-push-a
taskRef:
name: build-and-push
params:
- name: pathToContext
value: "$(params.pathToContext-a)"
- name: imageUrl
value: "$(params.imageUrl-a)"
- name: imageTag
value: "$(params.imageTag-a)"
resources:
inputs:
- name: git-source
resource: git-source
- name: build-and-push-b
taskRef:
name: build-and-push
runAfter:
- build-and-push-a
params:
- name: pathToContext
value: "$(params.pathToContext-b)"
- name: imageUrl
value: "$(params.imageUrl-b)"
- name: imageTag
value: "$(params.imageTag-b)"
resources:
inputs:
- name: git-source
resource: git-source
- name: deploy-application
taskRef:
name: deploy-application
runAfter:
- build-and-push-b
params:
- name: pathToContext
value: "$(params.pathToContext)"
- name: pathToYamlFile
value: "$(params.pathToYamlFile)"
- name: imageUrl-a
value: "$(params.imageUrl-a)"
- name: imageTag-a
value: "$(params.imageTag-a)"
- name: imageUrl-b
value: "$(params.imageUrl-b)"
- name: imageTag-b
value: "$(params.imageTag-b)"
resources:
inputs:
- name: git-source
resource: git-source

View File

@@ -0,0 +1,29 @@
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
name: application-pipeline-run
spec:
serviceAccountName: tutorial-service
pipelineRef:
name: application-pipeline
resources:
- name: git-source
resourceRef:
name: git
params:
- name: pathToYamlFile
value: "deploy.yaml"
- name: pathToContext
value: "."
- name: imageUrl-a
value: "beppeserver-a"
- name: imageTag-a
value: "beppeserver-a-tag"
- name: pathToContext-a
value: "./serverA"
- name: imageUrl-b
value: "beppeserver-b"
- name: imageTag-b
value: "beppeserver-b-tag"
- name: pathToContext-b
value: "./serverB"

View File

@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: tutorial-service
secrets:
- name: regcred

View File

@@ -0,0 +1,12 @@
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: git
spec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/beppevanrolleghem/cicdTest

View File

@@ -0,0 +1,30 @@
---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: build-and-push
spec:
inputs:
resources:
- name: git-source
type: git
params:
- name: pathToContext
description: The path to the build context, used by Kaniko - within the workspace
default: .
- name: pathToDockerfile
description: The path to the dockerfile to build
default: Dockerfile
- name: imageUrl
description: value should be like - us.icr.io/test_namespace/builtImageApp
- name: imageTag
description: Tag to apply to the built image
steps:
- name: build-and-push
image: gcr.io/kaniko-project/executor
command:
- /kaniko/executor
args:
- "--dockerfile=$(inputs.params.pathToContext)/dockerfile"
- "--destination=$(inputs.params.imageUrl):$(inputs.params.imageTag)"
- "--context=$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/"

View File

@@ -0,0 +1,53 @@
---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: deploy-application
spec:
inputs:
resources:
- name: git-source
type: git
params:
- name: pathToContext
description: The path to the build context, used by Kaniko - within the workspace
default: .
- name: pathToYamlFile
description: The path to the yaml file to deploy within the git source
default: deploy.yaml
- name: imageUrl-a
description: Url of image repository
default: url
- name: imageTag-a
description: Tag of the images to be used.
default: "latest"
- name: imageUrl-b
description: Url of image repository
default: url
- name: imageTag-b
description: Tag of the images to be used.
default: "latest"
steps:
- name: replace-imagea
image: alpine
command: ["sed"]
args:
- "-i"
- "-e"
- "s;IMAGE-A;$(inputs.params.imageUrl-a):$(inputs.params.imageTag-a);g"
- "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)"
- name: replace-imageb
image: alpine
command: ["sed"]
args:
- "-i"
- "-e"
- "s;IMAGE-b;$(inputs.params.imageUrl-b):$(inputs.params.imageTag-b);g"
- "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)"
- name: deploy-app
image: lachlanevenson/k8s-kubectl
command: ["kubectl"]
args:
- "apply"
- "-f"
- "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)"