Skip to content

Commit

Permalink
Use image outputs in examples
Browse files Browse the repository at this point in the history
While talking with @jonjohnsonjr about #216 I wanted to show him an
example of a Pipeline wherein there are Tasks that output Images
Resources, which are then used as inputs for subsequent Tasks. Our
examples Pipelines were meant to do that, but unfortunately when I
looked at them, I realized these were not actually hooked up properly.
The Tasks were not actually using the Images that were built by previous
Tasks, so I have updated them to do that.

I also discovered that the templating was incorrect (#108 - adding tests
for these examples - and #212 - making sure templated variables are
actually used - can't come quickly enough!) so I've updated that in the
examples as well.
  • Loading branch information
bobcatfish committed Nov 7, 2018
1 parent 9ae0688 commit 3e4657c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 49 deletions.
4 changes: 2 additions & 2 deletions examples/build_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ spec:
command:
- /kaniko/executor
args:
- --dockerfile=${pathToDockerFile}
- --destination=$builtImage
- --dockerfile=${inputs.params.pathToDockerFile}
- --destination=${outputs.resources.builtImage.url}
39 changes: 34 additions & 5 deletions examples/deploy_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ spec:
resources:
- name: workspace
type: git
- name: imageToDeploy
type: image
params:
- name: pathToHelmCharts
description: Path to where the Helm charts live
- name: helmArgs
description: Extra arguments to pass to Helm
- name: image
description: The image to override the Helm chart with
clusters:
- name: targetCluster
buildSpec:
steps:
- name: deploy
image: kubernetes-helm
command: ['helm']
args: ['install', '--kube-context=${targetCluster}', '--set image=${image}', '${helmArgs}', '${pathToHelmChart}']
args:
- 'install'
- '--kube-context=${inputs.clusters.targetCluster}'
- '--set image=${inputs.resources.imageToDeploy.url}@${inputs.resources.imageToDeploy.digest}'
- '${inputs.params.helmArgs}'
- '${inputs.params.pathToHelmChart}'

---
apiVersion: pipeline.knative.dev/v1alpha1
Expand All @@ -35,6 +40,10 @@ spec:
resources:
- name: workspace
type: git
- name: redisImage
type: image
- name: guestbookImage
type: image
params:
- name: kubectlArgs
description: Extra arguments to pass to kubectl
Expand All @@ -44,7 +53,27 @@ spec:
- name: targetCluster
buildSpec:
steps:
- name: replaceRedisImage
image: busybox
command: ['sed']
args:
- "-ri"
- "'s/image: k8s.gcr.io\\/redis:e2e/image: ${inputs.resources.redisImage.url}@{inputs.resources.redisImage.digest}/' ${inputs.params.pathToFiles}"
- name: replaceGuestbookImage
image: busybox
command: ['sed']
args:
- "-ri"
- "'s/image: gcr.io\\/google-samples\\/gb-frontend:v4/image: ${inputs.resources.guestbookImage.url}@{inputs.resources.guestbookImage.digest}/' ${inputs.params.pathToFiles}"
- name: runKubectl
image: k8s-kubectl
image: lachlanevenson/k8s-kubectl
command: ['kubectl']
args: ['--use-context', '${targetCluster}', '--namespace', '${targetCluster.namespace}', 'apply', '-c', '${pathToFiles}', '${kubectlArgs}']
args:
- '--use-context'
- '${inputs.clusters.targetCluster}'
- '--namespace'
- '${inputs.clusters.targetCluster.namespace}'
- 'apply'
- '-f'
- '${inputs.params.pathToFiles}'
- '${inputs.params.kubectlArgs}'
46 changes: 31 additions & 15 deletions examples/pipelines/guestbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ spec:
taskRef:
name: build-push
inputSourceBindings:
- name: workspace # bind to the name in the task
- name: workspace
resourceRef:
name: guestbook-resources-git
outputSourceBindings:
- name: builtImage # bind to the name in the task
- name: builtImage
resourceRef:
name: guestbookstagingimage
params:
- name: pathToDockerfile
value: guestbook-go/Dockerfile

- name: build-redis # 1.b Build and push redis docker image.
taskRef:
name: build-push
Expand All @@ -33,27 +34,31 @@ spec:
params:
- name: pathToDockerfile
value: 4/debian9/4.0/Dockerfile

- name: deploy-bundle-test # 2. Deploy GuestBook and Redis to test cluster
taskRef:
name: deploy-with-kubectl
inputSourceBindings:
- name: workspace
- name: imageToDeploy1
resourceRef:
name: guestbook-resources-git
name: redisstagingimage
passedConstraints:
- build-guestbook
- build-redis
- name: redis-docker
- name: imageToDeploy2
resourceRef:
name: guestbook-resources-redis-docker
name: guestbookstagingimage
passedConstraints:
- build-redis
- build-guestbook
- name: workspace
resourceRef:
name: guestbook-resources-redis-docker
params:
- name: pathToFiles
value: guestbook/all-in-one/guestbook-all-in-one.yaml
clusterBindings:
- inputName: clusterName
key: testCluster

- name: int-test-osx # 3.a Run Integration tests for osx
taskRef:
name: integration-test-in-docker
Expand All @@ -66,6 +71,7 @@ spec:
params:
- name: dockerBuildFile
value: guestbook-int/Dockerfile

- name: int-test-linux # 3.b Run Integration tests for linux
taskRef:
name: integration-test-in-docker
Expand All @@ -78,19 +84,29 @@ spec:
params:
- name: dockerBuildFile
value: guestbook-int/Dockerfile
- name: deploy-bundle-staging # 4. Deploy GuestBook and Redis to staging cluster

- name: deploy-bundle-test # 4. Deploy GuestBook and Redis to staging cluster
taskRef:
name: deploy-with-kubectl
inputSourceBindings:
- name: workspace
resourceRef:
name: guestbook-resources-git
passedConstraints:
- name: redisImage
resourceRef:
name: redisstagingimage
passedConstraints:
- int-test-osx
- int-test-linux
- name: guestbookImage
resourceRef:
name: guestbookstagingimage
passedConstraints:
- int-test-osx
- int-test-linux
- name: workspace
resourceRef:
name: guestbook-resources-redis-docker
params:
- name: pathToFiles
value: guestbook/all-in-one/guestbook-all-in-one.yaml
clusterBindings:
- inputName: targetCluster
key: stagingCluster
- inputName: clusterName
key: testCluster
Binary file modified examples/pipelines/kritis-pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 2 additions & 15 deletions examples/pipelines/kritis-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,13 @@ spec:
value: https://github.com/grafeas/kritis
- name: revision
value: master
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineResource
metadata:
name: kritis-resources-test-git
namespace: default
spec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/grafeas/kritis-test
---
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineResource
metadata:
name: kritis-resources-image
namespace: default
spec:
spec:
type: image
params:
- name: url
Expand Down
16 changes: 12 additions & 4 deletions examples/pipelines/kritis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,37 @@ spec:
taskRef:
name: make
inputSourceBindings:
- name: workspace # bind to the name in the task
- name: workspace
resourceRef:
name: kritis-resources-git
params:
- name: makeTarget
value: test

- name: push-kritis # 2. Build And Push Tests
taskRef:
name: build-push
inputSourceBindings:
- name: workspace # bind to the name in the task
- name: workspace
resourceRef:
name: kritis-resources-git
passedConstraints: [unit-test-kritis]
outputSourceBindings:
- name: builtImage # bind to the name in the task
- name: builtImage
resourceRef:
name: kritis-resources-image
params:
- name: pathToDockerfile
value: deploy/Dockerfile

- name: deploy-test-env # 3. Finally Deploy to Test environment
taskRef:
name: deploy-with-helm
inputSourceBindings:
- name: workspace
resourceRef:
name: kritis-resources-git
- name: builtImage
resourceRef:
name: kritis-resources-image
passedConstraints: [push-kritis]
Expand All @@ -44,14 +49,17 @@ spec:
clusterBindings:
- inputName: targetCluster
key: testCluster

- name: integration-test # 4. Run Integration Tests in test cluster
taskRef:
name: integration-test-in-docker
inputSourceBindings:
- name: workspace
resourceRef:
name: kritis-resources-test-git
name: kritis-resources-git
passedConstraints: [deploy-test-env]
params:
- name: testArgs
value: "-e REMOTE_INTEGRATION=true"
- name: testCommand
value: "make integration-in-docker"
16 changes: 8 additions & 8 deletions examples/test_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
- name: runMake
image: ubuntu
command: ['make']
args: ['${makeTarget}']
args: ['${inputs.params.makeTarget}']

---
apiVersion: pipeline.knative.dev/v1alpha1
Expand All @@ -34,9 +34,9 @@ spec:
resources:
- name: workspace
type: git
- name: testImage
type: image
params:
- name: testImage
description: The image to use while running the test
- name: testCommand
description: The command to run on the image
- name: testArgs
Expand All @@ -49,9 +49,9 @@ spec:
buildSpec:
steps:
- name: runTests
image: '${testImage}'
command: ['${testCommand}']
args: ['${testArgs}']
image: docker
command: ['${inputs.resources.params.testCommand}']
args: ['${inputs.resources.params.testArgs}']
volumeMounts:
- name: gac
mountPath: gac.json
Expand All @@ -62,10 +62,10 @@ spec:
volumes:
- name: gac
hostPath:
path: ${workspace}/config/gac.json
path: /workspace/config/gac.json
- name: cloudconfig
hostPath:
path: ${workspace}/config/gcloud
path: /workspace/config/gcloud
- name: dockerSocket
hostPath:
path: /var/run/docker.sock
Expand Down

0 comments on commit 3e4657c

Please sign in to comment.