2
1

More than 3 years have passed since last update.

Azure App Service on Linux に Python Flaskアプリをデプロイ

Last updated at Posted at 2020-04-17

こちらに記載されている内容とほとんど同じです。
https://docs.microsoft.com/ja-jp/azure/app-service/containers/quickstart-python?tabs=bash

Azure CLI のインストール

brew update && brew install azure-cli

サンプルのダウンロード

git clone https://github.com/Azure-Samples/python-docs-hello-world

サンプルを実行する

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
export FLASK_APP=application.py
flask run

Web ブラウザーを開き http://localhost:5000/ にアクセスして、"Hello World! " というメッセージが表示されていることを確認。

Azure へのサインイン

az login

使用できるリージョンの確認

az account list-locations 

デプロイ

az webapp up コマンドを実行すると、App Service 上に Web アプリが作成され、コードがデプロイされます。

az webapp up --sku F1 -n <app-name> -l <location-name>

実行例

az webapp up --sku F1 -n test-app -l japanwest
{
  "URL": "http://test-app.azurewebsites.net",
  "appserviceplan": "taro.yamada_asp_Linux_japanwest_0",
  "location": "japanwest",
  "name": "test-app",
  "os": "Linux",
  "resourcegroup": "taro.yamada_rg_Linux_japanwest",
  "runtime_version": "python|3.7",
  "runtime_version_detected": "-",
  "sku": "FREE",
  "src_path": "//Users//fjunya//Documents//PyCharm//pa_workspace//Ibasho-Qanat-Stub"
}

結果に表示されたURLにアクセスするとアプリにアクセスが可能です。

--sku F1 引数を使用すると、Free 価格で Web アプリが作成されます。 この引数を省略すると、Premiumを使用することができます。その場合、時間単位のコストが発生します。

更新の再デプロイ

az webapp up

以下のエラーが出た場合はsubscriptionを指定すれば更新可能です。

Webapp pbx-api-stub already exists. The command will deploy contents to the existing app.
Unable to retrieve details of the existing app pbx-api-stub. Please check that the app is a part of the current subscription
# subscriptionを指定
az webapp up --subscription b43fdb54-b148-4d60-a89f-xxxxxxxxxxxx
2
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
2
1