-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodefresh.yml
222 lines (207 loc) · 8.89 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
version: '1.0'
stages:
- prepare
- build
- deploy
- postdeploy
steps:
#This file describes the deployment process for templateservicename
main_clone:
stage: prepare
title: Cloning main repository...
type: git-clone
repo: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}'
revision: '${{CF_REVISION}}'
git: gitlab
setup_variables:
stage: prepare
description: Sets variables for future steps
image: alpine:latest
working_directory: ${{main_clone}}
commands:
- export RJM_VERSION=$(cat ./VERSION)
- export RJM_VERSION_UNDERSCORE=$(cat ./VERSION | tr '.' '_')
- export RJM_MAJOR_VERSION=$(echo ${RJM_VERSION%%.*})
- export RJM_WS_NAME=$(echo "templateservicename")
- export RJM_DOCKER_SERVICE_NAME=${RJM_WS_NAME}_${RJM_VERSION_UNDERSCORE}
- export RJM_DOCKER_SERVICE_URL=tasks.${RJM_WS_NAME}_${RJM_VERSION_UNDERSCORE}
- export RJM_KONG_UPSTREAM_NAME=${RJM_WS_NAME}_${RJM_MAJOR_VERSION}
- export RJM_DOCKERWSCALLER_IMAGE="metcarob/docker-ws-caller:0.7.19"
- export RJM_BUILDQUASARAPP_IMAGE="metcarob/docker-build-quasar-app:0.0.28"
- export RJM_UNITTESTAPICONTIANER_IMAGE="metcarob/python_unittest_api_container:0.0.9"
- export RJM_DOCKER_KONG_API_URL="http://tasks.kong:8001"
- export MEMSET_CLOUD_ROOT=/memset_cloud
- export RJM_PYTHON_TEST_IMAGE="python:3.8.13-slim"
- cf_export RJM_VERSION=${RJM_VERSION}
- cf_export RJM_VERSION_UNDERSCORE=${RJM_VERSION_UNDERSCORE}
- cf_export RJM_MAJOR_VERSION=${RJM_MAJOR_VERSION}
- cf_export RJM_WS_NAME=${RJM_WS_NAME}
- cf_export RJM_DOCKER_SERVICE_NAME=${RJM_DOCKER_SERVICE_NAME}
- cf_export RJM_DOCKER_SERVICE_URL=${RJM_DOCKER_SERVICE_URL}
- cf_export RJM_KONG_UPSTREAM_NAME=${RJM_KONG_UPSTREAM_NAME}
- cf_export RJM_DOCKERWSCALLER_IMAGE=${RJM_DOCKERWSCALLER_IMAGE}
- cf_export RJM_BUILDQUASARAPP_IMAGE=${RJM_BUILDQUASARAPP_IMAGE}
- cf_export RJM_UNITTESTAPICONTIANER_IMAGE=${RJM_UNITTESTAPICONTIANER_IMAGE}
- cf_export RJM_DOCKER_KONG_API_URL=${RJM_DOCKER_KONG_API_URL}
- cf_export MEMSET_CLOUD_ROOT=${MEMSET_CLOUD_ROOT}
- cf_export RJM_PYTHON_TEST_IMAGE="${RJM_PYTHON_TEST_IMAGE}"
# These are the application unit tests
unit_test:
stage: build
description: Make sure all the unit tests pass
image: ${{RJM_PYTHON_TEST_IMAGE}}
working_directory: ${{main_clone}}/services
commands:
- pip3 install --no-cache-dir -r ./src/requirements.txt
- pip3 install --no-cache-dir -r ./testContainer/requirements.txt
- python3 -m pytest ./test
compile_frontend:
stage: build
description: Compile the frontend quasar application
image: ${{RJM_BUILDQUASARAPP_IMAGE}}
working_directory: ${{main_clone}}
commands:
- build_quasar_app ./frontend pwa ${{RJM_VERSION}}
build_the_image:
stage: build
working_directory: ${{main_clone}}
type: build
image_name: metcarob/${{RJM_WS_NAME}}
tag: ${{RJM_VERSION}}
build_the_test_image:
stage: build
working_directory: ${{main_clone}}/services/testContainer
type: build
image_name: metcarob/${{RJM_WS_NAME}}test
tag: develop
dockerfile: ./Dockerfile
free_disk_space:
stage: build
description: Free up disk space
image: alpine:latest
working_directory: ${{main_clone}}
commands:
- rm -rf ./webapp/node_modules
- rm -rf ./webapp/dist
container_level_tests:
stage: build
type: composition
title: Container level tests
composition:
version: '2'
services:
container_under_test:
image: ${{build_the_image}}
environment:
- APIAPP_JWTSECRET="someDummy3245SecretForTesting"
- APIAPP_APIURL=http://container_under_test:80/api
- APIAPP_APIDOCSURL=http://container_under_test:80/apidocs
- APIAPP_FRONTENDURL=http://container_under_test:80/frontend
- APIAPP_DEFAULTMASTERTENANTJWTCOLLECTIONALLOWEDORIGINFIELD="http://localhost"
- APIAPP_COMMON_ACCESSCONTROLALLOWORIGIN="http://localhost"
- APIAPP_OBJECTSTORECONFIG="{\"Type\":\"Memory\"}"
composition_candidates:
saas_user_management_systemtest:
image: ${{build_the_test_image}}
command: /run_tests_with_wait.sh
environment:
- TESTPARAM_EXPECTED_CONTAINER_VERSION=${{RJM_VERSION}}
- TESTPARAM_ENDPOINTURL="http://container_under_test"
- TESTPARAM_THROUGHKONG="False"
#Deploy new container to my website swarm
deploy_to_metcarob_swarm:
stage: deploy
image: codefresh/remote-docker
working_directory: ${{main_clone}}
commands:
- rdocker ${{RDOCKER_HOST}} docker login -u ${{RJM_DOCKERHUB_USER}} -p ${{RJM_DOCKERHUB_PASS}} \&\& docker service create
--with-registry-auth
--name ${RJM_DOCKER_SERVICE_NAME}
--network main_net
--secret saas_jwtsecret
-e APIAPP_APIURL=https://api.metcarob.com/templateservicename/v${{RJM_MAJOR_VERSION}}/public/api
-e APIAPP_APIDOCSURL=https://api.metcarob.com/templateservicename/v${{RJM_MAJOR_VERSION}}/public/web/apidocs
-e APIAPP_FRONTENDURL=https://api.metcarob.com/templateservicename/v${{RJM_MAJOR_VERSION}}/public/web/frontend
-e APIAPP_COMMON_ACCESSCONTROLALLOWORIGIN="https://api.metcarob.com,https://challengeswipe.com,http://platform.challengeswipe.com"
-e APIAPP_JWTSECRETFILE=/run/secrets/saas_jwtsecret
--secret templateservicename_objectstore_config_dynamodb_cached
-e APIAPP_OBJECTSTORECONFIGFILE=/run/secrets/templateservicename_objectstore_config_dynamodb_cached
metcarob/${RJM_WS_NAME}:${RJM_VERSION}
environment:
- SSH_KEY=${{SSH_KEY_COMMAS}}
- SSH_PORT=${{SSH_PORT}}
- SPLIT_CHAR=${{SPLIT_CHAR}}
run_terraform_setuptest:
stage: deploy
title: "Run terraform to setup test endpoints on memset..."
description: Compile the frontend quasar application
image: ${{RJM_DOCKERWSCALLER_IMAGE}}
working_directory: ${{main_clone}}
environment:
- SSH_KEY=${{SSH_KEY_COMMAS}}
- SSH_PORT=${{SSH_PORT}}
- SPLIT_CHAR=${{SPLIT_CHAR}}
commands:
- transferDirectory ${{RDOCKER_HOST}} ./terraform/ ${{MEMSET_CLOUD_ROOT}}/data_to_backup/terraform/executions/${{RJM_WS_NAME}}
- ssh -p ${{SSH_PORT}} -i ${HOME}/.ssh/id_rdocker -o StrictHostKeyChecking=no ${{RDOCKER_HOST}} ${{MEMSET_CLOUD_ROOT}}/scripts/update_terraform_deployment.sh setup_test ${{MEMSET_CLOUD_ROOT}} ${{RJM_WS_NAME}} ${{RJM_VERSION}}
- ssh -p ${{SSH_PORT}} -i ${HOME}/.ssh/id_rdocker -o StrictHostKeyChecking=no ${{RDOCKER_HOST}} ${{MEMSET_CLOUD_ROOT}}/scripts/execute_terraform.sh ${{MEMSET_CLOUD_ROOT}} ${{RJM_WS_NAME}}
run_container_tests_against_test_endpoint:
stage: deploy
image: ${{build_the_test_image}}
working_directory: ${{main_clone}}/server
commands:
- python3 -m pytest /test
environment:
- TESTPARAM_EXPECTED_CONTAINER_VERSION=${{RJM_VERSION}}
- TESTPARAM_ENDPOINTURL=https://api.metcarob.com/${{RJM_WS_NAME}}/test/v${{RJM_MAJOR_VERSION}}
- TESTPARAM_THROUGHKONG="True"
retry:
maxAttempts: 5
delay: 40
exponentialFactor: 1
# rdockerinit directory required because it sets up .ssh/id_rdocker
run_terraform_deploy:
stage: deploy
title: "Run terraform to deploy on memset..."
description: Compile the frontend quasar application
image: ${{RJM_DOCKERWSCALLER_IMAGE}}
working_directory: ${{main_clone}}
environment:
- SSH_KEY=${{SSH_KEY_COMMAS}}
- SSH_PORT=${{SSH_PORT}}
- SPLIT_CHAR=${{SPLIT_CHAR}}
commands:
- rdockerinit
- ssh -p ${{SSH_PORT}} -i ${HOME}/.ssh/id_rdocker -o StrictHostKeyChecking=no ${{RDOCKER_HOST}} ${{MEMSET_CLOUD_ROOT}}/scripts/update_terraform_deployment.sh deploy ${{MEMSET_CLOUD_ROOT}} ${{RJM_WS_NAME}} ${{RJM_VERSION}}
- ssh -p ${{SSH_PORT}} -i ${HOME}/.ssh/id_rdocker -o StrictHostKeyChecking=no ${{RDOCKER_HOST}} ${{MEMSET_CLOUD_ROOT}}/scripts/execute_terraform.sh ${{MEMSET_CLOUD_ROOT}} ${{RJM_WS_NAME}}
approveCleanUpOldVersion:
stage: postdeploy
type: pending-approval
title: Check prod version is working
description: Check prod version ${{RJM_VERSION}} before continuing pipeline and destorying old versions
timeout:
duration: 2
finalState: denied
cleanUpOldVersion:
stage: postdeploy
image: codefresh/remote-docker
working_directory: ${{main_clone}}
commands:
- rdocker ${{RDOCKER_HOST}} docker run --rm -it --network main_net --volume=/var/run:/var/run --entrypoint docker_service_remove_non_live
${{RJM_DOCKERWSCALLER_IMAGE}}
${{RJM_WS_NAME}}
${{RJM_VERSION}}
metcarob/
environment:
- SSH_KEY=${{SSH_KEY_COMMAS}}
- SSH_PORT=${{SSH_PORT}}
- SPLIT_CHAR=${{SPLIT_CHAR}}
when:
steps:
- name: approveCleanUpOldVersion
on:
- approved
retry:
maxAttempts: 2
delay: 3
exponentialFactor: 1