-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.gitlab-ci.yml
130 lines (120 loc) · 4.94 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
stages:
- build
- deploy
############################################
################# CONFIG ###################
############################################
before_script:
- | # export env file and copy routing table to pyalbert config
if [[ -z $CI_ENVIRONMENT_NAME ]]; then
echo "info: CI_ENVIRONMENT_NAME is empty, skip the export"
else
if [[ $CI_COMMIT_BRANCH = "staging" ]]; then
echo "info: export staging env file of $CI_ENVIRONMENT_NAME environment"
export $(grep -v "^#" $STAGING__ENV_FILE | xargs)
elif [[ $CI_COMMIT_BRANCH = "main" ]]; then
echo "info: export production env file of $CI_ENVIRONMENT_NAME environment"
export $(grep -v "^#" $PROD__ENV_FILE | xargs)
fi
fi
config:clean gitlab runner:
rules:
- when: manual
allow_failure: true # to avoid blocked state
stage: .pre
image: docker:latest
services:
- docker:dind
script:
- docker system prune -af --volumes
############################################
################## FRONT ###################
############################################
################## DINUM ###################
build:front:dinum:
environment:
name: dinum
rules:
- if: $CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == "main"
when: manual
allow_failure: true # to avoid blocked state
stage: build
image: docker:latest
services:
- docker:dind
script:
- | # build and push front image to gitlab registry
docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY
docker build --rm --file ./Dockerfile \
--build-arg VITE_API_URL=${CI_DEPLOY_URL} \
--build-arg VITE_ENVIRONMENT_NAME=${CI_ENVIRONMENT_NAME} \
--build-arg VITE_MODEL_NAME=${MODEL_NAME} \
--build-arg VITE_MODEL_MODE=${MODEL_MODE} \
--build-arg VITE_MATOMO_URL=${MATOMO_URL} \
--tag ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH} .
docker push ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH}
deploy:front:dinum:
environment:
name: dinum
rules:
- if: $CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == "main"
when: manual
allow_failure: true # to avoid blocked state
stage: deploy
image: alpine:latest
script:
- | # ssh connection setup
chmod og= $CI_DEPLOY_USER_SSH_PRIVATE_KEY
apk update
apk add openssh-client
- |
ssh -i $CI_DEPLOY_USER_SSH_PRIVATE_KEY -o StrictHostKeyChecking=no ${CI_DEPLOY_USER}@${CI_DEPLOY_HOST} "
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
docker container rm -f ${CI_ENVIRONMENT_NAME}-front || true
docker image rm ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH} || true
docker run --restart always --detach --publish 4174:4173 --name ${CI_ENVIRONMENT_NAME}-front ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH}
"
############# FRANCE SERVICES ##############
build:front:france services:
environment:
name: franceservices
rules:
- if: $CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == "main"
when: manual
allow_failure: true # to avoid blocked state
stage: build
image: docker:latest
services:
- docker:dind
script:
- | # build and push front image to gitlab registry
docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY
docker build --rm --file ./Dockerfile \
--build-arg VITE_API_URL=${CI_DEPLOY_URL} \
--build-arg VITE_ENVIRONMENT_NAME=${CI_ENVIRONMENT_NAME} \
--build-arg VITE_MODEL_NAME=${MODEL_NAME} \
--build-arg VITE_MODEL_MODE=${MODEL_MODE} \
--build-arg VITE_MATOMO_URL=${MATOMO_URL} \
--tag ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH} .
docker push ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH}
deploy:front:france services:
environment:
name: franceservices
rules:
- if: $CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == "main"
when: manual
allow_failure: true # to avoid blocked state
stage: deploy
image: alpine:latest
script:
- | # ssh connection setup
chmod og= $CI_DEPLOY_USER_SSH_PRIVATE_KEY
apk update
apk add openssh-client
- |
ssh -i $CI_DEPLOY_USER_SSH_PRIVATE_KEY -o StrictHostKeyChecking=no ${CI_DEPLOY_USER}@${CI_DEPLOY_HOST} "
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
docker container rm -f ${CI_ENVIRONMENT_NAME}-front || true
docker image rm ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH} || true
docker run --restart always --detach --publish 4174:4173 --name ${CI_ENVIRONMENT_NAME}-front ${CI_REGISTRY_IMAGE}/front/${CI_ENVIRONMENT_NAME}:${CI_FRONT_IMAGE_TAG}-${CI_COMMIT_BRANCH}
"