-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
222 lines (205 loc) · 5.2 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
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
stages:
- build
- push
- bundle
- upload
- deploy
build_app:
stage: build
tags:
- aws
- docker
- build
variables:
PROXY_HOST: ${BUILD_PROXY_HOST}
PROXY_PORT: ${BUILD_PROXY_PORT}
image: maven:latest
script:
- mvn -Dhttp.proxyHost=${PROXY_HOST} -Dhttp.proxyPort=${PROXY_PORT} -Dhttps.proxyHost=${PROXY_HOST} -Dhttps.proxyPort=${PROXY_PORT} clean package
artifacts:
paths:
- md2moin-web/target
expire_in: 30 minutes
.build_docker: &build_push_image
tags:
- aws
- docker
- build
script:
- cd md2moin-web
- $(aws ecr get-login --no-include-email --region eu-west-1)
- docker build -t ${ECR_REPOSITORY}/md2moin-web:${CI_COMMIT_SHORT_SHA} .
- docker push ${ECR_REPOSITORY}/md2moin-web:${CI_COMMIT_SHORT_SHA}
## Push docker image to ECR
push_image_dev:
<<: *build_push_image
stage: push
only:
- develop
variables:
AWS_ACCESS_KEY_ID: ${DEV_ECR_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${DEV_ECR_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
ECR_REPOSITORY: ${DEV_ECR_REPO}
push_image_int:
<<: *build_push_image
stage: push
only:
- stage
variables:
AWS_ACCESS_KEY_ID: ${INT_ECR_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${INT_ECR_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
ECR_REPOSITORY: ${INT_ECR_REPO}
push_image_ope:
<<: *build_push_image
stage: push
only:
- master
variables:
AWS_ACCESS_KEY_ID: ${OPE_ECR_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${OPE_ECR_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
ECR_REPOSITORY: ${OPE_ECR_REPO}
## Prepare Beanstalk bundle
.prepare_eb_bundle: &prepare_bundle
stage: bundle
image: alpine:latest
tags:
- aws
- docker
- build
only:
- develop
- stage
- master
variables:
http_proxy: ${PROXY_STRING}
https_proxy: ${PROXY_STRING}
script:
- apk add zip
- cd md2moin-web/eb-bundle
- sed -i "s|DOCKER_IMAGE|${ECR_REPO}/md2moin-web:${CI_COMMIT_SHORT_SHA}|g" Dockerrun.aws.json
- echo Generated Dockerrun
- cat Dockerrun.aws.json
- zip -r ${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}.zip .ebextensions/ Dockerrun.aws.json
artifacts:
paths:
- md2moin-web/eb-bundle
expire_in: 30 minutes
prepare_bundle_dev:
<<: *prepare_bundle
stage: bundle
only:
- develop
variables:
ECR_REPO: ${DEV_ECR_REPO}
prepare_bundle_int:
<<: *prepare_bundle
stage: bundle
only:
- stage
variables:
ECR_REPO: ${INT_ECR_REPO}
prepare_bundle_ope:
<<: *prepare_bundle
stage: bundle
only:
- master
variables:
ECR_REPO: ${OPE_ECR_REPO}
## Upload Beanstalk bundle
.upload_beanstalk_bundle: &upload_bundle
tags:
- aws
- docker
- build
script:
- echo "Uploading bundle..."
- aws s3 cp md2moin-web/eb-bundle/${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}.zip s3://${S3_BUCKET}/
upload_bundle_dev:
<<: *upload_bundle
stage: upload
only:
- develop
variables:
AWS_ACCESS_KEY_ID: ${DEV_DEPLOY_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${DEV_DEPLOY_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
S3_BUCKET: ${DEV_S3_DEPLOY}
upload_bundle_int:
<<: *upload_bundle
stage: upload
only:
- stage
variables:
AWS_ACCESS_KEY_ID: ${INT_DEPLOY_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${INT_DEPLOY_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
S3_BUCKET: ${INT_S3_DEPLOY}
upload_bundle_ope:
<<: *upload_bundle
stage: upload
only:
- master
variables:
AWS_ACCESS_KEY_ID: ${OPE_DEPLOY_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${OPE_DEPLOY_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
S3_BUCKET: ${OPE_S3_DEPLOY}
## Deploy to Beanstalk
.deploy_beanstalk: &deploy_app
tags:
- aws
- docker
- build
script:
- echo "Creating new application version..."
- |
aws elasticbeanstalk create-application-version \
--application-name ${EB_APP_NAME} \
--version-label "md2moin-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" \
--description "${CI_COMMIT_MESSAGE}" \
--source-bundle S3Bucket="${S3_BUCKET}",S3Key="${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}.zip"
- echo "Deploying new application version..."
- |
aws elasticbeanstalk update-environment \
--application-name "${EB_APP_NAME}" \
--environment-name "${EB_APP_NAME}-${STAGE}" \
--version-label "md2moin-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}"
deploy_dev:
<<: *deploy_app
stage: deploy
only:
- develop
variables:
AWS_ACCESS_KEY_ID: ${DEV_DEPLOY_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${DEV_DEPLOY_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
S3_BUCKET: ${DEV_S3_DEPLOY}
EB_APP_NAME: ${DEV_EB_APP_NAME}
STAGE: dev
deploy_int:
<<: *deploy_app
stage: deploy
only:
- stage
variables:
AWS_ACCESS_KEY_ID: ${INT_DEPLOY_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${INT_DEPLOY_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
S3_BUCKET: ${INT_S3_DEPLOY}
EB_APP_NAME: ${INT_EB_APP_NAME}
STAGE: int
deploy_ope:
<<: *deploy_app
stage: deploy
only:
- master
variables:
AWS_ACCESS_KEY_ID: ${OPE_DEPLOY_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${OPE_DEPLOY_SECRET_KEY}
AWS_DEFAULT_REGION: eu-west-1
S3_BUCKET: ${OPE_S3_DEPLOY}
EB_APP_NAME: ${OPE_EB_APP_NAME}
STAGE: ope