株式会社ノハナ junpayment
CIジョブでファイヤーウォールを
突破するハナシ!
Powered by
野村順平
@junpayment
株式会社ノハナ
サーバサイドテックリード
GCP,GKE,Go…
釣り
● 福岡出身
● Windows,Linux組み込み系
● ソーシャルゲーム業界
● ノハナ入社
DB依存するテスト
https://support.circleci.com/hc/en-us/articles/115014372807-IP-Address-ranges-for-whitelisting-
• DB,既存レコードに依存するテスト
• DBがVPCに存在,IP制限
• テスト書き直す<回避を選択
• CircleCIは実行ホストIP固定できない
こうしました
https://github.com/junpayment/circleci20200805/blob/master/.circleci/co
nfig.yml
1 FW rule作る
2 テストする
3 FW rule削除する
4 テスト結果をビルド結果に反映
when: always
これで良かった
https://github.com/junpayment/circleci20200805/blob/usealways/.circlec
i/config.yml
ジョブ前後でFWに穴あける
- run:
name: add a temporary firewall
command: |
export SOURCE_RANGE=`curl http://ifconfig.me/`
gcloud compute firewall-rules create circleci-${CIRCLE_WORKFLOW_ID}-${CIRCLE_BUILD_NUM} 
--network=default 
--action=allow 
--target-tags=mongo 
--source-ranges=${SOURCE_RANGE} 
--rules=tcp:27017-27019 || true
:
- run:
name: delete the temporary firewall
command: |
gcloud compute firewall-rules delete circleci-${CIRCLE_WORKFLOW_ID}-${CIRCLE_BUILD_NUM} --quiet
テスト結果のエラーとFWエラー
- run:
name: test
command: |
curl https://dl.google.com/go/go1.14.6.linux-amd64.tar.gz -o go1.14.6.linux-amd64.tar.gz
tar -C /usr/local -xzvf go1.14.6.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go vet ./... || echo "export VET_RESULT=${?}" >> $BASH_ENV
go test ./... || echo "export TEST_RESULT=${?}" >> $BASH_ENV
:
- run:
name: exit with error code if error occured
command: |
echo "TEST_RESULT: ${TEST_RESULT:-0}"
echo "VET_RESULT: ${VET_RESULT:-0}"
exit $((${VET_RESULT:-0} + ${TEST_RESULT:-0}))
本番上げる前に待つ
deploy-production:
jobs:
- test:
filters:
branches:
only:
- master
- slack/approval-notification:
message:
requires:
- test
- hold:
type: approval
requires:
- slack/approval-notification
- deploy:
requires:
- hold
context: production

CircleCIコミュニティミートアップLT資料