Skip to content

Commit 379c24b

Browse files
authored
Update tekton example README and file names (#65)
1 parent 3ecb894 commit 379c24b

File tree

14 files changed

+132
-86
lines changed

14 files changed

+132
-86
lines changed

docs/README.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

docs/gitconfig

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/promoterun.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/promotesecret.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

tekton-example/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Tekton Pipeline/Task Example
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.
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.
6+
7+
## Template Files
8+
9+
- `auth.yaml`: Creates secrets for a GitHub repository and Docker registry, an access token for the GitHub repository and the ServiceAccount
10+
- `resources.yaml`: Creates PipelineResources for GitHub and Docker repositories
11+
12+
## Other Files
13+
- `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+
- `service-promote-pipeline-run.yaml`: Creates a PipelineRun that executes the `service-promote-pipeline` - This will build the code and promote it to a repository you have specified
16+
- `promote.yaml`: Creates a pull request from one repository to another repository
17+
- `promote-run.yaml`: Creates a TaskRun that executes a task promoting from a testing repository to a production repository
18+
- `build-task.yaml`: This task builds a git source into a docker image and pushes to a docker registry
19+
- `gitconfig`: Data file for the configmap - includes a GitHub user ID and email address
20+
21+
## Pre-requisites
22+
23+
- You will need two repositories for this example, one to promote from and one to promote to
24+
- For the repository to promote from, an example can be forked from here: https://github.com/akihikokuroda/promote-demo
25+
- For the repository to promote to, an example can be forked from here:
26+
https://github.com/akihikokuroda/gitops-test
27+
28+
## Create Tekton Resources
29+
30+
- Create a new namespace:
31+
```shell
32+
kubectl create ns <namespace>
33+
```
34+
35+
- Modify your Kubernetes context to use this namespace by default:
36+
```shell
37+
kubectl config set-context --current --namespace=<namespace>
38+
```
39+
40+
- Apply the resources folder:
41+
```shell
42+
kubectl apply -f resources
43+
```
44+
45+
- Edit all 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.
46+
47+
- Apply the templates folder:
48+
```shell
49+
kubectl apply -f templates
50+
```
51+
- Edit `gitconfig` to contain your GitHub username and email address
52+
53+
- Create a configmap:
54+
```shell
55+
kubectl create configmap promote-configmap --from-file=gitconfig
56+
```
57+
This will store your GitHub username and email address in key-value pairs that can be used in the PipelineRun.
58+
59+
- Edit `service-promote-pipeline-run.yaml` to contain the name of the repository you want to promote to
60+
61+
## Execute Pipeline
62+
63+
`service-promote-pipeline-run` 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).
64+
65+
- Create `service-promote-pipeline-run`:
66+
```shell
67+
kubectl create -f service-promote-pipeline-run.yaml
68+
```
69+
70+
## Promote to Prod
71+
72+
You can use `promote-run.yaml` to 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 clone: https://github.com/a-roberts/gitops-repo-testing
73+
74+
- Edit `promote-run.yaml` to contain the URL of the repository you want to promote from, and the URL of the repository you want to promote to
75+
76+
- Create the `promote-run` TaskRun:
77+
```shell
78+
kubectl create -f promote-run.yaml
79+
```
80+
81+
You can view the progress of your PipelineRun using:
82+
```shell
83+
kubectl get pod <name of pod>
84+
```
85+
Or alternatively view its progress in the Tekton Dashboard.
86+
87+
The PipelineRun will clone the code from the inital 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.
88+

tekton-example/gitconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[user]
2+
name = REPLACE_ME.GITHUB_USERNAME
3+
email = REPLACE_ME.GITHUB_EMAIL

tekton-example/promote-run.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: TaskRun
3+
metadata:
4+
generateName: promote-run-
5+
spec:
6+
params:
7+
- name: github-secret
8+
value: promote-secret
9+
- name: github-config
10+
value: promote-configmap
11+
- name: from
12+
value: "https://github.com/REPLACE_ME.OWNER/REPLACE_ME.GITHUB_TESTING_REPO"
13+
- name: to
14+
value: "https://github.com/REPLACE_ME.OWNER/REPLACE_ME.GITHUB_PROD_REPO"
15+
- name: service
16+
value: service-a
17+
taskRef:
18+
name: promote
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
params:
77
- name: github-secret
88
type: string
9-
description: seret name of the github that has the access token. The key name is token.
9+
description: secret name of the github that has the access token. The key name is token.
1010
- name: from
1111
type: string
1212
description: github repository url to be promoted from
@@ -18,7 +18,7 @@ spec:
1818
description: service name to be promoted
1919
- name: github-config
2020
type: string
21-
description: configmap name of the gitconfig file that has user name, user e-mail. The key name is gitconfig. It can be created by "kubectl create configmap <configmap name> --from-file=gitconfig -n promote"
21+
description: configmap name of the gitconfig file that has user name, user e-mail
2222
volumes:
2323
- name: gitconfig
2424
configMap:
@@ -28,8 +28,7 @@ spec:
2828
path: gitconfig
2929
steps:
3030
- name: promote
31-
#image: akihikokuroda/promote
32-
image: <image name>
31+
image: quay.io/redhat-developer/gitops-cli
3332
imagePullPolicy: Always
3433
volumeMounts:
3534
- name: gitconfig

docs/servicepromotepipeline.yaml renamed to tekton-example/resources/service-promote-pipeline.yaml

File renamed without changes.

0 commit comments

Comments
 (0)