Last active
May 12, 2019 03:53
-
-
Save castlemilk/680ef36a65e83b9a6817ddada990bb49 to your computer and use it in GitHub Desktop.
Tekton Pipeline - GCP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: default-cluster-admin | |
subjects: | |
- kind: ServiceAccount | |
name: default | |
namespace: default | |
roleRef: | |
kind: ClusterRole | |
name: cluster-admin | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
apiVersion: tekton.dev/v1alpha1 | |
kind: PipelineResource | |
metadata: | |
name: dev-xp-image | |
spec: | |
type: image | |
params: | |
- name: url | |
value: gcr.io/${PROJECT_ID}/webapp | |
--- | |
apiVersion: tekton.dev/v1alpha1 | |
kind: PipelineResource | |
metadata: | |
name: dev-xp-git | |
spec: | |
type: git | |
params: | |
- name: revision | |
value: master | |
- name: url | |
value: https://github.com/castlemilk/next-dev-xp | |
--- | |
apiVersion: tekton.dev/v1alpha1 | |
kind: Task | |
metadata: | |
name: kubectl-apply | |
spec: | |
inputs: | |
resources: | |
- name: workspace | |
type: git | |
- name: image | |
type: image | |
params: | |
- name: path | |
description: Path to the manifest to apply | |
- name: yqArg | |
description: | |
Okay this is a hack, but I didn't feel right hard-coding `-d1` down | |
below | |
- name: yamlPathToImage | |
description: The path to the image to replace in the yaml manifest (arg to yq) | |
clusters: | |
- name: targetCluster | |
description: Not yet used, kubectl command below should use this cluster | |
steps: | |
- name: replace-image | |
image: mikefarah/yq | |
command: ['yq'] | |
args: | |
- "w" | |
- "-i" | |
- "${inputs.params.yqArg}" | |
- "${inputs.params.path}" | |
- "${inputs.params.yamlPathToImage}" | |
- "${inputs.resources.image.url}" | |
- name: run-kubectl | |
image: lachlanevenson/k8s-kubectl | |
command: ['kubectl'] | |
args: | |
- 'apply' | |
- '-f' | |
- '${inputs.params.path}' | |
--- | |
apiVersion: tekton.dev/v1alpha1 | |
kind: Pipeline | |
metadata: | |
name: webapp-pipeline | |
spec: | |
resources: | |
- name: source-repo | |
type: git | |
- name: webapp-image | |
type: image | |
tasks: | |
- name: deploy-webapp | |
taskRef: | |
name: kubectl-apply | |
resources: | |
inputs: | |
- name: workspace | |
resource: source-repo | |
- name: image | |
resource: webapp-image | |
params: | |
- name: path | |
value: /workspace/workspace/webapp/kubernetes-manifests/webapp.yaml | |
- name: yamlPathToImage | |
value: "spec.template.spec.containers[0].image" | |
- name: yqArg | |
value: "-d1" | |
--- | |
apiVersion: tekton.dev/v1alpha1 | |
kind: PipelineRun | |
metadata: | |
name: webapp-deployment-pipeline | |
spec: | |
pipelineRef: | |
name: webapp-pipeline | |
trigger: | |
type: manual | |
serviceAccount: 'default' | |
resources: | |
- name: source-repo | |
resourceRef: | |
name: dev-xp-git | |
- name: webapp-image | |
resourceRef: | |
name: dev-xp-image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment