Project Structure

How a Funcy Azure Project Looks Like

A basic Funcy Azure project contains the following directory structure:

admin.env
cloud.env
local.env
.deployment
deployment.cmd
f-project.json
f-resources-arm.json
.gitignore
host.json
lib
   |_index.js
   |_ package.json
myFunction
   |_ index.js
   |_ args.json
   |_ function.json

Here's the same directory structure with some explanations:

admin.env        // Service Principal credentials
cloud.env         // environment variables available in the cloud for all functions
local.env          // environment variables available locally for all functions
.deployment          // deployment configuration for KUDO 
deployment.cmd        // deployment script that will be executed by KUDO
f-project.json        // project data and settings
f-resources-arm.json  // Azure Resource Management template
.gitignore          // Funcy Azure specific ignores such as admin.env, cloud.env, ...
host.json          // Host configuration for Azure Function App
lib                    // Folder for shared code across all of your Azure Functions
   |_index.js
   |_ package.json
myFunction          // your first function
   |_ index.js      // your function code
   |_ args.json     // sample arguments to invoke your function locally
   |_ function.json   // your binding definitions

Now let's dive deeper into the most critical pieces of a Serverless project:

Project

Each Funcy Azure Project contains an f-project.json file that looks like this:

{
  "name": "projectname",
  "versionControl": {
    "type": "git",
    "location": "https://your.git.repository.git",
    "branch": "master"
  },
  "cors": {
    "allowedOrigins": [
      "https://functions.azure.com/"
    ]
  },
  "containerSize": 128
}

If you want the Azure Portal be able to talk to your app (e.g. in order to manually run a function from the portal), you need to keep the pre-defined allowedOrigin https://functions.azure.com. Add as many origins as you like.
The amount of RAM a function gets is defined on the Function App level. So every function in your project gets the same amount. Allowed values are starting from 128MB up to 1536MB in increments of 64MB.

Environment Files

You'll find three different .env files in your project folder (which are all git ignored):

  • admin.env: Holds the Service Principal credentials.
  • local.env: Holds the environment variables that are visible to your functions when executed locally.
  • cloud.env: Holds the environment variables that are visible to your functions when executed on Azure.

Deployment Files

As soon as you provision your project (through faz project provision) and have entered a valid Git repository in your f-project.json file, your function app is linked with that repository. So whenever you pushing upstream that new revision gets deployed automatically. The standard process, however, does not install your node dependencies. To account for this, Funcy Azure creates two files: .deployment and deployment.cmd which configure Kudo (which is the engine behind Git deployments on Azure) accordingly so that every time you are pushing upstream, Node.js dependencies (as defined in lib/package.json) are installed automatically. See official documentation https://github.com/projectkudu/kudu/wiki/Deployment-hooks for more details.

Resource Template

The file f-resources-arm.json is the Azure Resource Management Template used by Funcy Azure to provision the Function App and Dynamic Web App Plan. More information about the Dynamic App Plan can be found at https://azure.microsoft.com/en-us/documentation/articles/functions-scale/.

Function Code

Each function you define via faz function create lives in its own folder. We recommend to put third party dependencies and code that is shared amongst your functions in the lib folder.