7
votes

I'm using Azure functions with GitHub deployment. I would like to place the function in src/server/functionName/ within the repo, but the deployment works only if the function is placed directly in functionName/

How do I deploy functions that are placed in subdirectories?

The documentation states

your host.json file and function folders should be directly at the root of what you deploy.

but "should" doesn't mean "must", right?

What I tried:

  • Various combinations of locations of host.json and function.json
  • In host.json I set routePrefix but it seems to affect only the function's URL: "http": { "routePrefix": "src/server" },
2
as for me I've created a separate branch to work around that. i was unable to find any way to put them anywhere else4c74356b41
FYI - the routePrefix setting doesn't refer to file paths, it refers to http routes. You only use that if you want to customize/change the default /api route.mathewc

2 Answers

10
votes

There are a few ways you can customize the deployment process. One way is by adding a custom deployment script to your repository root. When a .deployment script exists Azure will run that script as part of the deployment process as detailed here. E.g. you can write a simple script that copies the files and directories from your sub directory \src\server to the root, e.g.:

@echo off
echo Deploying Functions ...
xcopy "%DEPLOYMENT_SOURCE%\src\server" %DEPLOYMENT_TARGET% /Y /S

If you don't want to commit a .deployment file to your repo and your requirements are relatively simple, you can also do this via app settings by adding a PROJECT app setting to your function app with the value being your sub directory, e.g. src\server.

0
votes

Try setting the AZURE-FUNCTIONAPP_PACKAGE_PATH variable in .github/workflows/<something>.yml:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: 'azure/api' # set this to the path of your web app project, defaults to the repository root
  DOTNET_VERSION: '3.1.301'  # set this to the dotnet version to use