14
10

More than 3 years have passed since last update.

GitHub Actions から Azure にデプロイ!

Posted at

ちょっと目を離してるうちに GitHub Actions の Azure 向けのものが充実してますね!
GitHub Actions for deploying to Azure

ということで試してみましょう。Azure 側に Function App を 1 つ作っておきます。

そして、適当に GitHub に node の Azure Functions を作ってしまいましょう。

以下のコマンドで生成してものを使ってみましょう。

> func init
node
> func new
8. Http trigger
Function name: HttpTrigger1
> npm install

以下のコマンドで実行して動作確認んをしましょう

> func host start

ばっちり動いてます。name パラメーターつけて叩くと Hello って付けて返してくれるデフォルトのテンプレートのやつですね。

image.png

GitHub に適当なリポジトリ(ghactionsfunctions という名前で作りました)に push しておきましょう。

> git init
> git add --all
> git remote add origin https://github.com/runceel/ghactionsfunctions.git
> git push -u origin master 

本題

さて、やっと本題です。デプロイしよう!
とりあえず Starter Action Workflows to deploy to Azure のリポジトリに沢山サンプルがあります。

Node.js の Azure Functions をデプロイするためのサンプルの windows-node.js-functionapp-on-azure.yml というのがありますね。

これをベースにしてみましょう。リポジトリの Actions から新しい Workflow を作って、上のファイルの内容を張り付けて編集していきます。

ます、env: のところを自分に合わせて書き換えます。

env:
  AZURE_FUNCTIONAPP_NAME: ghactions   # set this to your application's name
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'      # set this to the path to your web app project, defaults to the repository root
  NODE_VERSION: '12.x'                     # set this to the node version to use (supports 8.x, 10.x, 12.x)

publish-profile として ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} を使ってるのでリポジトリの Settings に Secrets という項目があるので、ここに AZURE_FUNCTIONAPP_PUBLISH_PROFILE という名前の Secret を作ります。Value には Azure ポータルからデプロイ先の Function App を選択して「発行プロファイルの取得」でダウンロードできるファイルの中身を設定しましょう。

取得して…

image.png

設定!

image.png

シークレットも作ったら GitHub Actions の YAML ファイルを保存しましょう。そうすると、今回は push の度に走るので、自動的に走り始めます。

image.png

暫く待ってると…、

image.png

いい感じの実行結果が出ました。
ポータルを覗いてみると HttpTrigger1 が Function App に出来てるので URL を取得します。

image.png

ちゃんと動いてますね。

image.png

あとはスワップとかにも対応させたいけど、AppService を swap させる専用のものはなさそうなので、Azure CLI の GitHub Actions あたりでやる感じかな。

後で時間を見てやってみよう。

14
10
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
14
10