-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.gitlab-ci.yml
141 lines (131 loc) · 4.71 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
default:
image: docker.porscheinformatik.com/eenv/builders/mise
before_script:
- command -v mise >/dev/null 2>&1 && mise install --yes
- export MR_TAG="${CI_MERGE_REQUEST_IID:+mr-snapshot-${CI_MERGE_REQUEST_IID}}"
- export IMAGE_TAG="${MR_TAG:-${CI_COMMIT_REF_SLUG}}"
- |
function deploy_name() {
if [[ "$CI_COMMIT_REF_SLUG" == "main" ]]; then
name='prod'
else
name="mr-$CI_MERGE_REQUEST_IID"
fi
name=${name:0:45}
name=${name%-}
echo "ash-$name"
}
stages:
- build
- deploy
- acceptence-tests
- cleanup
build:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
stage: build
interruptible: true
variables:
MAVEN_CLI_OPTS: '-Ppoi --batch-mode --errors --fail-at-end --show-version -Ddocker.builderRegistry.username=$DOCKER_REGISTRY_USER -Ddocker.builderRegistry.password=$DOCKER_REGISTRY_PASSWORD -Ddocker.publishRegistry.username=$DOCKER_REGISTRY_USER -Ddocker.publishRegistry.password=$DOCKER_REGISTRY_PASSWORD'
services:
- name: docker.porscheinformatik.com/docker-proxy-dockerhub/docker:dind
alias: docker
script:
- mvn $MAVEN_CLI_OPTS install spring-boot:build-image -Pnative -Dimage.tag=${IMAGE_TAG} -Dimage.push=true
build-sonarqube:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
stage: build
interruptible: true
script:
- mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent install org.jacoco:jacoco-maven-plugin:report
- mvn -B sonar:sonar
build-sonarqube-qa:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
stage: build
interruptible: true
allow_failure: true
script:
- mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent install org.jacoco:jacoco-maven-plugin:report
- SONAR_HOST_URL=$SONAR_QA_HOST_URL SONAR_TOKEN=$SONAR_QA_TOKEN mvn -B sonar:sonar
.deploy:
script:
- helm-deploy ${OPENSHIFT_SERVER} ${OPENSHIFT_TOKEN} ${OPENSHIFT_PROJECT} deploy/${HELM_VALUES} $(deploy_name) porscheinformatik/web-application --set appVersion="v`date +'%Y%m%d-%H%M%S'`" --set "podLabels.tags\.datadoghq\.com/version=1.0.0.${CI_COMMIT_SHORT_SHA}" --set image.tag=${IMAGE_TAG} --set route.host=$APP_HOST --set postgresql.postgresPassword="${POSTGRESQL_PASSWORD}"
deploy-review:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
extends: .deploy
stage: deploy
variables:
APP_HOST: ash-mr-$CI_MERGE_REQUEST_IID.$OPENSHIFT_DOMAIN
HELM_VALUES: 'values-review.yaml'
environment:
name: review/mr-$CI_MERGE_REQUEST_IID
url: https://ash-mr-$CI_MERGE_REQUEST_IID.$OPENSHIFT_DOMAIN
on_stop: stop-review
script:
- helm-deploy ${OPENSHIFT_SERVER} ${OPENSHIFT_TOKEN} ${OPENSHIFT_PROJECT} deploy/${HELM_VALUES} $(deploy_name) porscheinformatik/web-application --set appVersion="v`date +'%Y%m%d-%H%M%S'`" --set image.tag=${IMAGE_TAG} --set "route.host=$APP_HOST"
acceptence-tests-cypress:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
image: docker.porscheinformatik.com/docker-proxy-dockerhub/cypress/base:22.11.0
stage: acceptence-tests
interruptible: true
variables:
CYPRESS_baseUrl: https://ash-mr-$CI_MERGE_REQUEST_IID.$OPENSHIFT_DOMAIN
script:
- apt update
- apt install -y ca-certificates curl
- curl -v --max-time 300 -o /dev/null "${CYPRESS_baseUrl}"
- cd heroes-acceptence-tests
- npm i
- npm test
artifacts:
expire_in: 1 week
when: always
paths:
- heroes-acceptence-tests/cypress/videos
acceptence-tests-playwright:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
image: docker.porscheinformatik.com/docker-proxy-mcr/playwright:v1.49.0-jammy
stage: acceptence-tests
interruptible: true
variables:
BASE_URL: https://ash-mr-$CI_MERGE_REQUEST_IID.$OPENSHIFT_DOMAIN
before_script:
script:
- curl -v -o /dev/null "${CYPRESS_baseUrl}" & # warmup request
- cd acceptence-tests
- npm ci
- npm test
deploy-production:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: manual
extends: .deploy
stage: deploy
variables:
APP_HOST: $CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
HELM_VALUES: 'values-prod.yaml'
environment:
name: production
url: https://$CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
stop-review:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: manual
allow_failure: true
extends: .deploy
stage: cleanup
variables:
GIT_STRATEGY: none
script:
- oc login "$OPENSHIFT_SERVER" --token="$OPENSHIFT_TOKEN"
- helm --namespace ${OPENSHIFT_PROJECT} delete $(deploy_name)
environment:
name: review/mr-$CI_MERGE_REQUEST_IID
action: stop