Azure functions github deployment from subfolder - azure

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" },

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.

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

Related

AWS Elastic beanstalk - My deployed app can't seem to write pdf's into this directory i've set up in my project folder

I am currently using nodejs that is deployed in ebs on aws. I have a function that will write a pdf and then email it off but it says the file path can't be found. I've verified the project file seems to be /var/app/current/, but changing the reference of the file path doesn't seem to remove the error. Any idea how to go about fixing this?
The /var/app/current/ does not exist initially. Its only created at the very last stage of your deployment.
The deployment happens in /var/app/staging/ folder, and at the very last, once everything finishes, /var/app/staging/ is moved into /var/app/current/.
Thus, I would not recommend using absolute paths in your project or config files. Its better to use relative path or container_commands for config scripts:
The specified commands run as the root user, and are processed in alphabetical order by name. Container commands are run from the staging directory, where your source code is extracted prior to being deployed to the application server.

Environment Variable replacement in Nuget.config

We have dotnet core application with Nuget.config file . As part of azure devops CI pipeline, we want to read and replace environment variables in Nuget.config file. Environment/Pipeline variables(USERNAME and PWD) are configured in "Build Docker Image" Task in CI pipeline. The azure devops CI build server runs on Ubuntu machine.
Environment variables in MAC/Linux should be replaced in following way as per this documentation.
The syntax "$USERNAME" in Nuget.config is not working here. When we replace static username and password, it works fine.
Nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="abcFeed" value="https://somedevops.com/xyz/packaging/someApps/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <abcFeed>
      <add key="Username" value="$USERNAME"/>
      <add key="ClearTextPassword" value="$PWD"/>
    </abcFeed>
  </packageSourceCredentials>
</configuration>
We have tried below syntax with following documentation, none of them are working: $USERNAME, $(USERNAME), %USERNAME%, $USERNAME$
https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#example-config-file
https://intercom.help/appcenter/en/articles/2216043-restore-private-azuredevops-package-management-feeds-using-pat.
Setting an environment variable in a NuGet.Config file
What is correct syntax or way of replacing environment variables in Nuget.config file with azure devops pipeline?
You could use a Replace Tokens task instead, and configure this to process your nuget.config file.
However, you may want to consider using a Nuget service connection as that will avoid having to save the Nuget credentials as pipeline variables and also make them more secure as they will be exposed in plain text when replaced in the config file.
For more information about using Service Connections in Azure DevOps, see the Microsoft documentation at: https://learn.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#sep-nuget
I believe our nuget docs need correcting. Use the same characters for environment variable replacement, regardless of platform: %myPW%
I tested successfully with dotnet.exe 3.0.100 on Ubuntu 18.*
Please engage with me on the tracking issue I have assigned to me: https://github.com/NuGet/Home/issues/8662

Gitlab CI Web Deployment

So we are currently moving away from our current deployment provider: Beanstalk, which is great but we are on the top tier and we keep running out of space or hitting our repository limits. So we are moving away so please do not suggest any other SaaS provider.
I personally use Gitlab for my own projects and a few company projects and it's amazing we use a self hosted version on our local server in our company building.
We have CI setup and currently are using the following deployment code (I have minified the bits just to the deployment for development) - this uses the shell executer for deploying as we deploy to an existing linux server.
variables:
HOSTNAME: '<hostname>'
USERNAME: '<username>'
PASSWORD: '<password>'
PATH_DEV: '/path/to/www'
# Define the stages (we can add as many as we want)
stages:
# - build
- deploy
# The code for development deployment
deploy_dev:
stage: deploy
script:
- echo "Deploying to development environment..."
- rm .gitlab-ci.yml
- rsync -urltvz --filter=':- .gitignore' --exclude=".git" -e "sshpass -p"$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" * $USERNAME#$HOSTNAME:$PATH_DEV
- echo "Finished deploying."
environment:
name: Development
url: http://dev.domain.com
only:
- envdev
The Problem:
When we use the above code to deploy it's perfect and works really well, and it deploys all the code after optimisation etc, but we have found a little bug here.
When you delete a file then the rsync command will not delete the file, now I did some searching and found the --remove flag you can add, and it worked - but it deleted all the user uploaded content as well. Now I added the .gitignore in to the filtering, so it would ignore some the files in their (which are usually user generated) or configuration files or/and libraries (npm, etc.). This is fine until a user started uploading files using the media manager in our framework which stores in a folder that is not in the .gitignore file and it can't because it contains other files, as we also add our own files in there so they're editable by the user, so now I am unsure how to manage this.
What we are looking for is a CI setup, which will upload file changes to the server, so it would search through the latest commits, and find the latest files that have been changed and then push only them files up. Of course I would like to do this with the Gitlab CI still, so any ideas examples or tutorials would be amazing.
Thanks in advance.
~ Danny
May it helps: https://github.com/banago/PHPloy
Looks this tool designed for php project, but I think it can use other web deployment.
how it works:
PHPloy stores a file called .revision on your server. This file contains the hash of the commit that you have deployed to that server. When you run phploy, it downloads that file and compares the commit reference in it with the commit you are trying to deploy to find out which files to upload. PHPloy also stores a .revision file for each submodule in your repository.

