-
Notifications
You must be signed in to change notification settings - Fork 16
/
.gitlab-ci.yml
332 lines (303 loc) · 10.2 KB
/
.gitlab-ci.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
image: $REGISTRY_CI/gitlab-ci-base:buster
variables:
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
GIT_DEPTH: 10
RELEASE_NAME: ${DOCKER_STACK}-${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}
stages:
- quality
- build-test
- test
- release
- build
- deploy
#########################
#### TEMPLATE ####
########################
.test_template: &test_definition
allow_failure: false
variables:
ALLOW_EMPTY_PASSWORD: yes
MARIADB_USER: bn_magento
MARIADB_DATABASE: bitnami_magento
GITHUB_API_TOKEN: $GITHUB_TOKEN
GITLAB_API_TOKEN: $GITLAB_API_TOKEN
CUSTOM_REPOSITORIES: vcs https://gitlab.hipay.org/pi-ecommerce/hipay-fullservice-sdk-magento2.git,vcs [email protected]:hipay/hipay-fullservice-sdk-php.git
CUSTOM_PACKAGES: hipay/hipay-fullservice-sdk-magento2:dev-$CI_COMMIT_REF_NAME
CUSTOM_MODULES: HiPay_FullserviceMagento
MAGENTO_HOST: 127.0.0.1
MAGENTO_EXTERNAL_HTTP_PORT_NUMBER: 8096
MAGENTO_EXTERNAL_HTTPS_PORT_NUMBER: 8096
MAGENTO_DATABASE_HOST: mariadb
MAGENTO_DATABASE_PORT_NUMBER: 3306
MAGENTO_DATABASE_USER: bn_magento
MAGENTO_DATABASE_NAME: bitnami_magento
MAGENTO_USERNAME: demo
MAGENTO_PASSWORD: hipay123
MAGENTO_EMAIL: demo@hipaycom
MAGENTO_MODE: developer
ELASTICSEARCH_HOST: elasticsearch
ELASTICSEARCH_PORT_NUMBER: 9200
PHP_ENABLE_OPCACHE: false
ENVIRONMENT: stage
HIPAY_API_USER_TEST: $HIPAY_API_USER_TEST
HIPAY_API_PASSWORD_TEST: $HIPAY_API_PASSWORD_TEST
HIPAY_SECRET_PASSPHRASE_TEST: $HIPAY_SECRET_PASSPHRASE_TEST
HIPAY_TOKENJS_USERNAME_TEST: $HIPAY_TOKENJS_USERNAME_TEST
HIPAY_TOKENJS_PUBLICKEY_TEST: $HIPAY_TOKENJS_PUBLICKEY_TEST
HIPAY_APPLEPAY_USERNAME_TEST: $HIPAY_APPLEPAY_USERNAME_TEST
HIPAY_APPLEPAY_PASSWORD_TEST: $HIPAY_APPLEPAY_PASSWORD_TEST
HIPAY_APPLEPAY_SECRET_PASSPHRASE_TEST: $HIPAY_APPLEPAY_SECRET_PASSPHRASE_TEST
HIPAY_APPLEPAY_TOKENJS_USERNAME_TEST: $HIPAY_APPLEPAY_TOKENJS_USERNAME_TEST
HIPAY_APPLEPAY_TOKENJS_PUBLICKEY_TEST: $HIPAY_APPLEPAY_TOKENJS_PUBLICKEY_TEST
SMTP_LINK: common-smtp:1025
ACTIVE_METHODS: $ACTIVE_METHODS
XDEBUG_ENABLED: 0
PI_DATA_URL: $PI_CI_DATA_URL
services:
- name: $REGISTRY_CI/test-jobs-${DOCKER_STACK}-${DOCKER_SERVICE}_web:${CI_COMMIT_REF_SLUG}
alias: web
- name: docker.io/bitnami/mariadb:10.6
alias: mariadb
- name: docker.io/bitnami/elasticsearch:7
alias: elasticsearch
artifacts:
paths:
- bin/tests/errors
when: always
tags:
- small
except:
variables:
- $ONLY_DEPLOY
- $CI_COMMIT_MESSAGE =~ /skip-tests/
.login_to_registry: &login-to-registry
before_script:
- 'mkdir /tmp'
- 'touch /tmp/credentials.json'
- 'echo ${SA_REGISTRY_CD} > /tmp/credentials.json'
- 'export GOOGLE_APPLICATION_CREDENTIALS=/tmp/credentials.json'
.login_to_cd: &login-to-cd
before_script:
# Connect GCP with deploy service account
- mkdir -p /tmp
- touch /tmp/credentials.json
- echo ${SA_DEPLOY_CD} > /tmp/credentials.json
- gcloud auth activate-service-account "${SA_DEPLOY_NAME}" --key-file="/tmp/credentials.json"
- gcloud config set project "${GCP_CD_PROJECT_ID}"
- gcloud config set compute/zone "${GCP_CD_CLUSTER_REGION}"
- gcloud container clusters get-credentials "${GCP_CD_CLUSTER_NAME}"
#########################
#### JOBS ####
########################
code-quality:
stage: quality
script:
- cd ci-tools/phpcs
- composer install
- ./vendor/bin/phpcs --standard=ruleset.xml
except:
variables:
- $ONLY_DEPLOY
tags:
- small
build-test-2-1-10:
stage: build-test
image:
name: gcr.io/kaniko-project/executor:v1.6.0-debug
script:
- cp bin/docker/conf/development/auth.json.sample bin/docker/conf/development/auth.json
- sed -i "s|<MAGE_ACCOUNT_PUBLIC_KEY>|$MAGE_ACCOUNT_PUBLIC_KEY|" bin/docker/conf/development/auth.json
- sed -i "s|<MAGE_ACCOUNT_PRIVATE_KEY>|$MAGE_ACCOUNT_PRIVATE_KEY|" bin/docker/conf/development/auth.json
- /kaniko/executor
--cache=true
--context "dir://${CI_PROJECT_DIR}"
--dockerfile "./bin/docker/images/default/Dockerfile"
--destination "$REGISTRY_CI/test-jobs-${DOCKER_STACK}-${DOCKER_SERVICE}_web:${CI_COMMIT_REF_SLUG}"
except:
variables:
- $ONLY_DEPLOY
tags:
- small
.casperjs-2-1-10:
<<: *test_definition
stage: test
script:
- curl --retry 20 --retry-delay 10 --retry-connrefused --output /dev/null http://web
- sh bin/tests/casper_run_circle.sh http://web:8096
except:
variables:
- $ONLY_DEPLOY
tags:
- medium
get-jira-tickets:
stage: release
image: node:latest
rules:
- if: $CI_COMMIT_TAG
script:
- |
node <<EOF
(async () => {
try {
const gitlabResponse = await fetch("${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests?state=merged&target_branch=develop&milestone=${CI_COMMIT_TAG}", {
method: "GET",
headers: {
"Private-Token": "$GITLAB_API_TOKEN"
}
});
if (!gitlabResponse.ok) {
const err = await gitlabResponse.json();
throw new Error("Failed to send GitLab request: " + JSON.stringify(err));
}
const mergeRequests = await gitlabResponse.json();
const tickets = [];
mergeRequests.forEach((mr) => {
const matches = mr.source_branch.match(/EC-\d+/);
if(matches?.length) {
tickets.push(matches[0].toUpperCase());
}
});
console.log("tickets", tickets);
const payload = {
"event_type": "trigger-artifact-workflow",
"client_payload": {
"tickets": tickets
}
};
console.log("payload", JSON.stringify(payload));
const githubResponse = await fetch("https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_PROJECT}/dispatches", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer ${GITHUB_TOKEN}",
"User-Agent": "Node.js"
},
body: JSON.stringify(payload)
});
if (!githubResponse.ok) {
const err = await githubResponse.json();
throw new Error("Failed to send GitHub event: " + JSON.stringify(err));
}
} catch (error) {
throw new Error("Request error: " + error.message);
}
})();
EOF
release-job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- get-jira-tickets
variables:
TEMP_CHANGELOG_FILE: 'release_changelog.txt'
rules:
- if: $CI_COMMIT_TAG
script:
- |
# Extract changelog part according to tag version
CHANGELOG=$(awk -v version="## $CI_COMMIT_TAG" '
$0 ~ version {printit=1; next}
printit && /^## / {exit}
printit {print}
' CHANGELOG.md)
{
echo "# CHANGE LOG"
echo "$CHANGELOG"
} > "$TEMP_CHANGELOG_FILE"
- cat "$TEMP_CHANGELOG_FILE"
release:
tag_name: $CI_COMMIT_TAG
name: Version $CI_COMMIT_TAG
description: '$TEMP_CHANGELOG_FILE'
milestones:
- $CI_COMMIT_TAG
build:
<<: *login-to-registry
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.6.0-debug
rules:
- if: $ONLY_DEPLOY
when: on_success
- if: $CI_PIPELINE_SOURCE == "push"
when: manual
script:
- cp bin/docker/conf/development/auth.json.sample bin/docker/conf/development/auth.json
- sed -i "s|<MAGE_ACCOUNT_PUBLIC_KEY>|$MAGE_ACCOUNT_PUBLIC_KEY|" bin/docker/conf/development/auth.json
- sed -i "s|<MAGE_ACCOUNT_PRIVATE_KEY>|$MAGE_ACCOUNT_PRIVATE_KEY|" bin/docker/conf/development/auth.json
- /kaniko/executor
--cache=true
--context "dir://${CI_PROJECT_DIR}"
--dockerfile "./bin/docker/images/default/Dockerfile_helm"
--destination "${REGISTRY_CD}/${DOCKER_STACK}-${DOCKER_SERVICE}-web:${CI_COMMIT_REF_SLUG}"
tags:
- small
deploy2recette:
<<: *login-to-cd
stage: deploy
image: $REGISTRY_CI/gitlab-ci-base:deployment
needs:
- build
rules:
- if: $ONLY_DEPLOY
when: on_success
- if: $CI_PIPELINE_SOURCE == "push"
when: manual
variables:
GPC_ACCOUNT: ''
script:
- echo $RELEASE_NAME
- |-
BRANCH=$CI_COMMIT_REF_NAME
if [ "$CI_COMMIT_TAG" = "" ]; then
BRANCH=dev-$CI_COMMIT_REF_NAME
fi
- >
helm install $RELEASE_NAME ./bin/docker/kubernetes/helm/
--namespace default
--set magento2_image="${REGISTRY_CD}/${DOCKER_STACK}-${DOCKER_SERVICE}-web"
--set magento2_tag="${CI_COMMIT_REF_SLUG}"
--set magento2_url="${DOCKER_STACK}-${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}.${URL_CD}"
--set github_api_token="${GITHUB_TOKEN}"
--set gitlab_api_token="${GITLAB_API_TOKEN}"
--set hipay_api_user_test="$HIPAY_API_USER_RE7"
--set hipay_api_password_test="$HIPAY_API_PASSWORD_RE7"
--set hipay_secret_passphrase_test="$HIPAY_SECRET_PASSPHRASE_RE7"
--set hipay_tokenjs_username_test="$HIPAY_TOKENJS_USERNAME_RE7"
--set hipay_tokenjs_publickey_test="$HIPAY_TOKENJS_PUBLICKEY_RE7"
--set hipay_applepay_username_test="$HIPAY_APPLEPAY_USERNAME_RE7"
--set hipay_applepay_password_test="$HIPAY_APPLEPAY_PASSWORD_RE7"
--set hipay_applepay_secret_passphrase_test="$HIPAY_APPLEPAY_SECRET_PASSPHRASE_RE7"
--set hipay_applepay_tokenjs_username_test="$HIPAY_APPLEPAY_TOKENJS_USERNAME_RE7"
--set hipay_applepay_tokenjs_publickey_test="$HIPAY_APPLEPAY_TOKENJS_PUBLICKEY_RE7"
--set pi_data_url="$PI_CI_DATA_URL"
--set branch="$BRANCH"
allow_failure: true
environment:
name: review/${CI_COMMIT_REF_SLUG}
url: https://${DOCKER_STACK}-${DOCKER_SERVICE}-${CI_COMMIT_REF_SLUG}.${URL_CD}
on_stop: stop_review
tags:
- small
stop_review:
<<: *login-to-cd
stage: deploy
image: $REGISTRY_CI/gitlab-ci-base:deployment
needs:
- deploy2recette
rules:
- if: $ONLY_DEPLOY
when: manual
- if: $CI_PIPELINE_SOURCE == "push"
when: manual
variables:
GIT_STRATEGY: none
script:
- helm uninstall $RELEASE_NAME --namespace=default
allow_failure: true
environment:
name: review/${CI_COMMIT_REF_SLUG}
action: stop
tags:
- small