Function ComputeとAPI GatewayにTravis CIからデプロイする
GitHubにpushしたFunction Compute用のコードをTravis CIからfunを使ってデプロイします。
やること
Function Compute用のjsファイルをTravis CIからFunction ComputeとAPI Gatewayに自動でデプロイします。
準備
以下を参考にしてまずローカルからfunを使ってFunction Computeにデプロイできるようになっていてください。
Function ComputeとAPI Gatewayのデプロイツールであるfunを使う - asmsuechan’s blog
.travis.ymlの追加
fun deploy
コマンドによって、node_modules/を含めてzipに固めてFunction Computeにデプロイしてくれます。
アクセスキー等は環境変数に入れておけばコマンド実行時に拾ってくれます。travis encrypt
で.travis.ymlに追加しておきましょう。
$ travis encrypt -r asmsuechan/fc_deploy_travis ACCESS_KEY_ID=xxxxxxxxxxxxxx --add $ travis encrypt -r asmsuechan/fc_deploy_travis ACCESS_KEY_SECRET=xxxxxxxxxxxxxxxxxxxxx --add $ travis encrypt -r asmsuechan/fc_deploy_travis ACCOUNT_ID=xxxxxxxxxxxx --add # エンドポイントの数字部分
funはnode.jsのバージョン8以上じゃないと動きません。
language: node_js node_js: - 8 install: - yarn script: - yarn run lint before_deploy: - yarn add global @alicloud/fun deploy: provider: script skip_cleanup: true script: - fun deploy on: repo: asmsuechan/fc_deploy_travis env: global: - secure: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - secure: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - secure: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - DEFAULT_REGION=cn-shanghai
REGION
じゃなくてDEFAULT_REGION
にしないとエラーが出ます。
Waiting for service fc to be deployed... TypeError: "config.region" must be passed in at new Client (/home/travis/build/asmsuechan/fc_deploy_travis/node_modules/@alicloud/fc2/lib/client.js:54:13) at getFcClient (/home/travis/build/asmsuechan/fc_deploy_travis/node_modules/@alicloud/fun/lib/deploy/deploy-support.js:39:10) at <anonymous> Script failed with status 255