@@ -2,20 +2,36 @@ apiVersion: tekton.dev/v1beta1
2
2
kind : Task
3
3
metadata :
4
4
name : green
5
+ labels :
6
+ app.kubernetes.io/version : " 0.1"
7
+ annotations :
8
+ tekton.dev/categories : Testing
9
+ tekton.dev/pipelines.minVersion : " 0.17.0"
10
+ tekton.dev/tags : python, green
11
+ tekton.dev/displayName : " green tests"
12
+ tekton.dev/platforms : " linux/amd64"
5
13
spec :
6
14
workspaces :
7
15
- name : source
8
16
description : >-
9
17
This task can be used to perform unit tests with green.
10
18
11
- If you define an environment variable called DATABASE_URI
12
- it will surface that in the test environment so that you
13
- can use it to connect to a test database.
19
+ If you define a secret with the key `database_uri`
20
+ it will create an environment variable named DATABASE_URI
21
+ that can be used to connect to a test database.
14
22
params :
15
23
- name : ARGS
16
24
description : The additional arguments to be used with green
17
25
type : string
18
26
default : " -vvv --processes=1 --run-coverage --minimum-coverage=95"
27
+ - name : SECRET_NAME
28
+ description : The name of the secret containing a database_uri key
29
+ type : string
30
+ default : " postgres-creds"
31
+ - name : SECRET_KEY
32
+ description : The name of the key that contains the database uri
33
+ type : string
34
+ default : " database_uri"
19
35
steps :
20
36
- name : green
21
37
image : python:3.11-slim
@@ -24,15 +40,108 @@ spec:
24
40
- name : DATABASE_URI
25
41
valueFrom :
26
42
secretKeyRef :
27
- name : postgres-creds
28
- key : database_uri
43
+ name : $(params.SECRET_NAME)
44
+ key : $(params.SECRET_KEY)
29
45
script : |
30
46
#!/bin/bash
31
47
set -e
32
48
33
49
echo "***** Installing dependencies *****"
34
50
python -m pip install --upgrade pip wheel
35
- pip install -r requirements.txt
51
+ pip install -qr requirements.txt
36
52
37
53
echo "***** Running Tests *****"
38
54
green $(params.ARGS)
55
+
56
+ ---
57
+ apiVersion : tekton.dev/v1beta1
58
+ kind : Task
59
+ metadata :
60
+ name : deploy-image
61
+ labels :
62
+ app.kubernetes.io/version : " 0.1"
63
+ annotations :
64
+ tekton.dev/categories : Deployment
65
+ tekton.dev/pipelines.minVersion : " 0.17.0"
66
+ tekton.dev/tags : openshift, deploy
67
+ tekton.dev/displayName : " deploy image"
68
+ tekton.dev/platforms : " linux/amd64"
69
+ spec :
70
+ workspaces :
71
+ - name : source
72
+ description : >-
73
+ This task will update the deployment.yaml with the latest image name
74
+ and then apply that yaml file and it's service file.
75
+ params :
76
+ - name : old_image_name
77
+ description : The fully qualified name of the old image to replace
78
+ type : string
79
+ - name : image_name
80
+ description : The fully qualified name of the new image to deploy
81
+ type : string
82
+ - name : manifest_dir
83
+ description : The directory in source that contains yaml manifests
84
+ type : string
85
+ default : " k8s"
86
+ steps :
87
+ - name : deploy
88
+ image : quay.io/openshift/origin-cli:latest
89
+ workingDir : /workspace/source
90
+ command : ["/bin/bash", "-c"]
91
+ args :
92
+ - |-
93
+ #!/bin/bash
94
+ set -e
95
+
96
+ echo Applying manifests in $(inputs.params.manifest_dir) directory
97
+
98
+ echo "********************* DEPLOYMENT ***********************"
99
+ echo "Deploying $(inputs.params.image_name) ..."
100
+
101
+ sed -i 's|'"$(inputs.params.old_image_name)"'|'"$(inputs.params.image_name)"'|g' $(inputs.params.manifest_dir)/deployment.yaml
102
+ cat $(inputs.params.manifest_dir)/deployment.yaml
103
+
104
+ echo "************************************************************"
105
+ echo "OC APPLY..."
106
+ oc apply -f $(inputs.params.manifest_dir)/deployment.yaml
107
+ oc apply -f $(inputs.params.manifest_dir)/service.yaml
108
+
109
+ echo "************************************************************"
110
+ sleep 3
111
+ echo "Pods:"
112
+ oc get pods
113
+ echo ""
114
+
115
+ ---
116
+ apiVersion : tekton.dev/v1beta1
117
+ kind : Task
118
+ metadata :
119
+ name : apply-manifests
120
+ labels :
121
+ app.kubernetes.io/version : " 0.1"
122
+ annotations :
123
+ tekton.dev/categories : Deployment
124
+ tekton.dev/pipelines.minVersion : " 0.17.0"
125
+ tekton.dev/tags : openshift, deploy
126
+ tekton.dev/displayName : " deploy"
127
+ tekton.dev/platforms : " linux/amd64"
128
+ spec :
129
+ workspaces :
130
+ - name : source
131
+ description : >-
132
+ This task will deploy all of the yaml files in the manifest folder.
133
+ params :
134
+ - name : manifest_dir
135
+ description : The directory in source that contains yaml manifests
136
+ type : string
137
+ default : " k8s"
138
+ steps :
139
+ - name : apply
140
+ image : quay.io/openshift/origin-cli:latest
141
+ workingDir : /workspace/source
142
+ command : ["/bin/bash", "-c"]
143
+ args :
144
+ - |-
145
+ echo Applying manifests in $(inputs.params.manifest_dir) directory
146
+ oc apply -f $(inputs.params.manifest_dir)
147
+ echo -----------------------------------
0 commit comments