koudenpaのブログ

趣味のブログです。株式会社はてなでWebアプリケーションエンジニアをやっています。職業柄IT関連の記事が多いと思います。

Azure Functionsの従量課金AppのZIPデプロイに容量不足で失敗したら発行時のアーキテクチャを指定するといいのかもしれない

タイトルが全て。.NETのバージョンは.NET6(関数アプリのインプロセスモデルが現状は6まで対応なので)。

あるFunction AppGitHub ActionsのActionでデプロイしようとしたら There is not enough space on the disk.\r\n\r\nが出力されるのが趣深い)で失敗してイラついていた。

App setting SCM_DO_BUILD_DURING_DEPLOYMENT propagated to Kudu container
Setting ENABLE_ORYX_BUILD in Kudu container to false
Update using context.kuduService.updateAppSettingViaKudu
Response with status code 204
App setting ENABLE_ORYX_BUILD propagated to Kudu container
Package deployment using ZIP Deploy initiated.
Fetching changes.
Cleaning up temp folders from previous zip deployments and extracting pushed zip file C:\local\Temp\zipdeploy\zcwve14g.zip (179.97 MB) to C:\local\Temp\zipdeploy\extracted
There is not enough space on the disk.\r\n
Error: Failed to deploy web package to App Service.
Error: Execution Exception (state: PublishContent) (step: Invocation)
Error:   When request Azure resource at PublishContent, zipDeploy : Failed to use D:\a\_temp\temp_web_package_7244580107888943.zip as ZipDeploy content
Error:     Package deployment using ZIP Deploy failed. Refer logs for more details.
Error: Deployment Failed!

file C:\local\Temp\zipdeploy\zcwve14g.zip (179.97 MB)

とのことなので、展開前で180MBほどの容量があるっぽいけれど、展開したって一桁GBにはおさまるだろう? そんなしょっぱい容量でディスクが枯渇していいのか?

とは言え、従量課金でやりたい(し、App Service PlanのFreeにしても容量が劇的に容量が増えるわけでもないだろう)ので、何とかデプロイが通るようにしたい。

デプロイ用の成果物には実行環境以外のアーキテクチャアセンブリも同梱されている雰囲気があったので、ビルド時にランタイムとアーキテクチャを指定したら疎通した。

    - name: Restore
      run: dotnet restore "${{ env.WORKING_DIRECTORY }}" --runtime win-x64
    - name: Build
      run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --arch x64 --no-restore
    - name: Publish
      run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --arch x64 --no-build --output "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}"

dotnet restoredotnetdotnet build,dotnet publish--arch x64が該当箇所。

コマンド毎に指定の仕方がちょっと違うのはなんでか分かっていない(runtime(RID)が正で、archはそれの簡易構文らしいが、分けるメリットがよく分からん)。

各プロジェクトファイルに妥当な指定がされていればdotnetコマンドのオプションは不要っぽいのだが、そんなものを精査するよりオプション指定してしまった方が手っ取り早いのでそうした。趣味の遊びでDeep Diveしたい領域ではない。

指定前

The raw size of all the files that were specified for upload is 424107130 bytes
The size of all the files that were uploaded is 171362747 bytes. This takes into account any gzip compression used to reduce the upload size, time and storage

指定後

The raw size of all the files that were specified for upload is 271871447 bytes
The size of all the files that were uploaded is 103138755 bytes. This takes into account any gzip compression used to reduce the upload size, time and storage

オチ(この画像を生成するFunction Appのデプロイに失敗していた)もついてちょうどよい。そんな感じ。