0
0

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.

Google App Engine Ruby FlexibleでDockerイメージをいろいろカスタマイズする方法

Last updated at Posted at 2019-10-24

概要

Google App Engine Ruby Flexible環境で、Pythonや機械学習など、Ruby以外のなにかを使いたい場合に、Dockerイメージをカスタマイズできると便利です。

その方法はドキュメントに記載されていませんが、以下を読むとわかります。

その解説です。

環境変数

以下のように環境変数を設定できる。


runtime: ruby
env: flex
service: api-production

env_variables:
  LC_ALL: C.UTF-8
  LANG: C.UTF-8

PATHは設定できないので注意

PATHの変更は禁止されている。
PATHを変更すると、デプロイ時のバリデーションが失敗して、デプロイができない。

ubuntuパッケージ

以下のようにubuntuパッケージをインストールできる。

runtime: ruby
env: flex
service: api-production

runtime_config:
  packages:
    - postgresql
    - tmux
    - vim

カスタムインストールスクリプト

以下のようにすると、カスタムインストールスクリプトを実行できる。最後のほうで実行される。

runtime: ruby
env: flex
service: api-production

runtime_config:
  build:
    - 'sh script/install_python.sh'

注意

Ruby FlexibleのDockerイメージはステップに分かれてビルドされるので、最終的なイメージには、/app配下しか残らない。/app配下にインストールする必要がある。

参考: https://github.com/GoogleCloudPlatform/ruby-docker/blob/master/ruby-generate-dockerfile/app/Dockerfile.erb#L191

ビルドタイムアウト

問題

ubuntuパッケージやカスタムインストールスクリプトを設定するとDockerのビルド時間が長くなって、App Engineのビルドタイムアウトにひっかかってしまう。

以下のようなエラーが出る。

ERROR: (gcloud.app.deploy) Cloud build failed. Check logs at https://console.cloud.google.com/xxxxxxxx/ Failure status: UNKNOWN: Error Response: [4] DEADLINE_EXCEEDED

解決策

以下のコマンドでビルドタイムアウトを伸ばせる。1000の部分は好きな秒数に設定。

gcloud config set app/cloud_build_timeout 1000

注意

以下の記事では、上記の解決策が使えないようなことが書いているが、使えた。

cloud_build_timeout is 10 minutes. I tries to set it to more than 10 min but it doesn't work. – AsmaG Mar 15 at 15:31

独自のDockerfileを使う方法との比較

独自のDockerfileを直下に配置すれば、そのDockerfileでDockerイメージをビルドできますが、cloud_sql_instancesなども自前で実装しないといけないので、面倒です。

App Engineの作法に則ってカスタマイズするほうが楽だと思います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?