Skip to content

Commit

Permalink
Finally commit a demo example that works :D
Browse files Browse the repository at this point in the history
This example will build two images and then deploy them. It uses the
microservice example in Skaffold (just an arbitrary choice of a simple
deployment situation with 2 apps).

This is the (updated version of) the demo that @dlorenc gave at Jenkins
World.

It's kind of weird that this adds yet another example; I suggest that as
part of #108 we remove the other examples since we've never actually run
them successfully: they were added at the beginning of the project as
examples of where we wanted to go.

Had to update step names b/c using camelcase in container names is not
allowed (opened #273 to handle this).

Fixes #89
  • Loading branch information
bobcatfish authored and knative-prow-robot committed Nov 30, 2018
1 parent 7fc6a3f commit 54051bf
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 5 deletions.
29 changes: 27 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,41 @@ To deploy them to your cluster (after
```bash
kubectl apply -f examples/
kubectl apply -f examples/pipelines
kubectl apply -f examples/demo

# To invoke them:
kubectl apply -f examples/demo/run

# TODO(#108): these examples are not known to work
kubectl apply -f examples/invocations
```

## Example Pipelines

We have 2 example [Pipelines](../README.md#pipeline) in [./pipelines](./pipelines)
We have 3 example [Pipelines](../README.md#pipeline) in [./pipelines](./pipelines)

### Demo Pipeline

[`demo`](./demo): This simple Pipeline Builds
[two microservice images](https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices)
from [the Skaffold repo](https://github.com/GoogleContainerTools/skaffold) and deploys them
to the repo currently running the Pipeline CRD.

It does this using the `Deployment` in the existing yaml files, so at the moment there
is no guarantee that the image that are built and pushed are the ones that are deployed
(that would require using the digest of the built image, see
https://github.com/knative/build-pipeline/issues/216).

To run this yourself, you will need to change the values of
`gcr.io/christiewilson-catfactory` to a registry you can push to from inside your cluster.

Since this demo modifies the cluster (deploys to it) you must use a service account with
permission to admin the cluster (or make your default user an admin of the `default`
namespace with [default-cluster-admin.yaml](demo/default-cluster-admin.yaml)).

### Kritis Pipeline

[The Kritis Pipline](./pipelines/kritis.yaml): This example builds a Pipeline for the
[The Kritis Pipeline](./pipelines/kritis.yaml): This example builds a Pipeline for the
[kritis project](https://github.com/grafeas/kritis), and demonstrates how to configure
a pipeline which:

Expand Down
4 changes: 4 additions & 0 deletions examples/build_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ spec:
- name: pathToDockerFile
description: The path to the dockerfile to build
default: /workspace/Dockerfile
- name: pathToContext
description: The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)
default: /workspace
outputs:
resources:
- name: builtImage
Expand All @@ -24,3 +27,4 @@ spec:
args:
- --dockerfile=${inputs.params.pathToDockerFile}
- --destination=${outputs.resources.builtImage.url}
- --context=${inputs.params.pathToContext}
12 changes: 12 additions & 0 deletions examples/demo/default-cluster-admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
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
40 changes: 40 additions & 0 deletions examples/demo/demo-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: pipeline.knative.dev/v1alpha1
kind: Task
metadata:
name: demo-deploy-kubectl
namespace: default
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-codeing `-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}'
51 changes: 51 additions & 0 deletions examples/demo/demo-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: pipeline.knative.dev/v1alpha1
kind: Pipeline
metadata:
name: demo-pipeline
namespace: default
spec:
tasks:
- name: build-skaffold-web
taskRef:
name: build-push
params:
- name: pathToDockerFile
value: Dockerfile
- name: pathToContext
value: /workspace/examples/microservices/leeroy-web
- name: build-skaffold-app
taskRef:
name: build-push
params:
- name: pathToDockerFile
value: Dockerfile
- name: pathToContext
value: /workspace/examples/microservices/leeroy-app
- name: deploy-app
taskRef:
name: demo-deploy-kubectl
resources:
- name: image
providedBy:
- build-skaffold-app
params:
- name: path
value: /workspace/examples/microservices/leeroy-app/kubernetes/deployment.yaml
- name: yqArg
value: "-d1"
- name: yamlPathToImage
value: "spec.template.spec.containers[0].image"
- name: deploy-web
taskRef:
name: demo-deploy-kubectl
inputSourceBindings:
- name: image
providedBy:
- build-skaffold-web
params:
- name: path
value: /workspace/examples/microservices/leeroy-web/kubernetes/deployment.yaml
- name: yqArg
value: "-d1"
- name: yamlPathToImage
value: "spec.template.spec.containers[0].image"
34 changes: 34 additions & 0 deletions examples/demo/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineResource
metadata:
name: skaffold-git
namespace: default
spec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/GoogleContainerTools/skaffold
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineResource
metadata:
name: skaffold-image-leeroy-web
namespace: default
spec:
type: image
params:
- name: url
value: gcr.io/christiewilson-catfactory/leeroy-web
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineResource
metadata:
name: skaffold-image-leeroy-app
namespace: default
spec:
type: image
params:
- name: url
value: gcr.io/christiewilson-catfactory/leeroy-app
47 changes: 47 additions & 0 deletions examples/demo/run/pipeline-run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: pipeline.knative.dev/v1alpha1
kind: PipelineRun
metadata:
name: demo-pipeline-run-1
namespace: default
spec:
pipelineRef:
name: demo-pipeline
pipelineParamsRef:
name: pipelineparams-sample
triggerRef:
type: manual
resources:
- name: build-skaffold-web
inputs:
- name: workspace
resourceRef:
name: skaffold-git
outputs:
- name: builtImage
resourceRef:
name: skaffold-image-leeroy-web
- name: build-skaffold-app
inputs:
- name: workspace
resourceRef:
name: skaffold-git
outputs:
- name: builtImage
resourceRef:
name: skaffold-image-leeroy-app
- name: deploy-app
inputs:
- name: workspace
resourceRef:
name: skaffold-git
- name: image
resourceRef:
name: skaffold-image-leeroy-app
- name: deploy-web
inputs:
- name: workspace
resourceRef:
name: skaffold-git
- name: image
resourceRef:
name: skaffold-image-leeroy-web
2 changes: 1 addition & 1 deletion examples/deploy_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ spec:
- 'apply'
- '-f'
- '${inputs.params.pathToFiles}'
- '${inputs.params.kubectlArgs}'
- '${inputs.params.kubectlArgs}'
10 changes: 8 additions & 2 deletions examples/pipelineparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ metadata:
name: pipelineparams-sample
namespace: default
spec:
serviceAccount: 'demoServiceAccount'
clusters:
- name: 'testCluster'
type: 'gke'
endpoint: 'https://prod.gke.corp.com'
- name: 'stagingCluster'
type: 'gke'
endpoint: 'https://staging.gke.corp.com'
results:
runs:
name: 'runsBucket'
Expand All @@ -17,4 +23,4 @@ spec:
tests:
name: 'testBucket'
type: 'gcs'
url: 'gcs://somebucket/results/tests'
url: 'gcs://somebucket/results/tests'

0 comments on commit 54051bf

Please sign in to comment.