1
+ # These are custom tasks that are not on Tekton Hub
2
+ ---
3
+ apiVersion : tekton.dev/v1beta1
4
+ kind : Task
5
+ metadata :
6
+ name : pylint
7
+ labels :
8
+ app.kubernetes.io/version : " 0.4"
9
+ annotations :
10
+ tekton.dev/categories : Code Quality
11
+ tekton.dev/pipelines.minVersion : " 0.17.0"
12
+ tekton.dev/tags : python, pylint, poetry
13
+ tekton.dev/displayName : " pylint"
14
+ tekton.dev/platforms : " linux/amd64,linux/s390x,linux/ppc64le"
15
+ spec :
16
+ workspaces :
17
+ - name : source
18
+ description : The workspace with the source code.
19
+ description : >-
20
+ Use to run pylint on the provided input source. If Poetry is being used
21
+ it will detect the poetry.lock file and install via requirements export.
22
+ params :
23
+ - name : image
24
+ description : The container image with pylint
25
+ default : docker.io/python:3.11-slim
26
+ - name : path
27
+ description : The path to the module which should be analyzed by pylint
28
+ default : " ."
29
+ type : string
30
+ - name : args
31
+ description : The arguments to pass to the pylint CLI.
32
+ type : array
33
+ default : []
34
+ - name : requirements_file
35
+ description : The name of the requirements file inside the source location
36
+ default : " requirements.txt"
37
+ steps :
38
+ - name : pylint
39
+ image : $(params.image)
40
+ workingDir : $(workspaces.source.path)
41
+ script : |
42
+ #!/bin/bash
43
+ set -e
44
+ export PATH=$PATH:$HOME/.local/bin:
45
+
46
+ echo "***** Installing dependencies *****"
47
+ if [ -e "poetry.lock" ]; then
48
+ echo "Found poetry.lock file: using poetry "
49
+ python -m pip install poetry poetry-plugin-export
50
+ poetry export --with=dev -f requirements.txt --output requirements.txt
51
+ python -m pip install --user -r requirements.txt
52
+ elif [ -n "$(params.requirements_file)" ] && [ -e "$(params.requirements_file)" ]; then
53
+ python -m pip install --user -r "$(params.requirements_file)"
54
+ fi
55
+
56
+ # Make sure pylint is installed
57
+ python -m pip install pylint
58
+
59
+ echo "***** Running Linting *****"
60
+ pylint $@ "$(params.path)"
61
+ args :
62
+ - " $(params.args)"
63
+
64
+ ---
1
65
apiVersion : tekton.dev/v1beta1
2
66
kind : Task
3
67
metadata :
4
- name : green
68
+ name : pytest-env
5
69
labels :
6
70
app.kubernetes.io/version : " 0.1"
7
71
annotations :
8
72
tekton.dev/categories : Testing
9
73
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"
74
+ tekton.dev/tags : python, pytest
75
+ tekton.dev/displayName : " pytest tests"
76
+ tekton.dev/platforms : " linux/amd64,linux/s390x,linux/ppc64le "
13
77
spec :
14
78
workspaces :
15
79
- name : source
16
80
description : >-
17
- This task can be used to perform unit tests with green.
81
+ This task can be used to perform unit tests with pytest.
82
+ It supports both requirements.txt and poetry.lock files.
18
83
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.
84
+ It also has the ability to create an environment variable
85
+ that is sourced from a Secret. This allows you to define
86
+ credentials that can be used to connect to a test database.
22
87
params :
23
- - name : ARGS
24
- description : The additional arguments to be used with green
25
- type : string
26
- default : " -vvv --processes=1 --run-coverage --minimum-coverage=95 "
88
+ - name : PYTEST_ARGS
89
+ description : The arguments to pass to the pytest CLI.
90
+ type : array
91
+ default : []
27
92
- name : SECRET_NAME
28
93
description : The name of the secret containing a database_uri key
29
94
type : string
33
98
type : string
34
99
default : " database_uri"
35
100
steps :
36
- - name : green
37
- image : python:3.11-slim
101
+ - name : pytest
102
+ image : docker.io/ python:3.11-slim
38
103
workingDir : $(workspaces.source.path)
39
104
env :
40
105
- name : DATABASE_URI
@@ -45,13 +110,26 @@ spec:
45
110
script : |
46
111
#!/bin/bash
47
112
set -e
113
+ export PATH=$PATH:$HOME/.local/bin:
48
114
49
115
echo "***** Installing dependencies *****"
50
- python -m pip install --upgrade pip wheel
51
- pip install -qr requirements.txt
116
+ if [ -e "poetry.lock" ]; then
117
+ echo "Found poetry.lock file: using poetry "
118
+ python -m pip install poetry poetry-plugin-export
119
+ poetry export --with=dev -f requirements.txt --output requirements.txt
120
+ python -m pip install --user -r requirements.txt
121
+ elif -e "requirements.txt" ]; then
122
+ python -m pip install --user -r requirements.txt
123
+ fi
124
+
125
+ # Make sure pylint is installed
126
+ python -m pip install pytest
52
127
53
128
echo "***** Running Tests *****"
54
- green $(params.ARGS)
129
+ pytest --version
130
+ pytest
131
+ args :
132
+ - " $(params.PYTEST_ARGS)"
55
133
56
134
---
57
135
apiVersion : tekton.dev/v1beta1
73
151
This task will update the deployment.yaml with the latest image name
74
152
and then apply that yaml file and it's service file.
75
153
params :
76
- - name : old_image_name
77
- description : The fully qualified name of the old image to replace
78
- type : string
79
154
- name : image_name
80
155
description : The fully qualified name of the new image to deploy
81
156
type : string
@@ -95,10 +170,17 @@ spec:
95
170
96
171
echo Applying manifests in $(inputs.params.manifest_dir) directory
97
172
173
+ echo "**********************************************************************"
174
+ echo "Installing YQ..."
175
+ echo "**********************************************************************"
176
+ wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
177
+ chmod a+x /usr/bin/yq
178
+
98
179
echo "********************* DEPLOYMENT ***********************"
99
180
echo "Deploying $(inputs.params.image_name) ..."
100
181
101
- sed -i 's|'"$(inputs.params.old_image_name)"'|'"$(inputs.params.image_name)"'|g' $(inputs.params.manifest_dir)/deployment.yaml
182
+ yq -e -i '.spec.template.spec.containers[0].image="$(inputs.params.image_name)"' $(inputs.params.manifest_dir)/deployment.yaml
183
+ # sed -i 's|'"$(inputs.params.old_image_name)"'|'"$(inputs.params.image_name)"'|g' $(inputs.params.manifest_dir)/deployment.yaml
102
184
cat $(inputs.params.manifest_dir)/deployment.yaml
103
185
104
186
echo "************************************************************"
@@ -145,3 +227,60 @@ spec:
145
227
echo Applying manifests in $(inputs.params.manifest_dir) directory
146
228
oc apply -f $(inputs.params.manifest_dir)
147
229
echo -----------------------------------
230
+
231
+ ---
232
+ apiVersion : tekton.dev/v1beta1
233
+ kind : Task
234
+ metadata :
235
+ name : behave
236
+ labels :
237
+ app.kubernetes.io/version : " 0.1"
238
+ annotations :
239
+ tekton.dev/categories : Testing
240
+ tekton.dev/pipelines.minVersion : " 0.17.0"
241
+ tekton.dev/tags : python, bdd, behave
242
+ tekton.dev/displayName : " bdd tests"
243
+ tekton.dev/platforms : " linux/amd64"
244
+ spec :
245
+ workspaces :
246
+ - name : source
247
+ description : >-
248
+ This task can be used to perform bdd tests with behave.
249
+ params :
250
+ - name : BASE_URL
251
+ description : The url of the application to test
252
+ type : string
253
+ - name : WAIT_SECONDS
254
+ description : The number of seconds to wait for a reply
255
+ type : string
256
+ default : " 60"
257
+ - name : DRIVER
258
+ description : The web driver to use (chrome or firefox)
259
+ type : string
260
+ default : " chrome"
261
+ steps :
262
+ - name : behave
263
+ image : rofrano/pipeline-selenium
264
+ workingDir : $(workspaces.source.path)
265
+ env :
266
+ - name : BASE_URL
267
+ value : $(params.BASE_URL)
268
+ - name : WAIT_SECONDS
269
+ value : $(params.WAIT_SECONDS)
270
+ - name : DRIVER
271
+ value : $(params.DRIVER)
272
+ script : |
273
+ #!/bin/bash
274
+ set -e
275
+ export PATH=$PATH:$HOME/.local/bin:
276
+
277
+ echo "***** Installing dependencies *****"
278
+ if [ -e "poetry.lock" ]; then
279
+ echo "Found poetry.lock file: using poetry"
280
+ python -m pip install poetry poetry-plugin-export
281
+ poetry export --with=dev -f requirements.txt --output requirements.txt
282
+ fi
283
+ python -m pip install --user -r requirements.txt
284
+
285
+ echo "***** Running Tests *****"
286
+ behave
0 commit comments