azure-functions-core-tools
azure-functions-core-tools copied to clipboard
Support for creating the zip archive only
When using Azure Functions Core Tools in conjunction with Terraform, you have to create the uploaded zip archive manually. Since azure-functions-core-tools already implemented the logic to create the archive, the archive could also be saved as file, provided via CLI, e.g. as --zip-only option.
https://github.com/Azure/azure-functions-core-tools/blob/dab8daca606d1a6f398b01b6f29ce8f081c34ec9/src/Azure.Functions.Cli/Actions/AzureActions/PublishFunctionAppAction.cs#L692
We don't have full documentation for this, but you could also use func pack which should create a zip file. func pack takes parameters similar to func azure functionapp publish.
Thanks for the suggestion. I didn't know the pack action. ~~But the zip archives generated by pack and uploaded by azure functionapp publish differ.~~
~~It seems that pack adds most of the root directory to the archive (e.g. node_modules). The method ZipHelper.GetAppZipFile() is called differently by both actions. Whereas the method is called with ignoreParser by the PublishFunctionAppAction, the ignoreParser is not set by the PackAction. Is it intended?~~
After some adaptions of the .funcignore file, the pack action matches my needs perfectly. :+1:
I've setup a TypeScript function app and removed all unnecessary files of the archive by the .funcignore:
- Replaced
*.js.map,*.tsby**.js.map,**.tsto ignore these files in subfolders, too. - Added
node_modulesto avoidnpm prunelocally. - Added
packag*.jsonandtsconfig.jsonbecause it isn't required in the archive.
Couldn't find any documentation about pack action and the supported syntax of the .funcignore file . Is there a reason?
Thanks. :smile:
Some extra documentation on this would be great! We're also using the pack function to create the ZIP files. On Python packages this seems to be working pretty well, but we have some issues with Node packages.
We have a Typescript project, each function has their own directory with an function.json (nothing unusual here).
Everything is compiled into a dist directory.
Now when we run func pack some things gets packaged, so we have;
- host.json
- dist/
- package.json
- node_modules (which is empty)
However, the directories with the function.json are missing. In some cases (seems quite random - locally it packages the dist directory but on our CI which is using the mcr.microsoft.com/azure-functions/node:3.0-node12-core-tools docker image it's missing). So we have to do dirty tricks like:
func pack -o build/$NAME --javascript
# For some reason; func pack doesnt do this for us;
find . -name function.json | xargs zip -ur build/$NAME.zip
zip -ur build/$NAME.zip dist
zip -ur build/$NAME.zip node_modules
.funcignore just contains the usual; of course double checked if function.json is not part of this ;-)
It would be great if func pack would be documented and if inconsistencies could be eliminated
This pack function is extremely useful in order to package and distribute an application, especially an open source one. It fits very well in a CI/CD pipeline.
Please, add at least the pack subcommand to the help message.