Azure Functions deployment failing when using scm-do-build-during-deployment: true - node.js

I'm trying to deploy an Azure Functions Linux app using Github Actions. I've used the Deployment Center in the Azure Portal to connect my Github to enable CICD. Now that goes fine, but I want to use Playwright in my Azure Function, so I need to enable scm-do-build-during-deployment: true. I've added this setting to my workflow yaml, but then the deployment doesn't work anymore. I also added some other settings, which I came across when I searched the interwebs. Now this is the yaml I have:
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Node.js project to Azure Function App - app-name
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: "." # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: "16.x" # set this to the node version to use (supports 8.x, 10.x, 12.x)
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: "Checkout GitHub Action"
uses: actions/checkout#v2
- name: Setup Node ${{ env.NODE_VERSION }} Environment
uses: actions/setup-node#v1
with:
node-version: ${{ env.NODE_VERSION }}
- name: "Resolve Project Dependencies Using Npm"
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm install
npm run build --if-present
npm run test --if-present
popd
- name: "Run Azure Functions Action"
uses: Azure/functions-action#v1
id: fa
with:
app-name: "app-name"
slot-name: "Production"
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_A5413AC6097F4B21B4A709C270747826 }}
scm-do-build-during-deployment: true
enable-oryx-build: true
respect-funcignore: true
I also added the setting to my application settings in Azure, but to no avail. Furthermore, I added this setting: WEBSITE_RUN_FROM_PACKAGE=0 to the app settings.
Is there anything else I should try?

In the YAML the uses tag is not aligned with the name and the other tags
- name: "Run Azure Functions Action"
uses: Azure/functions-action#v1
id: fa
Add PLAYWRIGHT_BROWSERS_PATH in app settings with its value set to zero.
Rest remains the same and I was able to deploy the function.

Related

Change path of GitHub build action

I have a GitHub Action that is using the default Microsoft template for building an ASP.Net Core app to an Azure App Service.
At the top of the action, you can declare some environment variables. I have these set as follows:
name: Build and deploy ASP.Net Core app to an Azure Web App
env:
AZURE_WEBAPP_NAME: (redacted) # set this to the name of your Azure Web App
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.0' # set this to the .NET Core version to use
My issue is that the root folder doesn't contain the .csproj or .sln files. So this line is not correct: AZURE_WEBAPP_PACKAGE_PATH: '.'
I have tried changing it to AZURE_WEBAPP_PACKAGE_PATH: './FolderName/FolderName' (and many other variations), which is where the .csproj file is located, however the build still fails due to the following error:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
Edit to include entire YAML file:
name: Build and deploy ASP.Net Core app to an Azure Web App
env:
AZURE_WEBAPP_NAME: (redacted) # set this to the name of your Azure Web App
AZURE_WEBAPP_PACKAGE_PATH: '../../FolderName/FolderName' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.0' # set this to the .NET Core version to use
on:
push:
branches:
- "master"
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v3
- name: Set up .NET Core
uses: actions/setup-dotnet#v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up dependency caching for faster builds
uses: actions/cache#v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
permissions:
contents: none
runs-on: windows-latest
needs: build
environment:
name: 'Development'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v3
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
I ran into the same issue and found the solution on this SO answer, despite the fact that it wasn't marked as the correct.
Taking the above into account, your yaml file should look something like this:
name: Build and deploy ASP.Net Core app to an Azure Web App
defaults:
run:
working-directory: ./FolderName/FolderName
env:
AZURE_WEBAPP_NAME: (redacted) # set this to the name of your Azure Web App
AZURE_WEBAPP_PACKAGE_PATH: '../../FolderName/FolderName' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.0' # set this to the .NET Core version to use

GitHub actions deploys wrong version of Newtonsoft.Json nuget package to Azure

I have a GitHub action doing .net solution build, test and deploy to Azure:
name: Build and deploy ASP.Net Core app to Azure Web App - project-test-api
on:
push:
branches:
- main
workflow_dispatch:
env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: AutoModality/action-clean#v1
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: Manually restore
working-directory: SolutionDir
run: dotnet restore --force
- name: Build with dotnet
working-directory: SolutionDir
run: dotnet build --configuration Release --no-restore
- name: Test
working-directory: SolutionDir
run: dotnet test --no-restore --no-build --configuration Release
- name: dotnet publish
working-directory: SolutionDir
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'quickplanner-test-api'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_SECRET }}
package: .
Recently I added a test project to the solution. From what I can see one of the packages used in the test project uses Newtonsoft.Json v9.0 when the rest of the solution uses v13.0. The solution can be built locally, tested and everything is ok. The GitHub action also finishes successfully building the solution, runs tests and deploys it to Azure. The problem occurs on Azure - somewhere along the way GitHub action uses an older version of Newtonsoft.Json. All projects expect newer ones, so the whole website breaks because of this. I'm not sure how to fix this - I've tried adding manually correct version of Newtonsoft.Json to the test project, to all projects, clearing caches in GitHub actions but without luck. What works is just removing test project from the solution, but obviously I want tests to be working. Does anyone has idea why this breaks and how to fix it?
I managed to fix this problem by adding this code to my Tests project csproj file:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
I'm not entirely sure what was the root cause behind this problem

