9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CircleCI Orbsを用いてGoogle App Engine へデプロイ

Last updated at Posted at 2019-05-25

CircleCI Orbs とは何か?

CircleCIの設定(jobやcommand)を共有可能なパッケージにしたもの
以下、公式ドキュメント抜粋

CircleCI Orbs are shareable packages of configuration elements, including jobs, commands, and executors.

ちなみにOrbsはココから検索できる。

Orbs を使うと何が良くなる?

(思い付くところ)

  • パッケージを活用することでき、CIフローの実装スピード向上につながる
  • コード量を削減でき、config.ymlのメンテナンス性向上につながる

実際に Orbsを使ってみる

今回はシンプルに、Google Cloud CliのOrbを用いて以下の処理を実装した。
1.GitHubのレポジトリからコードをチェックアウト
2.gcloud CLIの初期化 (GCPのプロジェクトID, Compute Zone, Service Keyの設定。※環境変数の事前設定要)
3.Google App Engineへテストアプリをデプロイ

環境変数の設定

CircleCIの対象プロジェクトでBUILD SETTING -> Enviroment Variablesにて以下の項目を設定

  • GOOGLE_COMPUTE_ZONE
  • GOOGLE_PROJECT_ID
  • GCLOUD_SERVICE_KEY

Config.ymlの記述

version情報の直後に以下の内容を記載。
orbs: gcp-cli: circleci/gcp-cli@1.3.0

CLIの初期化処理は以下の1行のみの追加でOK!
- gcp-cli/initialize

Config全体は以下の通り

config.yml
version: 2.1
orbs:
  gcp-cli: circleci/gcp-cli@1.3.0

jobs:
  build:
    working_directory: ~/repo
    docker:
      - image: google/cloud-sdk:latest

    steps:
      - checkout
      - gcp-cli/initialize
      - run:
          name: Deploy to Google App Engine
          command: |
            gcloud --quiet app deploy app.yaml --version=test

実行結果
ci0525.png

所感

Orbsを利用する前は、GAEにデプロイするため、
環境変数の情報をjson形式で出力し、gcloud auth activate-service-account を実行。
gcloud --quiet config set projectでプロジェクトIDの設定を行っていた。
上記の内容が- gcp-cli/initializeの1行でできるのはとてもうれしい。

今後はできるだけOrbsを活用することで、configファイルをシンプルに保ちながら、CI/CDの品質・スピードを高めることができそうだ。

その他参考にしたサイト

9
7
1

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
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?