LoginSignup
4
0

More than 5 years have passed since last update.

Azure Functions CLI + Node + Mac で extension を追加する

Posted at

これも自分用のメモ。Azure Functions では、トリガーとかの extension 追加する方法があるみたい。特に、C# だったらたまに記事を見かける。

Azure Functions に Extension を追加したい。Node + Mac で

それはええねんけど、わし、Mac で Node 書いているねんけど、こういうときカスタムのエクステンション追加したいときどうなるんよ。これ、思いっきり nuget やし。例えばこれ。

これは、今は、コマンドラインで楽勝でできるみたい。CLI を使って。

Azure Functions CLI をアップデートする

Azure Functions の CLI が古いとダメみたい。私のダメだったバージョンは、これ。

$ func --help

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (2.0.0)
Function Runtime Version: 2.0.11280.0
Usage: func [context] [context] <action> [-/--options]

Contexts:
azure      Commands to log in to Azure and manage resources
function   Commands for creating and running functions locally
host       Commands for running the Functions host locally
settings   Commands for managing environment settings for the local Functions host
templates  Commands for listing available function templates

アップデートしてみよう。私が使っているのは preview のものだから、@core が付いている。これは、Azure Functions の 2.0

$ npm uninstall -g azure-functions-core-tools@core 
$ npm install -g azure-functions-core-tools@core --unsafe-perm

がっつり入れ替え。

$ func

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (2.0.0)
Function Runtime Version: 2.0.11308.0
Usage: func [context] [context] <action> [-/--options]

Contexts:
azure       Commands to log in to Azure and manage resources
extensions  Commands for installing extensions
function    Commands for creating and running functions locally
host        Commands for running the Functions host locally
settings    Commands for managing environment settings for the local Functions host
templates   Commands for listing available function templates

おお、新たなサブコマンドが増えている。

エクステンションのインストール

func extensions install コマンドを使う。ログの通り、FunctionApp のディレクトリに、functions-extensions というディレクトリができてそこに、格納される。これらは、.NET Core のライブラリ

$ func extensions install -p Microsoft.Azure.WebJobs.Extensions.CosmosDB -v 3.0.0-beta4
  Writing /var/folders/5b/rt6_lb397_3d92vp67g98pgr0000gn/T/tmp5igzx3.tmp
info : Adding PackageReference for package 'Microsoft.Azure.WebJobs.Extensions.CosmosDB' into project '/Users/ushio/Codes/Azure/carreviewbackend/functions-extensions/extensions.csproj'.
log  : Restoring packages for /Users/ushio/Codes/Azure/carreviewbackend/functions-extensions/extensions.csproj...
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.azure.webjobs.script.extensionsmetadatagenerator/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.azure.webjobs.script.extensionsmetadatagenerator/index.json 896ms
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.azure.webjobs.script.extensionsmetadatagenerator/1.0.0-beta2/microsoft.azure.webjobs.script.extensionsmetadatagenerator.1.0.0-beta2.nupkg
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.azure.webjobs.script.extensionsmetadatagenerator/1.0.0-beta2/microsoft.azure.webjobs.script.extensionsmetadatagenerator.1.0.0-beta2.nupkg 935ms
log  : Installing Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator 1.0.0-beta2.
info : Package 'Microsoft.Azure.WebJobs.Extensions.CosmosDB' is compatible with all the specified frameworks in project '/Users/ushio/Codes/Azure/carreviewbackend/functions-extensions/extensions.csproj'.
info : PackageReference for package 'Microsoft.Azure.WebJobs.Extensions.CosmosDB' version '3.0.0-beta4' added to file '/Users/ushio/Codes/Azure/carreviewbackend/functions-extensions/extensions.csproj'.

Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  extensions -> /Users/ushio/Codes/Azure/carreviewbackend/bin/extensions.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.57

おおお!入ったっぽい!これで、Azure Functions 2.0 でも、Cosmos DB のバインデイングが使えるように!

エクステンションをAzure で使う

で、ローカルはこれでええけど、Azure どうするのよ。これが、もっと簡単だった。

func azure functionapp publish FUNCTION_APP_NAME これだけで、Azure にアップロードしてくれるみたい。

$ func azure functionapp publish carreviewver2
Publish /Users/ushio/Codes/Azure/carreviewbackend contents to an Azure Function App. Locally deleted files are not removed from destination.
Getting site publishing info...
Creating archive for current directory...
Uploading archive...
Upload completed successfully.

Azure で確認

Azure Functions の DEVELOPMENT TOOL > Console で確認して見る。うん。入ってる!これはいけてるな!まだプレビューだけど。

Screen Shot 2017-10-10 at 11.15.52 PM.png

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