forked from lrochette/CorpSite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodefresh.yml
260 lines (239 loc) · 7.15 KB
/
codefresh.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
version: '1.0'
stages:
- clone
- build
- dev
- prod
- post
steps:
init:
type: parallel
stage: clone
steps:
clone:
title: Cloning repository
type: git-clone
git: github
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
revision: ${{CF_REVISION}}
stage: clone
calculateDate:
image: ubuntu:latest
stage: prod
commands:
- |
START_DATE=`date -u '+%Y-%m-%d %H:%M:%S'`
END_DATE=`date -u -d '+1 day' '+%Y-%m-%d %H:%M:%S'`
echo START_DATE=\"$START_DATE\" >> ${{CF_VOLUME_PATH}}/env_vars_to_export
echo END_DATE=\"$END_DATE\" >> ${{CF_VOLUME_PATH}}/env_vars_to_export
getVersion:
title: "Get the image version from the repo"
image: codefresh/cli
working_directory: "${{clone}}"
stage: build
commands:
- |
export VERSION=$(cat version.txt | tr -d '\n')
cf_export IMAGE_VERSION=$VERSION
cf_export IMAGE=lrochette/globex:$VERSION
build_application:
title: "Building Globex website"
image: maven:3.3-jdk-8
working_directory: "${{clone}}"
tag: "${{CF_BRANCH_TAG_NORMALIZED}}"
commands:
- mvn -Dmaven.repo.local=/codefresh/volume/m2_repository package
stage: build
build_image:
title: "Building tomcat container"
type: build
registry: docker
image_name: "lrochette/globex"
working_directory: "${{clone}}"
tags:
- "${{CF_BRANCH_TAG_NORMALIZED}}"
- ${{IMAGE_VERSION}}
dockerfile: "Dockerfile"
disable_push: false
stage: build
on_success:
annotations:
set:
- annotations:
- sha: ${{CF_SHORT_REVISION}}
- version: ${{IMAGE_VERSION}}
display: version
jira:
type: parallel
stage: build
fail_fast: false
steps:
jira-issue-extractor:
title: Enrich image with annotations
type: jira-issue-extractor
stage: "build"
arguments:
IMAGE: 'docker.io/lrochette/globex:${{CF_SHORT_REVISION}}'
JIRA_PROJECT_PREFIX: 'FT'
MESSAGE: '${{CF_COMMIT_MESSAGE}}'
JIRA_API_TOKEN: ${{JIRA_API_KEY}}
JIRA_EMAIL: ${{JIRA_USER}}
JIRA_HOST: ${{JIRA_URL}}
#JIRA_CONTEXT: jira
JiraCommentCreate:
title: "Add Jira Comment"
type: "jira-issue-manager"
fail_fast: false
arguments:
JIRA_API_KEY: ${{JIRA_API_KEY}}
JIRA_BASE_URL: ${{JIRA_URL}}
JIRA_USERNAME: ${{JIRA_USER}}
JIRA_ISSUE_SOURCE_FIELD: 'FT-50'
ACTION: "comment_create"
COMMENT_BODY: "Build to change location in Codefresh build [${{CF_BUILD_ID}}|${{CF_BUILD_URL}}] finished in Codefresh."
enrich-image:
title: Enrich image with annotations
type: image-enricher
stage: test
arguments:
IMAGE: 'lrochette/globex:${{CF_SHORT_REVISION}}'
BRANCH: '${{CF_BRANCH}}'
REPO: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}'
GIT_PROVIDER_NAME: github
clone_dev:
title: Cloning Gitops repository
type: git-clone
git: github
repo: ${{CF_REPO_OWNER}}/csdp_applications
revision: main
stage: dev
updateVersion_dev:
title: update the version of the image
stage: dev
image: codefresh/cli
working_directory: "${{clone_dev}}/kustomize/globex/overlays/dev"
commands:
- ls
- yq -iY '.spec.template.spec.containers[0].image=env.IMAGE' deployment.yaml
GitCommit_dev:
title: Commit new image version to Git
stage: dev
type: git-commit
arguments:
repo: ${{CF_REPO_OWNER}}/csdp_applications
git: github
working_directory: "/codefresh/volume/csdp_applications/kustomize/globex/overlays/dev"
commit_message: "update image to ${{IMAGE_VERSION}}"
git_user_name: lrochette
git_user_email: [email protected]
allow_empty: true
rebase: true
force_push: true
add:
- deployment.yaml
startDemo:
stage: dev
description: "Wait for demo"
type: pending-approval
timeout:
duration: 24
timeUnit: hours
finalState: denied
createCR:
type: service-now:${{VERSION}}
title: Create Service Now Change Request
stage: prod
arguments:
CR_ACTION: createCR
DEBUG: true
SN_USER: admin
SN_PASSWORD: '${{SN_PASSWORD}}'
SN_INSTANCE: ${{SN_INSTANCE}}
TOKEN: ${{CF_TOKEN}}
CR_CONFLICT_POLICY: ignore
CR_DATA: >-
{
"short_description": "Application deployment to Prod",
"description": "Change for build ${{CF_BUILD_ID}}\nThis change was created by the Codefresh plugin",
"justification": "I do not need a justification\nMy app is awesome",
"cmdb_ci":"tomcat",
"start_date":${{START_DATE}},
"end_date":${{END_DATE}}
}
approval:
stage: prod
description: "Approval to deploy to PROD"
type: pending-approval
timeout:
duration: 2
timeUnit: hours
finalState: denied
modifyCR:
stage: prod
title: "Modify the implementation plan"
type: service-now:${{VERSION}}
fail_fast: false
arguments:
CR_ACTION: updateCR
CR_SYSID: ${{CR_SYSID}}
SN_USER: admin
SN_PASSWORD: '${{SN_PASSWORD}}'
SN_INSTANCE: ${{SN_INSTANCE}}
CR_DATA: '{"implementation_plan":"The implementation has been approved."}'
updateVersion_prod:
title: update the version of the image for prod deployment
stage: prod
image: codefresh/cli
working_directory: "${{clone_dev}}/kustomize/globex/overlays/prod"
commands:
- ls
- yq -iY '.spec.template.spec.containers[0].image=env.IMAGE' deployment.yaml
GitCommit_prod:
title: Commit new image version to Git
stage: prod
type: git-commit
arguments:
repo: ${{CF_REPO_OWNER}}/csdp_applications
git: github
working_directory: "/codefresh/volume/csdp_applications/kustomize/globex/overlays/prod"
commit_message: "update image to ${{IMAGE_VERSION}}"
git_user_name: lrochette
git_user_email: [email protected]
allow_empty: true
rebase: true
force_push: true
add:
- deployment.yaml
modifyTestPlan:
stage: post
title: "Modify the test plan"
type: service-now:${{VERSION}}
fail_fast: false
arguments:
CR_ACTION: updateCR
CR_SYSID: ${{CR_SYSID}}
SN_USER: admin
SN_PASSWORD: '${{SN_PASSWORD}}'
SN_INSTANCE: ${{SN_INSTANCE}}
CR_DATA: '{"test_plan":"The testing suite has passed."}'
wait2:
stage: post
title: are we ready to close?
type: pending-approval
timeout:
duration: 30
timeUnit: minutes
finalState: approved
closeCR:
type: service-now:${{VERSION}}
title: Close Service Now Change Request
stage: post
arguments:
CR_ACTION: closeCR
CR_SYSID: ${{CR_SYSID}}
SN_USER: admin
SN_PASSWORD: '${{SN_PASSWORD}}'
SN_INSTANCE: ${{SN_INSTANCE}}
CR_CLOSE_CODE: "successful"
CR_CLOSE_NOTES: "Closed automatically by Codefresh build ${{CF_BUILD_ID}}"
CR_DATA: '{"work_notes":"this is a message for the work notes"}'