-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
150 lines (135 loc) · 4.81 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
# ------------------------------------------------
# - Définitions des variables -
# ------------------------------------------------
variables:
MAVEN_SETTINGS: "--settings .m2/settings.xml -Dmaven.repo.local=.m2/repository"
MAVEN_CLI_OPTS: "$MAVEN_SETTINGS --no-transfer-progress --errors --show-version -DinstallAtEnd=true -DdeployAtEnd=true -Pci,ocsin"
SONAR_MAVEN_OPTS: "-Dsonar.host.url=$SONARQUBE_URL $MAVEN_SETTINGS -Dsonar.login=$SONARQUBE_TOKEN -Pci,ocsin"
SONAR_MAVEN_GOAL: "org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar"
DEV_DEPLOY_PATH: "$DEV_CATALINA_HOME/livraison"
default:
tags:
- 'host:restricted-container'
- 'net:gold-dev'
- 'registered_endpoint:/DEVELOPPEUR-SOCIAL'
# Cache par défaut des node_modules ainsi que des dépôts maven et npm
cache:
key: "$CI_JOB_NAME"
paths:
- qeli-frontoffice-ihm/node_modules/
- .m2/repository
- .npm/
# Les étapes du build
stages:
- ihm # Compilation de l'interface graphique.
- verify # permet de vérifier que le projet compile bien et les tests passe sur des features branches.
- publish # Publication de l'artefact maven sur Nexus.
- run # Déploiement sur les servers de DEV.
- analyze # Analyse sonar de l'application.
##################################################
# Définition des étapes
##################################################
# ------------------------------------------------
# Compilation Frontend
# ------------------------------------------------
artifact:ihm:
image: $DOCKER_URL/node:16
stage: ihm
script:
- cd qeli-frontoffice-ihm
- npm ci
- npm run build
rules:
- allow_failure: false
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
expire_in: 1 day
paths:
- qeli-frontoffice-ihm/dist
# ------------------------------------------------
# Compilation backend
# ------------------------------------------------
artifact:verify:
image: $DOCKER_URL/maven:3.8.4-openjdk-17
stage: verify
script:
- mvn clean source:jar verify ${MAVEN_CLI_OPTS}
rules:
- if: $CI_COMMIT_BRANCH != "main" && $CI_COMMIT_BRANCH != "develop"
dependencies:
- artifact:ihm
# ------------------------------------------------
# Publication de l'artefact
# ------------------------------------------------
artifact:publish:
image: $DOCKER_URL/maven:3.8.4-openjdk-17
stage: publish
script:
- mvn clean source:jar deploy ${MAVEN_CLI_OPTS}
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
expire_in: 1 day
paths:
- qeli-frontoffice-application/target/qeli-frontoffice-application.war
rules:
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "develop"
dependencies:
- artifact:ihm
# ------------------------------------------------
# Déploiement DEV
# ------------------------------------------------
# DEV Host A
dev-a:run:
image: $DOCKER_URL/gotechnies/alpine-ssh:latest
stage: run
before_script:
- eval $(ssh-agent -s)
- echo "${DEV_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan ${DEV_HOST_A} >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- cd qeli-frontoffice-application/
- scp target/qeli-frontoffice-application.war ${DEV_USER}@${DEV_HOST_A}:${DEV_DEPLOY_PATH}/socialqeli_pub.war
- sed -i "s|%CATALINA_HOME%|${DEV_CATALINA_HOME}|" ./src/distrib/dev-deploy.sh
- scp src/distrib/dev-deploy.sh ${DEV_USER}@${DEV_HOST_A}:/home/${DEV_USER}/deploy.sh
- ssh -t ${DEV_USER}@${DEV_HOST_A} "cd /home/${DEV_USER}/ && sh ./deploy.sh"
rules:
- if: $CI_COMMIT_BRANCH == "develop"
dependencies:
- artifact:publish
# DEV Host B
dev-b:run:
image: $DOCKER_URL/gotechnies/alpine-ssh:latest
stage: run
before_script:
- eval $(ssh-agent -s)
- echo "${DEV_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan ${DEV_HOST_B} >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- cd qeli-frontoffice-application/
- scp target/qeli-frontoffice-application.war ${DEV_USER}@${DEV_HOST_B}:${DEV_DEPLOY_PATH}/socialqeli_pub.war
- sed -i "s|%CATALINA_HOME%|${DEV_CATALINA_HOME}|" ./src/distrib/dev-deploy.sh
- scp src/distrib/dev-deploy.sh ${DEV_USER}@${DEV_HOST_B}:/home/${DEV_USER}/deploy.sh
- ssh -t ${DEV_USER}@${DEV_HOST_B} "cd /home/${DEV_USER}/ && sh ./deploy.sh"
rules:
- if: $CI_COMMIT_BRANCH == "develop"
dependencies:
- artifact:publish
# ------------------------------------------------
# Analysis Sonar
# ------------------------------------------------
sonar:analyze:
image: $DOCKER_URL/maven:3.8.4-openjdk-17
stage: analyze
script:
- mvn clean package ${MAVEN_CLI_OPTS}
- mvn ${SONAR_MAVEN_GOAL} ${SONAR_MAVEN_OPTS}
rules:
- if: $CI_COMMIT_BRANCH == "develop"
dependencies:
- artifact:ihm