This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
144 lines (135 loc) · 5.24 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
stages:
- build-application
- build-docker-configuration-recette
- deploy-application-recette
- build-docker-configuration-production
- deploy-application-production
cache: &global_cache
key: ${CI_COMMIT_REF_SLUG}
paths:
- .m2/repository/
policy: pull-push
build_application :
stage: build-application
image: registry.beta.pole-emploi.fr/customize-docker-images/maven
script:
- 'mvn --batch-mode -DskipTests -Dmaven.repo.local=.m2/repository clean install'
- 'mkdir -p ./target/app && (cd ./target/app; jar -xf ../*.jar)'
artifacts:
paths:
- ./target/app
expire_in: 1 week
cache:
<<: *global_cache
policy: pull
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
changes:
- pom.xml
- src/main/java/**/*
sonar_quality_analyse :
stage: build-application
image: registry.beta.pole-emploi.fr/customize-docker-images/maven
script:
- mvn clean verify -P analyse-sonar sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN
cache:
<<: *global_cache
policy: pull
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
changes:
- pom.xml
- src/main/java/**/*
allow_failure: true
generate-docker-stack-recette:
stage: build-docker-configuration-recette
image:
# https://git.beta.pole-emploi.fr/customize-docker-images/p2cli.git
name: registry.beta.pole-emploi.fr/customize-docker-images/p2cli
script:
- cd docker
- mkdir recette
- p2 -t estime-backend-recette-stack.yml.j2 -o ./recette/estime-backend-stack.yml
artifacts:
paths:
- ./docker/recette
expire_in: 1 week
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
changes:
- pom.xml
- src/main/java/**/*
build-docker-image-recette:
stage: build-docker-configuration-recette
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
# build estime-backend docker image and push it in containers registry
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/docker-image/Dockerfile --destination $CI_REGISTRY_IMAGE:release-candidate
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
changes:
- pom.xml
- src/main/java/**/*
deploy_application-recette:
stage: deploy-application-recette
before_script:
- apt-get update -qq
- apt-get install -y -qq openssh-client rsync iputils-ping
# add target server in known_hosts
- mkdir ~/.ssh
- echo "$R7_SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# add SSH_PRIVATE_KEY in agent store
- eval $(ssh-agent -s)
- ssh-add <(echo "$R7_SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
script:
- rsync -avz --no-perms --no-owner --no-group -e 'ssh' $CI_PROJECT_DIR/docker/scripts/deploy.sh $CI_PROJECT_DIR/docker/recette/estime-backend-stack.yml $HOST_SERVER_USER@$R7_HOST_SERVER_IP:/home/docker/estime-backend
# exec deploy.sh to deploy docker stack estime-frontend or update estime-frontend image service
- ssh $HOST_SERVER_USER@$R7_HOST_SERVER_IP "cd /home/docker/estime-backend && ./deploy.sh $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD"
when: manual
generate-docker-stack-production:
stage: build-docker-configuration-production
image:
# https://git.beta.pole-emploi.fr/customize-docker-images/p2cli.git
name: registry.beta.pole-emploi.fr/customize-docker-images/p2cli
script:
- cd docker
- mkdir production
- p2 -t estime-backend-production-stack.yml.j2 -o ./production/estime-backend-stack.yml
artifacts:
paths:
- ./docker/production
expire_in: 1 week
when: manual
build-docker-image-production:
stage: build-docker-configuration-production
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
# build estime-backend docker image and push it in containers registry
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/docker-image/Dockerfile --destination $CI_REGISTRY_IMAGE:release
when: manual
deploy_application-production:
stage: deploy-application-production
before_script:
- apt-get update -qq
- apt-get install -y -qq openssh-client rsync iputils-ping
# add target server in known_hosts
- mkdir ~/.ssh
- echo "$PROD_SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# add SSH_PRIVATE_KEY in agent store
- eval $(ssh-agent -s)
- ssh-add <(echo "$PROD_SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
script:
- rsync -avz --no-perms --no-owner --no-group -e 'ssh' $CI_PROJECT_DIR/docker/scripts/deploy.sh $CI_PROJECT_DIR/docker/production/estime-backend-stack.yml $HOST_SERVER_USER@$PROD_HOST_SERVER_IP:/home/docker/estime-backend
# exec deploy.sh to deploy docker stack estime-frontend or update estime-frontend image service
- ssh $HOST_SERVER_USER@$PROD_HOST_SERVER_IP "cd /home/docker/estime-backend && ./deploy.sh $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD"
when: manual