kudu custom deployment fails for asp.net core webapp

I use pretty much standard custom kudu deployment script for asp.net core web app for external git deployment.
I managed to run the script mostly successfully, through mingling with SCM_COMMAND_IDLE_TIMEOUT and .cmd files encoding. My deployment scripts look as follows:
.deployment
[config]
command = deploy.cmd
deploy.cmd
#echo off
IF "%WEBSITE_SITE_TYPE%" == "<project_name>" (
.\<project folder>\Properties\deploy.cmd
goto end
)
echo Unknown WEBSITE_SITE_TYPE: "%WEBSITE_SITE_TYPE%". Expected one of the "<project name>"
:end
exit /b
.\<project folder>\Properties\deploy.cmd - regular asp.net core deploy.cmd script, updated for proper folder structure.
The WEBSITE_SITE_TYPE is a custom environment variable I added to the web app.
All these scripts saved with utf-8 without BOM encoding.
But even though the scripts look like runs successfully, the final state of the deployment process is Failed.
When looking into the kudu deployment log last few lines of the log look as follows:
...
2018-10-14T20:50:51.0660695Z,Copying file: 'wwwroot\runtime.ec2944dd8b20ec099bf3.js',,0
2018-10-14T20:50:51.0660695Z,Copying file: 'wwwroot\styles.8ef9ef86d2a54ed3748c.css',,0
2018-10-14T20:50:51.0816988Z,Deleting app_offline.htm,,0
2018-10-14T20:50:51.0816988Z,Finished successfully.,,0
2018-10-14T20:50:51.1129431Z,\r\nD:\Program Files (x86)\SiteExtensions\Kudu\78.11002.3584\bin\Scripts\starter.cmd deploy.cmd,,2
Apparently the last line returns error code 2 and it might cause the script status to fail. But what does it mean and how do I fix it?

Azure webapp deployment fails after removing Composer SiteExtension

I had Composer Site extension installed till now on azure php webapp.
I need custom deployment that can run grunt tasks also. So I created the .deployment and deploy.sh files in project root. But that deploy.sh is not being picked up.
.deployment file contents:
[config]
command = bash deploy.sh
Looking at the deployment logs, I find this
2017-05-04T06:21:03.9301086Z,Updating submodules.,8bc3029f-d77b-4c1e-860f-a3d439d7a354,0
2017-05-04T06:21:03.9926050Z,Preparing deployment for commit id 'e2b45fb52b'.,61c286b1-5c00-4c11-ae14-54e0711d6857,0
2017-05-04T06:21:04.2632947Z,Running custom deployment command...,e71c397e-bc63-4357-abc4-acd49bc2041d,0
2017-05-04T06:21:04.3101663Z,Running deployment command...,24db1c4f-8a51-463b-8c4a-ee040bc5dfd8,0
2017-05-04T06:21:04.3101663Z,Command: D:\home\SiteExtensions\ComposerExtension\Hooks\deploy.cmd,,0
2017-05-04T06:21:04.4039215Z,The system cannot find the path specified.,,1
2017-05-04T06:21:04.4195462Z,The system cannot find the path specified.\r\nD:\Program Files (x86)\SiteExtensions\Kudu\62.60430.2807\bin\Scripts\starter.cmd D:\home\SiteExtensions\ComposerExtension\Hooks\deploy.cmd,,2
Seems like somewhere the trigger for Composer site extension still remains which is being invoked during deployment.
How can I completely remove Composer site extension and use my custom deployment script deploy.sh? Thanks in advance.
Found the problem. After uninstalling Composer SiteExtension, this environment variable is still present APPSETTING_COMMAND = D:\home\SiteExtensions\ComposerExtension\Hooks\deploy.cmd. Deleted the environment variable using kudu console and then deployment succeeded.
After removing the Composer Extension the APPSETTING_COMMAND remains as an environment variable.
Use the Kudu PowerShell command Remove-Item Env:\APPSETTING_COMMAND to remove the variable online.
Alternatively, restarting the App Service via the overview tab will refresh the environment variables, though this could be a little invasive.

Resources