Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate yaml e2e test from knative/build #493

Merged
merged 2 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ For example, use volumes to accomplish one of the following common tasks:
- [Mount a Kubernetes secret](./auth.md).
- Create an `emptyDir` volume to act as a cache for use across multiple build
steps. Consider using a persistent volume for inter-build caching.
- Mount [Kubernetes configmap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) as volume source.
- Mount a host's Docker socket to use a `Dockerfile` for container image builds.
**Note:** Building a container image using `docker build` on-cluster is _very
unsafe_. Use [kaniko](https://github.com/GoogleContainerTools/kaniko) instead.
Expand All @@ -324,7 +325,7 @@ For example, use volumes to accomplish one of the following common tasks:
### Templating

`Tasks` support templating using values from all [`inputs`](#inputs) and
[`outputs`](#outputs),
[`outputs`](#outputs).

[`PipelineResources`](resources.md) can be referenced in a `Task` spec like
this, where `<name>` is the Resource Name and `<key>` is a one of the resource's
Expand All @@ -340,18 +341,20 @@ Or for an output resource:
${outputs.resources.<name>.<key>}
```

To access an input parameter, replace `resources` with `params` as below:
To access an input parameter, replace `resources` with `params`.

```shell
${inputs.params.<name>}
```
**Note**: Task volume names and volume source(current support includes only configmap) can also be parameterized as shown in [example](#using-kubernetes-configmap-as-volume-source)

## Examples

Use these code snippets to help you understand how to define your `Tasks`.

- [Example of image building and pushing](#example-task)
- [Mounting extra volumes](#using-an-extra-volume)
- [Mounting configMap as volume source](#using-kubernetes-configmap-as-volume-source)

_Tip: See the collection of simple
[examples](https://github.com/knative/build-pipeline/tree/master/examples) for
Expand Down Expand Up @@ -442,7 +445,29 @@ spec:
emptyDir: {}
```

---
#### Using Kubernetes Configmap as Volume Source

```yaml
spec:
inputs:
params:
- name: CFGNAME
description: Name of config map
- name: volumeName
description: Name of volume
steps:
- image: ubuntu
entrypoint: ["bash"]
args: ["-c", "cat /var/configmap/test"]
volumeMounts:
- name: "${inputs.params.volumeName}"
mountPath: /var/configmap

volumes:
- name: "${inputs.params.volumeName}"
configMap:
name: "${inputs.params.CFGNAME}"
```

Except as otherwise noted, the content of this page is licensed under the
[Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/),
Expand Down
19 changes: 0 additions & 19 deletions examples/1-bots.yaml

This file was deleted.

121 changes: 23 additions & 98 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,113 +5,38 @@ This directory contains examples of [the Pipeline CRDs](../README.md) in action.
To deploy them to your cluster (after
[installing the CRDs and running the controller](../DEVELOPMENT.md#getting-started)):

```bash
# To setup all the Tasks/Pipelines etc.
kubectl apply -f examples/
In few examples to demonstrate tasks that push image to registry, sample URL `gcr.io/christiewilson-catfactory` is used. To run these examples yourself, you will need to change the values of this sample registry URL to a registry you can push to from inside
your cluster. If you are following instructions [here](../DEVELOPMENT.md#getting-started) to setup then use the value of `${KO_DOCKER_REPO}` instead of `gcr.io/christiewilson-catfactory`.

```bash
# To invoke the build-push Task only
kubectl apply -f examples/run/taskrun.yaml
kubectl apply -f examples/taskruns/taskrun.yaml

# To invoke the simple Pipeline
kubectl apply -f examples/run/pipelinerun.yaml
kubectl apply -f examples/pipelineruns/pipelinerun.yaml

# To invoke the Pipeline that links outputs
kubectl apply -f examples/run/output-pipelinerun.yaml
kubectl apply -f examples/pipelineruns/output-pipelinerun.yaml

# To invoke the TaskRun with embedded Resource spec and task Spec
kubectl apply -f examples/run/resource-spec-taskrun.yaml
kubectl apply -f examples/taskruns/resource-spec-taskrun.yaml
```

## Example Pipelines

### Simple Pipelines

[The simple Pipeline](pipeline.yaml) 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 k8s `Deployment` in the skaffold repos's 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](default-cluster-admin.yaml)).

#### Simple Tasks

The [Tasks](../docs/tasks.md) used by the simple examples are:

- [build-task.yaml](build-task.yaml): Builds an image via
[kaniko](https://github.com/GoogleContainerTools/kaniko) and pushes it to
registry.
- [deploy-task.yaml](deploy-task.yaml): This task deploys with
`kubectl apply -f <filename>`

#### Simple Runs

The [run](./run/) directory contains an example [TaskRun](../docs/taskruns.md)
and an example [PipelineRun](../docs/pipelineruns.md):

- [task-run.yaml](./run/task-run.yaml) shows an example of how to manually run
the `build-push` task
- [pipeline-run.yaml](./run/pipeline-run.yaml) invokes
[the example pipeline](#example-pipeline)
- [embed-resource-spec.yaml](./run/task-run-resource-spec.yaml) shows an example
how to create TaskRun with embedded Task spec and resource spec.
## Results
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooo nice! maybe put a link to this section at the top?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just bumping this 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README is pretty small so is there any value in having link at top?

You can track the progress of your taskruns and pipelineruns with this command, which will also
format the output nicely.

### Pipeline with outputs

[The Pipeline with outputs](output-pipeline.yaml) contains a Pipeline that
demonstrates how the outputs of a `Task` can be given as inputs to the next
`Task`. It does this by:

1. Running a `Task` that writes to a `PipelineResource`
2. Running a `Task` that reads the written value from the `PipelineResource`

The [`Output`](../docs/tasks.md#outputs) of the first `Task` is given as an
[`Input`](../docs/tasks.md#inputs) to the next `Task` thanks to the
[`from`](../docs/pipelines.md#from) clause.

#### Output Tasks

The two [Tasks](../docs/tasks.md) used by the output Pipeline are in
[output-tasks.yaml](output-tasks.yaml):

- `create-file`: Writes "some stuff" to a predefined path in the `workspace`
`git` `PipelineResource`
- `check-stuff-file-exists`: Reads a file from a predefined path in the
`workspace` `git` `PipelineResource`

These work together when combined in a `Pipeline` because the git resource used
as an [`Output`](../docs/tasks.md#outputs) of the `create-file` `Task` can be an
[`Input`](../docs/tasks.md#inputs) of the `check-stuff-file-exists` `Task`.

#### Output Runs

The [run](./run/) directory contains an example
[PipelineRun](../docs/pipelineruns.md) that invokes this `Pipeline` in
[`run/output-pipeline-run.yaml`](./run/output-pipeline-run.yaml).

### Accessing private docker image

The [run](./run/) directory contains an example
[TaskRun](../docs/Concepts.md#taskrun) with an embedded taskSpec, that pull a
private image from `gcr.io`, see
[`run/private-taskrun.yaml`](./run/private-taskrun.yaml).

This _run_ requires the secrets from [`0-secrets.yaml`](`0-secrets.yaml`) and
service accounts from [`1-bots.yaml`](`1-bots.yaml`) to be able to pull the
private image.
```shell
$ kubectl get taskruns -o=custom-columns-file=./test/columns.txt
NAME TYPE STATUS START
test-git-branch Succeeded True 2019-02-11T21:21:03Z
test-git-ref Succeeded True 2019-02-11T21:21:02Z
test-git-tag Succeeded True 2019-02-11T21:21:02Z
```

It uses `kubernetes.io/dockercfg` secret type but,
`kubernetes.io/dockerconfigjson` and
[Knative flavored credentials](https://github.com/knative/docs/blob/master/build/auth.md#guiding-credential-selection)
are supported too.
```shell
$ kubectl get pipelineruns -o=custom-columns-file=./test/columns.txt
NAME TYPE STATUS START
demo-pipeline-run-1 Succeeded True 2019-02-11T21:21:03Z
output-pipeline-run Succeeded True 2019-02-11T21:35:43Z
```
29 changes: 0 additions & 29 deletions examples/build-task.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions examples/default-cluster-admin.yaml

This file was deleted.

39 changes: 0 additions & 39 deletions examples/deploy-task.yaml

This file was deleted.

27 changes: 0 additions & 27 deletions examples/output-pipeline.yaml

This file was deleted.

40 changes: 0 additions & 40 deletions examples/output-tasks.yaml

This file was deleted.

Loading