-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
248 lines (226 loc) · 7.29 KB
/
.gitlab-ci.yml
File metadata and controls
248 lines (226 loc) · 7.29 KB
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
image: wharf.es.net/dockerhub-proxy/library/docker:28.2.2-dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERT_DIR: ""
RELEASE_BRANCH: master
DEV_BRANCH: develop
MAIN_BRANCH: master
ENVIRONMENT: production
BACKEND_WHARF_NAME: oscars-backend
FRONTEND_WHARF_NAME: oscars-frontend
BACKEND_IMAGE_TAG: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG-backend:$CI_COMMIT_SHA
FRONTEND_IMAGE_TAG: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG-frontend:$CI_COMMIT_SHA
stages:
- build
- test
- profile
- loadtest
- push
.wharf_logout: &wharf_logout |-
docker logout "$WHARF_SITE"
.wharf_login: &wharf_login |-
echo "$WHARF_TOKEN" | docker login -u "$WHARF_USER" "$WHARF_SITE" --password-stdin
.docker_login: &docker_login |-
docker login -u gitlab-ci-token -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
backend:build_image:
stage: build
variables:
DOCKERFILE_PATH: ./deploy/prod/backend.dockerfile
CONTEXT_PATH: ./
script:
- *docker_login
- DOCKER_BUILDKIT=1 docker build -t ${BACKEND_IMAGE_TAG} --progress=plain -f $DOCKERFILE_PATH $CONTEXT_PATH
- docker push $BACKEND_IMAGE_TAG
backend:scan:
stage: test
needs: ["backend:build_image"]
variables:
CS_IMAGE: $BACKEND_IMAGE_TAG
trigger:
include:
- project: "security/container-scanning"
file: ".ESnet-container-scan.yml"
backend:test:
stage: test
needs: ["backend:build_image"]
variables:
DOCKERFILE_PATH: ./deploy/devel/backend.dockerfile
CONTEXT_PATH: ./
script:
- DOCKER_BUILDKIT=1 docker build --progress=plain --target=test --no-cache -f $DOCKERFILE_PATH $CONTEXT_PATH
# MUST run in stand-alone, with in-memory DB only. We only want to profile
# OSCARS backend, not dependencies.
backend:profile:
stage: profile
before_script:
- *docker_login
- *wharf_login
# - if docker network ls --format "{{.Name}}" | grep -q "^oscars-local-net$"; then docker network rm oscars-local-net; fi;
- mkdir -p ./backend/profiling
after_script:
- ls -la ./backend/profiling
- docker compose down
- *wharf_logout
services:
- docker:28.2.2-dind
needs: ["backend:build_image", "backend:test"]
rules:
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
artifacts:
paths:
- ./backend/profiling
variables:
CONTEXT_PATH: ./
DELAY_MIN: "30s"
DURATION_MIN: "10m"
TARGET_HOST: "oscars-backend:1099"
FILENAME: "profiling/${CI_COMMIT_BRANCH}_${CI_PIPELINE_CREATED_AT}_oscars_backend_profile.jfr"
DOCKER_DRIVER: overlay2
DOCKER_BUILDKIT: 1
# DOCKER_HOST: tcp://docker:2375 # Connect to the DinD service
# DOCKER_TLS_CERTDIR: "" # Disable TLS for simplicity in this example
SPRING_PROFILES_ACTIVE: test
HOSTNAME: oscars-backend
JAVA_OPTS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:9201 \n
-Dcom.sun.management.jmxremote \n
-Dcom.sun.management.jmxremote.port=1099 \n
-Dcom.sun.management.jmxremote.rmi.port=1099 \n
-Djava.rmi.server.hostname=oscars-backend \n
-Dcom.sun.management.jmxremote.local.only=false \n
-Dcom.sun.management.jmxremote.authenticate=false \n
-Dcom.sun.management.jmxremote.ssl=false"
MAVEN_OPTS: ""
OSCARS_BACKEND_WEB_PORT: 8201
SPRING_DATASOURCE_URL: jdbc:postgresql://oscars-db:5432/oscars
POSTGRES_USER: no_user
POSTGRES_PASSWORD: no_password
ESDB_API_KEY: no_esdb_api_key
ESDB_URI: http://localhost:8080/esdb_api/v1
ESDB_GRAPHQL_URI: http://localhost:8080/esdb_api/graphql
TOPO_OSCARS_URL: http://localhost:8080/oscars-one/topology
NSO_SYNC: "disabled"
NSO_USERNAME: no_user
NSO_PASSWORD: no_password
NSO_URI: http://localhost:8080/restconf
script:
- echo "Checking Docker daemon status..."
- docker info # This command will fail if DinD is not ready
- echo "Docker daemon is available. Proceeding with scripts..."
- chmod -R a+rw ./backend/profiling
- docker compose --progress=plain -f docker-compose.profiling.yml up oscars-backend-profile
- if [ ! -f "./backend/${FILENAME}" ]; then echo "Could NOT find generated recording data at ./backend/${FILENAME}"; exit 1; fi;
backend:loadtest:
stage: loadtest
before_script:
- *docker_login
- *wharf_login
# - if docker network ls --format "{{.Name}}" | grep -q "^oscars-local-net$"; then docker network rm oscars-local-net; fi;
- mkdir -p ./backend/load-testing
after_script:
- ls -la ./backend/load-testing
- docker compose down
- *wharf_logout
services:
- docker:28.2.2-dind
needs:
- job: "backend:build_image"
- job: "backend:test"
- job: "backend:profile"
optional: true
rules:
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
artifacts:
paths:
- ./backend/load-testing
script:
- echo "Checking Docker daemon status..."
- docker info # This command will fail if DinD is not ready
- echo "Docker daemon is available. Proceeding with scripts..."
- docker compose --progress=plain -f docker-compose.loadtest.yml up oscars-load-test
.backend:push:
stage: push
needs:
- job: "backend:scan"
- job: "backend:test"
- job: "backend:profile"
optional: true
before_script:
- *docker_login
- *wharf_login
after_script:
- *wharf_logout
script:
- |
docker pull $BACKEND_IMAGE_TAG
for tag in $TAGS; do
if echo $tag | grep -q "BRANCH_TAG"; then
tag=$(echo $tag | sed "s/BRANCH_TAG/$(echo $CI_COMMIT_REF_NAME | sed 's/\//-/g')/g")
fi
docker tag $BACKEND_IMAGE_TAG $tag
docker push $tag
done;
frontend:build_image:
stage: build
variables:
DOCKERFILE_PATH: ./deploy/prod/frontend.dockerfile
CONTEXT_PATH: ./frontend
script:
- *docker_login
- DOCKER_BUILDKIT=1 docker build -t ${FRONTEND_IMAGE_TAG} --progress=plain -f $DOCKERFILE_PATH $CONTEXT_PATH
- docker push $FRONTEND_IMAGE_TAG
frontend:scan:
stage: test
needs: ["frontend:build_image"]
variables:
CS_IMAGE: $FRONTEND_IMAGE_TAG
trigger:
include:
- project: "security/container-scanning"
file: ".ESnet-container-scan.yml"
.frontend:push:
stage: push
needs: ["frontend:scan"]
before_script:
- *docker_login
- *wharf_login
after_script:
- *wharf_logout
script:
- |
docker pull $FRONTEND_IMAGE_TAG
for tag in $TAGS; do
if echo $tag | grep -q "BRANCH_TAG"; then
tag=$(echo $tag | sed "s/BRANCH_TAG/$(echo $CI_COMMIT_REF_NAME | sed 's/\//-/g')/g")
fi
docker tag $FRONTEND_IMAGE_TAG $tag
docker push $tag
done;
backend:publish:
extends: .backend:push
variables:
TAGS: |
$WHARF_SITE/$WHARF_PROJECT/$BACKEND_WHARF_NAME:$CI_PIPELINE_ID
$WHARF_SITE/$WHARF_PROJECT/$BACKEND_WHARF_NAME:BRANCH_TAG
frontend:publish:
extends: .frontend:push
rules:
variables:
TAGS: |
$WHARF_SITE/$WHARF_PROJECT/$FRONTEND_WHARF_NAME:$CI_PIPELINE_ID
$WHARF_SITE/$WHARF_PROJECT/$FRONTEND_WHARF_NAME:BRANCH_TAG
backend:publish_release:
extends: .backend:push
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
- if: $CI_COMMIT_TAG
variables:
TAGS: |
$WHARF_SITE/$WHARF_PROJECT/$BACKEND_WHARF_NAME:latest
frontend:publish_release:
extends: .frontend:push
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
- if: $CI_COMMIT_TAG
variables:
TAGS: |
$WHARF_SITE/$WHARF_PROJECT/$FRONTEND_WHARF_NAME:latest