Environment Variables are undefined in Azure Service App

I'm breaking my head over this - I've had the same environment working with the variables 100% (and also on the local env ofcourse)- but I've created another App Service on Azure with the same workflow and all of the env variables defined under the App Settings (Configurations tab) are undefined when running the job in workflow. I'm using the default YML file that Azure created when you deploy it using the Deployment Center. The start command is very simple:
"build": "node app.js",
And this is the YML file:
name: Build and deploy Node.js app to Azure Web App - xxxxxxx
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Node.js version
uses: actions/setup-node#v1
with:
node-version: '14.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: node-app
path: .
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: node-app
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'xxxxxxxxx'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_74C0CC726E3C4567B0FXXXXXXXXXXC }}
package: .
No matter what I do, the process.env.X variables are all undefined, and if you list all variables using SSH on the same instance, I see the variables there, which drives me even more crazy!
Any idea?
As suggested by #Shinoy Babu ,We can try to add the environment variable in pipeline while deploying which will reflect in our App service in Azure after deploying.
Also if want to configure through Azure portal you can refer this
For more information please refer the below links:
SO THREAD| How to use environment variables in React app hosted in Azure

sync python code on GitHub repo and deploy on Azure function

I would like to sync the code (in an azure functions folder). I followed the doc to create a github actions cd. However in azure portal in my functions sections functions, my folder does not appear. Anyone have any idea what the problem is. I have no errors in my workflow.
I have an error when i'm trying to Redeploy/sync my code: it's not found...
My Worflow File
Just post how I deploy a function from GitHub repo.
My file structure:
https://github.com/Paprika-a11y/pythonfunc.git
Navigate to the Deployment Center page, configure the settings:
After saving the settings, check the deployment process on GitHub Action:
If your function project is correct locally, then it should appear on portal:
If you need the workflow, here is the file generated automatically:
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Python project to Azure Function App - pyfunctemp
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.7' # set this to the python version to use (supports 3.6, 3.7, 3.8)
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout#master
- name: Setup Python ${{ env.PYTHON_VERSION }} Environment
uses: actions/setup-python#v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: 'Resolve Project Dependencies Using Pip'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
python -m pip install --upgrade pip
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd
- name: 'Run Azure Functions Action'
uses: Azure/functions-action#v1
id: fa
with:
app-name: 'pyfunctemp'
slot-name: 'production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AzureAppService_PublishProfile_xxxxxx }}

Using webapps-deploy to deploy into a specifc folder (not just into wwwroot)

Is it possible to use the webapps-deploy action to deploy into a specific path of the web app (and not just into wwroot)? For example deploying into a IIS virtual directory under wwwroot/app.
Current yaml GitHub action configuration, can't find a property here for setting a requested path on the web server.
- name: "Run Azure webapp deploy action using publish profile credentials"
uses: azure/webapps-deploy#v2
with:
app-name: MyApp
publish-profile: ${{ secrets.SECRET_PROFILE }}
package: build
Image showing the Virtual Application (wwwroot/app) I'd like to deploy into
With many times testing, I found it's not possible using Git Action. But you can consider using Visual Studio, importing publish profile.
First, set the virtual path in portal.
Downloads the publish profile. You will use the content of publish profile.
Modify the profile. Change msdeploySite's value from Your-Site to Your-Site\folder\subfolder, such as msdeploySite="dorissub\app". Change destinationAppUrl's value from http://xxx.azurewebsites.net to http://xxx.azurewebsites.net/app
Publish from VS.
Check the sub folder. it works.
Here is how I do using Git Action.
Add secret. Go to your GitHub repository settings and add a secret with the content of publish profile as the value, name it as AZURE_WEBAPP_PUBLISH_PROFILE.
Run workflow with this yaml file:
name: .NET Core dorisxxx
on: [push]
env:
AZURE_WEBAPP_NAME: dorisxxx # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.1.x' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout#master
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release -o '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy#v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
But the project still published to wwwroot...
Maybe you should choose another way to deploy.

Resources