LoginSignup
12
11

More than 3 years have passed since last update.

StreamlitアプリケーションをGCP(GAE)にデプロイする方法

Posted at

0. フォルダ構成

application_directory
└Dockerfile
└app.py
└app.yaml
└requirements.txt

1. Dockerfileを作成する

以下のようなDockerfileを作成する

FROM python:3.7
EXPOSE 8080
WORKDIR /app
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
CMD streamlit run app.py --server.port 8080

※最後の行でstreamlit run app.pyとしているので、Pythonで書いたアプリケーションのファイルはapp.pyとなっていることを仮定しています。

2. requirements.txtを作成する

以下のようなファイルを作成する。

streamlit

※個人的には仮想環境下でアプリケーションの動作を確認した後に$ pip freeze > requirements.txtでrequirements.txtを作成するのがおすすめです。

3. app.yamlを作成する

app.yaml
runtime: custom
env: flex

※ここでflex環境を使わなければいけないのかどうかは私はよく分かっていません。standardでもいけるのかも。

4. デプロイする

GCP上で任意のプロジェクトを作成する。

作成したプロジェクトのホームページのナビゲーションメニューから「App Engine」に行き、App Engineアプリケーションを作成する。Languageは「Python」を選択し、Environmentは「フレキシブル」を選択する。

Google Cloud SDKをインストールしていなければ、ダウンロードおよびインストールをする。これでgloudコマンドが使えるようになる。

application_directory内で以下の操作を行う。

まず、必要に応じてSDKを初期化する。

$gcloud init

次に、App Engineにデプロイする。

$gcloud app deploy

参考

12
11
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
12
11