Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change to GitHub Flow #370

Merged
merged 7 commits into from Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
223 changes: 131 additions & 92 deletions .circleci/config.yml
Expand Up @@ -23,19 +23,25 @@ references:
- test_parallel4
- test_parallel5
- packaging
require_approval: &require_approval
require_approval: &require_approval_and_packaging
requires:
- approval
staging_steps: &staging_steps
- packaging
other_env_steps: &other_env_steps
<<: *ignore_master
# AlisProjectアカウントでもビルドは実行されるため、Contextはserverless_stagingを使用している
# フォークしたリポジトリで作業する際は、同名のContextを各自の環境に設定する必要がある
context: serverless_staging
staging_steps: &staging_steps
<<: *only_master
context: serverless_staging
production_steps: &production_steps
<<: *only_master
context: serverless_production

orbs:
aws-cli: circleci/aws-cli@0.1.13
slack: circleci/slack@3.2.0
slack: circleci/slack@3.3.0
jira: circleci/jira@1.0.5

executors:
Expand Down Expand Up @@ -105,9 +111,10 @@ commands:
at: .

- deploy:
name: Deployment
name: 'Deployment'
command: |
if [ $ALIS_APP_ID ]; then
# masterブランチであるか、フォークした環境であればデプロイを行う
if [ $CIRCLE_BRANCH == 'master' ] || [ $CIRCLE_PROJECT_USERNAME != 'AlisProject' ]; then
. venv/bin/activate
./deploy.sh << parameters.target >>
fi
Expand Down Expand Up @@ -153,9 +160,7 @@ commands:

jobs:
lint:
executor:
name: python3_6_1

executor: python3_6_1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

リファクタリングして省略記法へ変更。

