Azure FunctionsをGithub Actionsを使ってデプロイする
たぶんこの件に関する記事は書いてなかったと思います。
以下リポジトリをデプロイします。
https://github.com/xiaotiantakumi/azfunc-keyvault-sample
以前は関数アプリのリソースを作成後に設定していましたが、作成時にもGitHubのアカウント連携設定ができるようになってました。
まずは関数アプリリソースを作成します。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
入力内容としては以下のようにしています。リソースグループは新規作成でオッケーです。ここでは、key vaultコンテナ作成時に作っていたのでそれを使ってます。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
リソースのデプロイが完了すると、GitHub Actionが走り出します。デプロイされたことを確認します。
ちょっとミスって失敗してますが。。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
デプロイされたら関数を実行してみます。関数を選択します。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
名称から作成した関数を選びます。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
関数のエンドポイントとなるURLを取得します。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
URLをコピペしてブラウザとかで確認します。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ただ、今の状態だと構成情報を設定していないのでbodyに何も入って来ません。ソースは以下の通りで、構成情報の値を出力するようにしています。
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest
): Promise<void> {
const secret = process.env.KEY_VAULT_SECRET;
context.res = {
status: 200,
body: secret,
};
};
export default httpTrigger;
ということで、構成情報を設定します。構成から新しいアプリケーション設定を追加します。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
名称には、process.env.KEY_VAULT_SECRETで記載したキーとなるKEY_VAULT_SECRETを入力します。値に設定値を入れます。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
では、再度確認します。
うまく動きました。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
リソース作成後にGitHub Actionsの設定をしたい場合
既に関数アプリをデプロイしている場合は、デプロイ センターからGitHub Actionsとの連携設定ができます。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ディスカッション
コメント一覧
まだ、コメントがありません