You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tekton-example/README.md
+58-16Lines changed: 58 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,23 @@
1
1
# Tekton Pipeline/Task Example
2
2
3
-
An example of using `promote` in a Tekton Pipeline to promote a service's config to a GitOps repository. Creation of the PipelineRun (using `service-promote-pipeline-run.yaml`) will drive the pipeline to clone, build and push the service and then promote the config from the local clone into your staging/test GitOps repository.
3
+
An example of using `promote` in a Tekton Pipeline to promote a service's config to a GitOps repository. Creation of the PipelineRun will drive the pipeline to clone, build and push the service and then promote the config from the local clone into your staging/test GitOps repository.
4
4
5
-
Creation of a TaskRun (using `promote-run.yaml`) will then further promote from one GitOps repo to another, e.g. from staging to production.
5
+
## Tekton APIs: v1alpha1 and v1beta1
6
+
7
+
Tekton Pipelines introduced new [v1beta1](https://github.com/tektoncd/pipeline/blob/master/docs/migrating-v1alpha1-to-v1beta1.md) APIs with its 0.11.x release. We first developed this sample against v1alpha1 APIs, but now include both v1alpha1 and v1beta1 versions of this sample. The v1beta1 version uses no Tekton PipelineResources, in the spirit of [this](https://github.com/tektoncd/pipeline/blob/master/docs/migrating-v1alpha1-to-v1beta1.md#replacing-pipelineresources-with-tasks) section of the migration document. You should use Tekton Pipelines v0.12.1 or higher and the v1beta1 samples unless you are unable to do so, or wish to use the code in the final section, 'Promote to Next Managed Environment'. This has only been implemented under the v1alpha1 sample. We're still working through how promotion between GitOps repositories should work, so this last section is fairly expermimental.
6
8
7
9
## Template Files
8
10
9
11
-`auth.yaml`: Creates secrets for a GitHub repository and image registry, an access token for the GitHub repository and the ServiceAccount
10
-
-`resources.yaml`: Creates PipelineResources for GitHub and Docker repositories
12
+
-`resources.yaml`: Creates PipelineResources for GitHub and Docker repositories. This file only exists in the v1alpha1 sample.
11
13
12
14
## Other Files
15
+
13
16
-`service-promote.yaml`: This is the Tekton Task used for promoting from one repository to another. It creates a PullRequest and this represents the promotion from one environment to another (for example, from development to production - in this case represented as repositories)
14
-
-`service-promote-pipeline.yaml`: Creates a Pipeline that executes `build-task.yaml` and `service-promote.yaml`
15
-
-`promote.yaml`: Creates a pull request from one repository to another repository
17
+
-`service-promote-pipeline.yaml`: Creates a Pipeline that executes `build-task.yaml` and `service-promote.yaml`.
18
+
-`promote.yaml`: Creates a pull request from one repository to another repository.
16
19
-`build-task.yaml`: This task builds a Git source into a container image image and pushes to an image registry
20
+
-`git-clone.yaml`: A copy of the Tekton Catalog [git-clone](https://github.com/tektoncd/catalog/blob/v1beta1/git/git-clone.yaml) Task, replacing the Git PipelineResource used in v1alpha1.
17
21
18
22
## Pre-requisites
19
23
@@ -26,52 +30,90 @@ Creation of a TaskRun (using `promote-run.yaml`) will then further promote from
26
30
## Create Tekton Resources
27
31
28
32
- Create a new namespace:
33
+
29
34
```shell
30
35
kubectl create ns <namespace>
31
36
```
32
37
33
38
- Modify your Kubernetes context to use this namespace by default:
- Choose whether to use the `v1alpha1` or `v1beta1` resources. As per the introduction, we recommend Tekton 0.12.x+ and the `v1beta1` path unless you have clear reasons to choose `v1alpha1`.
45
+
46
+
```sh
47
+
cd v1beta1
48
+
# OR
49
+
cd v1alpha1
50
+
```
51
+
38
52
- Apply the resources folder:
39
-
```shell
53
+
54
+
```shell
40
55
kubectl apply -f resources
41
56
```
42
57
43
-
- Edit both files in the template folder to contain real values. Entries of the form `REPLACE_ME.x` must be replaced with the value you wish to use, i.e at occurences such as `REPLACE_ME.IMAGE_NAME`, `REPLACE_ME.GITHUB_ORG/REPLACE_ME.GITHUB_REPO` etc... There are eight instances to replace in this folder.
58
+
- Edit the files in the template folder to contain real values. Entries of the form `REPLACE_ME.x` must be replaced with the value you wish to use, i.e at occurences such as `REPLACE_ME.IMAGE_NAME`, `REPLACE_ME.GITHUB_ORG/REPLACE_ME.GITHUB_REPO` etc... There are eight instances to replace in the v1alpha1 templates/ folder and nine in the v1beta1 templates/ folder.
59
+
60
+
- If you are using v1alpha1 you can apply the templates folder:
44
61
45
-
- Apply the templates folder:
46
-
```shell
62
+
```shell
47
63
kubectl apply -f templates
48
64
```
49
65
66
+
If you are using v1beta1 then only apply templates/auth.yaml. The templates/ folder also contains a PipelineRun which we don't want to run yet.
67
+
68
+
```sh
69
+
kubectl apply -f templates/auth.yaml
70
+
```
71
+
50
72
## Execute Pipeline
51
73
52
74
The PipelineRun you will create is designed to build your microservice from its development repository and then promote the new configuration to a GitOps repository (representing a different environment, for example development, staging, test or production).
53
75
54
-
- To create the PipelineRun, use:
76
+
This example promotes from the `promote-demo` repository, containing a service with the same name.
77
+
78
+
- This creates a PipelineRun that executes the `service-promote-pipeline`, which will build the code and promote it to a repository you have specified
79
+
- The logs will be outputted to your console, and you can also view its progress in the Tekton Dashboard.
80
+
81
+
The exact steps to create a PipelineRun depend on whether you are using the v1alpha1 or v1beta1 APIs.
This example promotes from the `promote-demo` repository, containing a service with the same name.
91
+
### v1beta1
60
92
93
+
One of the main differences between our v1alpha1 and v1beta1 samples is that v1beta1 does not use a Tekton Git PipelineResource. Instead we use Tekton workspaces, which must be backed by persistent storage since they contain more than one task. Persistent storage requires a PersistentVolumeClaim. These can be dynamically generated using the `volumeClaimTemplate` stanza, but this is not supported in `tkn` until https://github.com/tektoncd/cli/issues/1006 is resolved. In the meantime we provide a PipelineRun:
61
94
62
-
- This creates a PipelineRun that executes the `service-promote-pipeline`, which will build the code and promote it to a repository you have specified
63
-
- The logs will be outputted to your console, and you can also view its progress in the Tekton Dashboard.
You will need to locate and tail the logs of this PipelineRun for yourself. For example you can use,
100
+
101
+
```sh
102
+
kubectl get pipelineruns
103
+
tkn pipelinerun logs [pipelinerun] -f
104
+
```
64
105
65
106
## Promote to Next Managed Environment
66
107
67
108
Optionally, you can run a subsequent promote from one GitOps repository to another (e.g staging to prod) after merging the pull request on your first GitOps repository. For this you will need a third repository, and for this you can fork: https://github.com/rhd-gitops-example/gitops-example-staging
68
109
69
-
-To do this second promote, you will need to create a TaskRun that executes a task promoting from a testing repository to a production repository
110
+
- To do this second promote, you will need to create a TaskRun that executes a task promoting from a testing repository to a production repository
70
111
- To create the TaskRun (again this uses a service called `promote-demo`), use:
This will start the TaskRun and output its logs, and you can also view its progress in the Tekton Dashboard.
75
118
76
119
The TaskRun will clone the code from the initial repository locally, build it and promote it to the final repository. This will open a pull request which you will be able to view in the repository you chose to promote to.
0 commit comments