azure-functions-pack icon indicating copy to clipboard operation
azure-functions-pack copied to clipboard

Proper usage

Open mderazon opened this issue 7 years ago • 3 comments

Not sure how to properly use this.

I have continuous deployment set up for the function via Github

  1. Should I commit .funcpack folder to Github ?
  2. Would azure function know not to download npm packages even though I have a package.json at the root of my function ?
  3. Should I have an npm run build script to first do npm install and then func pack ./ ?

A sample project would go a long way I think

Thanks.

mderazon avatar Feb 07 '18 18:02 mderazon

Over the last few days I've set my project up to use this tool. The way I'm using it right now is I'm installing it as a dev dependency and then added a script to my package.json like so

{
  "scripts": {
    "lint": "eslint **/*.js",
    "pack": "funcpack pack ./",
    "test": "npm run lint"
  },
  "devDependencies": {
    "azure-functions-pack": "1.0.0",
    "eslint": "4.17.0"
  }
}

Then in my appveyor.yml I've setup my build script like so

before_build:
  - npm run test

build_script:
  - npm run pack

after_build:
  - 7z a artifacts.zip %APPVEYOR_BUILD_FOLDER%\.funcpack
  - 7z a artifacts.zip %APPVEYOR_BUILD_FOLDER%\Notification-*\function.json
  - 7z a artifacts.zip %APPVEYOR_BUILD_FOLDER%\host.json

artifacts:
  - path: artifacts.zip
    type: Zip

And then to deploy I'm using the new Zip Push deployment provider to deploy the zip file from the build artifacts.

With this setup I can't really package everything up locally to test out the script, but the process is so simple it's easy to verify by checking the build artifacts of PRs. Plus all of my functions are in folders prefixed with Notification- which makes packing them up easier.

I tried playing around with the funcpack pack -c -o options but the resulting folder structure isn't what I was expecting (everything is put under the .funcpack folder) so I'm not sure if that's meant to be used as-is or if you're supposed to move those files/folders around some when you push them out for deployment.

For now I'm just grabbing the files manually to build my zip package. I think some clarification around the -c and -o options and examples of how you would use them to package up your functions would be helpful.

xt0rted avatar Feb 14 '18 03:02 xt0rted

@xt0rted this is exactly the build pipeline I am about to create. I agree clarification on the -c and -o options would be helpful!

necevil avatar Feb 15 '18 22:02 necevil

@mderazon to answer ONE of your questions: If you deploy like @xt0rted did using Zip Push Azure by default expects all dependencies to be properly installed / contained within your zip — in the case of Zip Push Deployment — Azure will ignore your package.json and not attempt to re-install already installed modules.

More info on Zip Push deployments can be found here: https://blogs.msdn.microsoft.com/appserviceteam/2017/10/16/zip-push-deployment-for-web-apps-functions-and-webjobs/

necevil avatar Feb 15 '18 23:02 necevil