Skip to content

Commit bc0bf71

Browse files
committed
Added Pipeline definition
1 parent 63e20f0 commit bc0bf71

File tree

3 files changed

+175
-52
lines changed

3 files changed

+175
-52
lines changed

.tekton/pipeline.yaml

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,33 @@ spec:
66
workspaces:
77
- name: pipeline-workspace
88
params:
9-
- name: GIT_REPO
10-
default: 'https://github.com/rofrano/lab-openshift.git'
11-
description: 'URL of repo to clone '
9+
- description: The URL to the git repo
10+
name: GIT_REPO
1211
type: string
13-
- name: GIT_BRANCH
14-
default: master
15-
description: Branch to clone
12+
- default: master
13+
description: The reference (branch or ref)
14+
name: GIT_REF
1615
type: string
17-
- name: IMAGE_NAME
18-
default: >-
19-
image-registry.openshift-image-registry.svc:5000/rofrano-dev/petstore:0.1.0
20-
description: Name of image to build
16+
- default: '-vvv --processes=1 --run-coverage --minimum-coverage=95'
17+
description: Arguments for green testing
18+
name: GREEN_ARGS
2119
type: string
22-
- name: GREEN_ARGS
23-
default: '-vvv --processes=1 --run-coverage --minimum-coverage=95'
24-
description: Arguments to geen command
25-
type: string
26-
- name: APP_NAME
27-
default: petstore
20+
- default: petshop
2821
description: Name of the application
22+
name: APP_NAME
23+
type: string
24+
- default: >-
25+
image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/$(params.APP_NAME):latest
26+
description: The name of the image to build
27+
name: IMAGE_NAME
2928
type: string
3029
tasks:
3130
- name: git-clone
3231
params:
3332
- name: url
3433
value: $(params.GIT_REPO)
3534
- name: revision
36-
value: $(params.GIT_BRANCH)
35+
value: $(params.GIT_REF)
3736
- name: refspec
3837
value: ''
3938
- name: submodules
@@ -69,25 +68,39 @@ spec:
6968
workspaces:
7069
- name: output
7170
workspace: pipeline-workspace
72-
- name: flake8
71+
- name: pylint
7372
params:
7473
- name: image
7574
value: 'docker.io/python:3.11-slim'
7675
- name: path
77-
value: .
76+
value: service
7877
- name: requirements_file
7978
value: requirements.txt
8079
- name: args
81-
value:
82-
- '--count'
83-
- '--max-complexity=10'
84-
- '--max-line-length=127'
85-
- '--statistics'
80+
value: []
81+
- name: pip_conf_file
82+
value: pip.conf
83+
runAfter:
84+
- git-clone
85+
taskRef:
86+
kind: Task
87+
name: pylint
88+
workspaces:
89+
- name: source
90+
workspace: pipeline-workspace
91+
- name: testing
92+
params:
93+
- name: ARGS
94+
value: $(params.GREEN_ARGS)
95+
- name: SECRET_NAME
96+
value: postgres-creds
97+
- name: SECRET_KEY
98+
value: database_uri
8699
runAfter:
87100
- git-clone
88101
taskRef:
89102
kind: Task
90-
name: flake8
103+
name: green
91104
workspaces:
92105
- name: source
93106
workspace: pipeline-workspace
@@ -115,37 +128,27 @@ spec:
115128
- name: SKIP_PUSH
116129
value: 'false'
117130
runAfter:
118-
- flake8
119-
- green
131+
- pylint
132+
- testing
120133
taskRef:
121134
kind: ClusterTask
122135
name: buildah
123136
workspaces:
124137
- name: source
125138
workspace: pipeline-workspace
126-
- name: green
139+
- name: deploy-image
127140
params:
128-
- name: ARGS
129-
value: $(params.GREEN_ARGS)
141+
- name: old_image_name
142+
value: 'cluster-registry:32000/petshop:latest'
143+
- name: image_name
144+
value: $(params.IMAGE_NAME)
145+
- name: manifest_dir
146+
value: k8s
130147
runAfter:
131-
- git-clone
148+
- buildah
132149
taskRef:
133150
kind: Task
134-
name: green
151+
name: deploy-image
135152
workspaces:
136153
- name: source
137154
workspace: pipeline-workspace
138-
- name: openshift-client
139-
params:
140-
- name: SCRIPT
141-
value: oc create deploy $(params.APP_NAME) --image $(params.IMAGE_NAME)
142-
- name: VERSION
143-
value: latest
144-
runAfter:
145-
- buildah
146-
taskRef:
147-
kind: ClusterTask
148-
name: openshift-client
149-
workspaces:
150-
- name: manifest-dir
151-
workspace: pipeline-workspace

.tekton/tasks.yaml

Lines changed: 115 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,36 @@ apiVersion: tekton.dev/v1beta1
22
kind: Task
33
metadata:
44
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"
513
spec:
614
workspaces:
715
- name: source
816
description: >-
917
This task can be used to perform unit tests with green.
1018
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.
1422
params:
1523
- name: ARGS
1624
description: The additional arguments to be used with green
1725
type: string
1826
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"
1935
steps:
2036
- name: green
2137
image: python:3.11-slim
@@ -24,15 +40,108 @@ spec:
2440
- name: DATABASE_URI
2541
valueFrom:
2642
secretKeyRef:
27-
name: postgres-creds
28-
key: database_uri
43+
name: $(params.SECRET_NAME)
44+
key: $(params.SECRET_KEY)
2945
script: |
3046
#!/bin/bash
3147
set -e
3248
3349
echo "***** Installing dependencies *****"
3450
python -m pip install --upgrade pip wheel
35-
pip install -r requirements.txt
51+
pip install -qr requirements.txt
3652
3753
echo "***** Running Tests *****"
3854
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 -----------------------------------

.tekton/workspace.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: pipeline-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 500Mi
11+
volumeMode: Filesystem

0 commit comments

Comments
 (0)