LoginSignup
23
15

More than 3 years have passed since last update.

NuxtアプリをGitHub ActionsでGAE環境にデプロイする

Last updated at Posted at 2019-11-12

※ 現在、GitHub Actionsは現在ベータ版でこちらから申し込みできます。

GitHub Actionsの制限事項

  • リポジトリごとに最大20のワークフローを同時に実行可能
  • 1時間に実行できるAPIリクエストは、1つのリポジトリの全アクションで最大1000まで
  • ワークフローの各ジョブは、最大で6時間まで実行可能
  • 同時に実行できるジョブの数は、GitHubの契約プランによって異なる

※ 詳細は公式ドキュメントを参照
個人的な所感ですが、CircleCIよりも優秀な気がします。

事前準備

  1. GCPコンソールから、GitHub Actionsで利用するサービスアカウントを作成し、必要な役割(権限)を付与するgcp_service_account.png
  2. デプロイ用のアクセスキーをjson形式で発行+保存しておく key_create.png

ワークフロー/ジョブの設定

  • origin masterブランチにpushされた場合のみワークフローを実行する
  • Node.jsのバージョンを10.16.0で固定
  • yarn install / buildコマンド実行後に、Cloud SDK のCLIツールからデプロイを実行する

以下

.github/workflows/master.yml
name: CI

on:
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.16.0]

    steps:
    - uses: actions/checkout@v1
    - name: Run tests with ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: yarn install, build
      run: |
        yarn install
        NODE_ENV=production yarn run build
    - name: GAE deploy
          run: |
            echo 'github-actions@{GCPプロジェクト名}.iam.gserviceaccount.com' | gcloud auth activate-service-account --key-file {事前準備で保存したjsonキーファイル}
            gcloud app deploy app.yaml --project {GCPプロジェクト名}

          env:
            CI: true

公式テンプレートにubuntuが入ってたのでそのまま使ってみましたが、gcloudコマンドがデフォルトで使えて感動しました

指定したブランチにpushが走ると、以下のようにGitHub上でワークフローが回っているのが確認できます
actions.png

23
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
15