3
1

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 3 years have passed since last update.

cloud build の設定方法メモ書き

Posted at

GCPでCI/CDを検討していて、Cloud buildついて調べたのでまとめたいと思います。

概要

Cloud build はGCPが提供するフルマネージド型のCI/CDで,特定のイベントに対して自分の処理を差し込みCI/CDを実現します。
また、githubなど既存のrepositoryと連携させたり、CLoud Source REpositoryなどのGCP上のリポジトリにも連携させることができます。

イベントの設定方法

イベントの設定方法はシンプルでgithubでの連携だと

スクリーンショット 2021-04-24 6.09.58.png

対象リポジトリに対して

  • 特定のブランチに対してpushされた時、
  • tagがpushされたとき
  • pull request

になります。

また詳細な設定として

スクリーンショット 2021-04-24 6.13.09.png

  • ビルド設定ァイルの指定
  • ビルド設定ファイルの置き場所
  • 代入変数

などの指定が行えます。

代入変数とは、設定ファイルで使いまわしたい値をKEY-VALUEの形で登録しておき、ビルドファイルにKEYを入れると、VALUEが展開される機能です。

ここで注意なのですが、Cloud buildが言うビルドとは、ビルド設定ファイルに書かれている処理を実行することであり、ソースを実際にコンパイルすることではないです。
なので、CI/CDの処理の記述はビルドファイルに記載することになります。

設定ファイルの書き方

ビルド設定ファイルはyaml,jsonから選べます。
全体の値は下記の通りです。

steps:
- name: string
  args: [string, string, ...]
  env: [string, string, ...]
  dir: string
  id: string
  waitFor: [string, string, ...]
  entrypoint: string
  secretEnv: string
  volumes: object(Volume)
  timeout: string (Duration format)
- name: string
  ...
- name: string
  ...
timeout: string (Duration format)
queueTtl: string (Duration format)
logsBucket: string
options:
 env: [string, string, ...]
 secretEnv: string
 volumes: object(Volume)
 sourceProvenanceHash: enum(HashType)
 machineType: enum(MachineType)
 diskSizeGb: string (int64 format)
 substitutionOption: enum(SubstitutionOption)
 logStreamingOption: enum(LogStreamingOption)
 logging: enum(LoggingMode)
substitutions: map (key: string, value: string)
tags: [string, string, ...]
serviceAccount: string
secrets: object(Secret)
availableSecrets: object(Secrets)
artifacts: object (Artifacts)
images:
- [string, string, ...]

今回は大まかn部分のみ解説します。

step

stepは簡単に言うと処理のまとめです。この中で使うパッケージやタイムアウト、環境変数などを指定して、コマンドを実行します。

name

これは cloud builderを指定します。cloud builderとは特定の言語のよく使うパッケージをインストールしたイメージです。javaであればgradle, rubyであればbundleといったものです。これを指定することで言語毎に使用するパッケージマネージャーを使えるようにします。

args

これは nameで指定した環境で実行するコマンドの引数です。

env

これは環境変数を指定します。

サンプル

簡単なサンプルだと以下のようなものになります。

steps:
  - name: 'spotlightcybersecurity/python-pipenv-builder'
    args: ['install']
  - name: 'spotlightcybersecurity/python-pipenv-builder'
    args: ['run','pelican','content','-o','output','-s','publishconf.py']
  - name: gcr.io/cloud-builders/gcloud
    entrypoint: gsutil
    args: ["-m", "rsync", "-R", "-c", "-d", "./output", "gs://YOURBUCKETHERE"]

上記のように
step -> name -> args といった形でコマンドと実行順を指定します

最後に

クラウドごとに思想が違うので,CI/CDや設定ファイルに特色が出ていて学ぶたびに結構を面をくらいます。
それでは良い cloud buildライフを

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?