steps:
- prepare-python-resources:
resource: 'requirements_test.txt'
Expand All @@ -172,12 +177,10 @@ jobs:
. venv/bin/activate
pyflakes src tests ./*.py

# 本来は CircleCIの parallelism を使用したいがLabmdaのテストは少々特殊なため難しく、力技で並列化している
# 本来は CircleCIの parallelism を使用したいがLambdaのテストは少々特殊なため難しく、力技で並列化している
# 効率的なワークフローとするため、個々のテストはpackagingの実行時間を下回ることを目標とする
test_parallel1:
executor:
name: test

executor: test
steps:
- prepare_test

Expand All @@ -186,27 +189,21 @@ jobs:
options: '--ignore /handlers/me/articles/public,/handlers/me/articles/drafts,/handlers/me/articles/purchase,/handlers/me/articles/comments,/handlers/articles,/handlers/me/comments,/handlers/search'

test_parallel2:
executor:
name: test

executor: test
steps:
- prepare_test
- run_tests:
options: '--target /handlers/me/articles/public'

test_parallel3:
executor:
name: test

executor: test
steps:
- prepare_test
- run_tests:
options: '--target /handlers/me/articles/drafts'

test_parallel4:
executor:
name: test

executor: test
steps:
- prepare_test
- run_tests:
Expand All @@ -215,9 +212,7 @@ jobs:
options: '--target /handlers/me/articles/purchase'

test_parallel5:
executor:
name: test

executor: test
steps:
- prepare_test
- run_tests:
Expand All @@ -228,9 +223,7 @@ jobs:
options: '--target /handlers/search'

packaging:
executor:
name: python3_6_1

executor: python3_6_1
steps:
- prepare-python-resources

Expand All @@ -245,45 +238,35 @@ jobs:
paths:
- deploy/*

deploy-function: &deploy-function
executor:
name: python3_6_1

deploy-function:
executor: python3_6_1
steps:
- deploy-resources:
target: 'function'

deploy-function-production: *deploy-function
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ワークフローを分けたためproduction専用のジョブは不要となりました。


deploy-function02: &deploy-function02
executor:
name: python3_6_1

deploy-function02:
executor: python3_6_1
steps:
- deploy-resources:
target: 'function02'

deploy-function-production02: *deploy-function02

deploy-api: &deploy-api
executor:
name: python3_6_1

deploy-api:
executor: python3_6_1
steps:
- deploy-resources:
target: 'api'

deploy-api-production: *deploy-api

deploy-permission: &deploy-permission
executor:
name: python3_6_1

deploy-permission:
executor: python3_6_1
steps:
- deploy-resources:
target: 'permission'

deploy-permission-production: *deploy-permission
deploy-alarms:
executor: python3_6_1
steps:
- deploy-resources:
target: 'apialarms'

labo:
docker:
Expand All @@ -303,7 +286,7 @@ jobs:
- v1-npm-dependencies-

- run:
command: npm i
command: npm ci
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ついでにpackage-lock.jsonを使用するよう変更。


- save_cache:
paths:
Expand All @@ -317,10 +300,8 @@ jobs:
npm run deploy
fi

fix-api: &fix-api
executor:
name: python3_6_1

fix-api:
executor: python3_6_1
steps:
- prepare-python-resources

Expand All @@ -335,32 +316,78 @@ jobs:
. venv/bin/activate
./fix_api.sh

fix-api-production: *fix-api

notify-to-slack-for-approval:
executor:
name: python3_6_1

executor: python3_6_1
steps:
- slack/approval:
message: "本番環境へのデプロイを承認してください"
color: "#F5E911"


# CloudFormationスタックの依存関係に即したワークフローとなっている
workflows:
# CloudFormationスタックの依存関係に即したワークフロー
build-deploy:
# masterブランチ以外への更新で実行される、その他環境用ビルド
# デプロイが実行されるのはフォークした環境のみ
other-env-build:
jobs:
- lint
- test_parallel1
- test_parallel2
- test_parallel3
- test_parallel4
- test_parallel5
- packaging
- lint:
<<: *other_env_steps
- test_parallel1:
<<: *other_env_steps
- test_parallel2:
<<: *other_env_steps
- test_parallel3:
<<: *other_env_steps
- test_parallel4:
<<: *other_env_steps
- test_parallel5:
<<: *other_env_steps
- packaging:
<<: *other_env_steps

- labo:
<<: *other_env_steps
<<: *deploy_requires
- deploy-function:
<<: *other_env_steps
<<: *deploy_requires
- deploy-function02:
<<: *other_env_steps
<<: *deploy_requires
- deploy-api:
<<: *other_env_steps
requires:
- deploy-function
- deploy-function02
- deploy-permission:
<<: *other_env_steps
requires:
- deploy-api
- fix-api:
<<: *other_env_steps
requires:
- deploy-api
post-steps:
- jira/notify

# ステージング環境
staging:
jobs:
- lint:
<<: *staging_steps
- test_parallel1:
<<: *staging_steps
- test_parallel2:
<<: *staging_steps
- test_parallel3:
<<: *staging_steps
- test_parallel4:
<<: *staging_steps
- test_parallel5:
<<: *staging_steps
- packaging:
<<: *staging_steps

# ステージング環境(本番環境以外)のワークフロー
- labo:
<<: *staging_steps
<<: *deploy_requires
Expand All @@ -370,50 +397,62 @@ workflows:
- deploy-function02:
<<: *staging_steps
<<: *deploy_requires

- deploy-api:
<<: *staging_steps
requires:
- deploy-function
- deploy-function02

- deploy-permission:
<<: *staging_steps
requires:
requires: &require-api-staging
- deploy-api
- deploy-alarms:
<<: *staging_steps
requires: *require-api-staging
- fix-api:
<<: *staging_steps
requires:
- deploy-api
requires: *require-api-staging
post-steps:
- jira/notify


# 本番環境のワークフロー
- notify-to-slack-for-approval:
# 本番環境(テスト等無し・承認付き)
production:
jobs:
# stagingで同時にテストを行っているため本番環境ワークフローではテストを行わない
- packaging:
<<: *production_steps
<<: *deploy_requires
- notify-to-slack-for-approval:
<<: *only_master
context: slack_notification
- approval:
<<: *production_steps
<<: *deploy_requires
type: approval

- labo:
<<: *production_steps
<<: *require_approval
- deploy-function-production:
<<: *require_approval_and_packaging
- deploy-function:
<<: *production_steps
<<: *require_approval
- deploy-function-production02:
<<: *require_approval_and_packaging
- deploy-function02:
<<: *production_steps
<<: *require_approval
- deploy-api-production:
<<: *require_approval_and_packaging

- deploy-api:
<<: *production_steps
requires:
- deploy-function-production
- deploy-function-production02
- deploy-permission-production:
- deploy-function
- deploy-function02

- deploy-permission:
<<: *production_steps
requires:
- deploy-api-production
- fix-api-production:
requires: &require-api-production
- deploy-api
- deploy-alarms:
<<: *production_steps
requires:
- deploy-api-production
requires: *require-api-production
- fix-api:
<<: *production_steps
requires: *require-api-production
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,8 @@
"build": "python make_deploy_zip.py --target 'src/handlers/labo/**/handler.py'",
"deploy": "npx sls deploy",
"remove": "npx sls remove",
"invoke": "npx sls invoke -f"
"invoke": "npx sls invoke -f",
"cilint": "circleci config validate -c .circleci/config.yml"
},
"devDependencies": {
"cfn-lint": "^1.9.7",
Expand Down