1
- version : 2
1
+ version : 2.1
2
2
3
3
references :
4
- setup_remote_docker : &setup_remote_docker
5
- setup_remote_docker :
6
- version : 17.11.0-ce
4
+ setup_remote_docker : &setup_remote_docker
5
+ setup_remote_docker :
6
+ version : 17.11.0-ce
7
+ ignore_master : &ignore_master
8
+ filters :
9
+ branches :
10
+ ignore :
11
+ - master
12
+ only_master : &only_master
13
+ filters :
14
+ branches :
15
+ only :
16
+ - master
17
+ deploy_requirements : &deploy_requires
18
+ requires :
19
+ - lint
20
+ - test
21
+ - packaging
22
+
23
+ orbs :
24
+ aws-cli :
circleci/[email protected]
25
+
26
+
27
+ executors :
28
+ python3_6_1 :
29
+ working_directory : ~/repo
30
+ docker :
31
+ - image : circleci/python:3.6.1
32
+
33
+ commands :
34
+ prepare-python-resources :
35
+ description : ' Pythonのリソースを準備'
36
+ parameters :
37
+ resource :
38
+ type : string
39
+ default : ' requirements.txt'
40
+ steps :
41
+ - checkout
42
+
43
+ - << : *setup_remote_docker
44
+
45
+ - restore_cache :
46
+ keys :
47
+ - v3-dependencies-{{ checksum "<< parameters.resource >>" }}
48
+ - v3-dependencies-
49
+
50
+ - run :
51
+ name : install dependencies
52
+ command : |
53
+ python3 -m venv venv
54
+ . venv/bin/activate
55
+ pip install -r << parameters.resource >>
56
+
57
+ - save_cache :
58
+ paths :
59
+ - ./venv
60
+ key : v3-dependencies-{{ checksum "<< parameters.resource >>" }}
61
+
62
+ deploy-resources :
63
+ description : ' リソースのデプロイの共通処理'
64
+ parameters :
65
+ target :
66
+ type : string
67
+ steps :
68
+ - prepare-python-resources
69
+
70
+ - attach_workspace :
71
+ at : .
72
+
73
+ - deploy :
74
+ name : Deployment
75
+ command : |
76
+ if [ $ALIS_APP_ID ]; then
77
+ . venv/bin/activate
78
+ ./deploy.sh << parameters.target >>
79
+ fi
7
80
8
81
jobs :
9
- build :
82
+ lint :
83
+ executor :
84
+ name : python3_6_1
85
+
86
+ steps :
87
+ - prepare-python-resources :
88
+ resource : ' requirements_test.txt'
89
+
90
+ - run :
91
+ name : checkstyle
92
+ command : |
93
+ . venv/bin/activate
94
+ pycodestyle src tests ./*.py
95
+
96
+ - run :
97
+ name : pyflakes
98
+ command : |
99
+ . venv/bin/activate
100
+ pyflakes src tests ./*.py
10
101
102
+ test :
11
103
docker :
12
104
- image : circleci/python:3.6.1
13
105
- image : bluszcz/bflocalstack-dynamodb-s3
@@ -23,12 +115,13 @@ jobs:
23
115
24
116
steps :
25
117
- checkout
118
+
26
119
- << : *setup_remote_docker
27
- # Download and cache dependencies
120
+
28
121
- restore_cache :
29
122
keys :
30
- - v3-dependencies-{{ checksum "requirements.txt" }}
31
- - v3-dependencies-
123
+ - v3-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements_test .txt" }}
124
+ - v3-dependencies-
32
125
33
126
- run :
34
127
name : install dependencies
@@ -41,46 +134,170 @@ jobs:
41
134
- save_cache :
42
135
paths :
43
136
- ./venv
44
- key : v3-dependencies-{{ checksum "requirements.txt" }}
137
+ key : v3-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements_test.txt" }}
45
138
46
139
- run :
47
- name : run checkstyle for python code
140
+ name : run tests
48
141
command : |
49
142
. venv/bin/activate
50
- pycodestyle src tests ./* .py
143
+ python exec_test .py
51
144
52
- - run :
53
- name : run pyflakes for python code
54
- command : |
55
- . venv/bin/activate
56
- pyflakes src tests ./*.py
145
+ packaging :
146
+ executor :
147
+ name : python3_6_1
148
+
149
+ steps :
150
+ - prepare-python-resources
57
151
58
152
- run :
59
- name : run tests
153
+ name : make deploy package
60
154
command : |
61
155
. venv/bin/activate
62
- # 全テスト実行
63
- python exec_test.py
156
+ ./packaging.sh
157
+
158
+ - persist_to_workspace :
159
+ root : .
160
+ paths :
161
+ - deploy/*
162
+
163
+ deploy-function :
164
+ executor :
165
+ name : python3_6_1
166
+
167
+ steps :
168
+ - deploy-resources :
169
+ target : ' function'
170
+
171
+ deploy-function02 :
172
+ executor :
173
+ name : python3_6_1
174
+
175
+ steps :
176
+ - deploy-resources :
177
+ target : ' function02'
178
+
179
+ deploy-api :
180
+ executor :
181
+ name : python3_6_1
182
+
183
+ steps :
184
+ - deploy-resources :
185
+ target : ' api'
186
+
187
+ deploy-permission :
188
+ executor :
189
+ name : python3_6_1
190
+
191
+ steps :
192
+ - deploy-resources :
193
+ target : ' permission'
194
+
195
+ labo :
196
+ docker :
197
+ - image : circleci/node:12.4.0
198
+
199
+ working_directory : ~/repo
200
+
201
+ steps :
202
+ - checkout
203
+
204
+ - attach_workspace :
205
+ at : .
206
+
207
+ - restore_cache :
208
+ keys :
209
+ - v1-npm-dependencies-{{ checksum "package-lock.json" }}
210
+ - v1-npm-dependencies-
211
+
64
212
- run :
65
- name : make deploy package
213
+ command : npm i
214
+
215
+ - save_cache :
216
+ paths :
217
+ - ./node_modules
218
+ key : v1-npm-dependencies-{{ checksum "package-lock.json" }}
219
+
220
+ - deploy :
221
+ name : Deployment
66
222
command : |
67
223
if [ $ALIS_APP_ID ]; then
68
- docker image build --tag deploy-image .
69
- docker container run -it --name deploy-container deploy-image
70
- docker container cp deploy-container:/workdir/vendor-package .
71
- . venv/bin/activate
72
- python make_deploy_zip.py
224
+ npm run deploy
73
225
fi
74
226
75
- - run :
76
- name : run deploy
227
+ notify-to-slack-for-approval :
228
+ executor :
229
+ name : python3_6_1
230
+
231
+ steps :
232
+ - slack/approval :
233
+ message : " 本番環境へのデプロイを承認してください"
234
+ color : " #F5E911"
235
+
236
+ bulk-deployment-to-production :
237
+ executor :
238
+ name : python3_6_1
239
+
240
+ steps :
241
+ - prepare-python-resources
242
+
243
+ - attach_workspace :
244
+ at : .
245
+
246
+ - aws-cli/install
247
+
248
+ - aws-cli/configure
249
+
250
+ - deploy :
251
+ name : Bulk deployment
77
252
command : |
78
- if [ $ALIS_APP_ID ]; then
79
- . venv/bin/activate
80
- ./deploy_api.sh
81
- ./fix_api.sh
82
- fi
253
+ . venv/bin/activate
254
+ ./deploy_api.sh
255
+ ./fix_api.sh
256
+
257
+
258
+ workflows :
259
+ # CloudFormationスタックの依存関係に即したワークフロー
260
+ build-deploy :
261
+ jobs :
262
+ - lint
263
+ - test
264
+ - packaging
265
+ - labo :
266
+ << : *ignore_master
267
+ << : *deploy_requires
268
+ - deploy-function :
269
+ << : *ignore_master
270
+ << : *deploy_requires
271
+ - deploy-function02 :
272
+ << : *ignore_master
273
+ << : *deploy_requires
274
+ - deploy-api :
275
+ << : *ignore_master
276
+ requires :
277
+ - deploy-function
278
+ - deploy-function02
279
+ - deploy-permission :
280
+ << : *ignore_master
281
+ requires :
282
+ - deploy-api
283
+
284
+ # 以下は本番環境へのデプロイ時のみ実行される
285
+ - notify-to-slack-for-approval :
286
+ << : *deploy_requires
287
+ << : *only_master
288
+ context : slack_notification
289
+ - approval :
290
+ << : *deploy_requires
291
+ << : *only_master
292
+ type : approval
293
+ - bulk-deployment-to-production :
294
+ << : *only_master
295
+ context : serverless_production
296
+ requires :
297
+ - approval
298
+ - labo :
299
+ << : *only_master
300
+ context : serverless_production
301
+ requires :
302
+ - approval
83
303
84
- - store_artifacts :
85
- path : test-reports
86
- destination : test-reports
0 commit comments