Azure DevOps First Time Web App Deployment Always Gives Error - azure

I am facing this odd situation. I have the following setup.
React JS app created using create-react-app
Code on GitHub
Azure Web App - Create from the Azure Portal.
Azure DevOps + Pipelines + YAML
I have been doing a bunch of deployments this week and I noticed this situation. Every 1st deployment, always ends up with the following situation inside the wwwroot folder.
But, every subsequent deployment, works just fine.
To reproduce
Create a new app with create-react-app
Put it on GitHub
Link GitHub repository with Azure DevOps Pipelines
Target the Pipeline to deploy to a Azure Web App, which has been created brand new.
The initial deployment, will always fail, with the above image. And, please, remember, Subsequent deployments dont fail.
So, the question is, is there something I can do to prevent this?
I am planning to automate resource creation on Azure, along with automating deployment.
Update 1
as per the comment, including my YAML here. I use this in all of my react JS deployments, which show the same issue as above.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: CopyFiles#2
inputs:
Contents: 'build/**' # Pull the build directory (React)
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory) # dist or build files
ArtifactName: 'www' # output artifact named www
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/build/'
includeRootFolder: false
- task: AzureWebApp#1
inputs:
azureSubscription: 'ReactJSRecipeAppConnection'
appName: 'ReactJSRecipeAppSep232020'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'

FAILED TO INITIALIZE RUN FROM PACKAGE usually means the zip file is corrupted or not deflateable. Please check whether the WEBSITE_RUN_FROM_PACKAGE flag under App Service -> Application settings was set.
In addition, try to use task Azure App Service deploy v4, instead of task Azure Web App v1.

Taking off from the discussion about with #Cece Dong, here is what eventually worked for me.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: CopyFiles#2
inputs:
Contents: 'build/**' # Pull the build directory (React)
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory) # dist or build files
ArtifactName: 'www' # output artifact named www
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/build/'
includeRootFolder: false
- task: AzureRMWebAppDeployment#4
inputs:
appType: webApp
azureSubscription: 'RandomStuffReactJSConnection'
WebAppName: 'randomstuffreactjsappsept24'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
The above, I can confirm, no longer requires a second trigger for a proper deployment.
specifically, the usage of 'AzureRMWebAppDeployment#4' is what solved the original issue.

Related

Azure Pipeline refuses to deploy from zip instead calling from blob which doesn't exist

Very much still new to YAML, but i've showed this to a colleague who's equally confused as me. I've built a CI/CD pipeline, and the CI end seems to work just fine. The pipeline claims its deploying a function app successfully, but when I go to check, there's nothing in the function app, and the output code from the pipeline seems to be calling from a blob storage folder that doesn't exist. We can't work out how to change the behaviour of it.
Is this something anyone has seen before?
This is the YAML:
# Python Function App to Linux on Azure
# Build a Python function app and deploy it to Azure as a Linux function app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/python
trigger:
- master
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'ab1c86d0-0d0c-4029-913b-e5483df967b2'
# Function app name
functionAppName: 'categoriserfunctionapp'
# Agent VM image name
vmImageName: 'ubuntu-latest'
# Working Directory
workingDirectory: ''
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion#0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6 # Functions V2 supports Python 3.6 as of today
architecture: 'x64'
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveType: zip
archiveFile: "$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip"
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip'
artifactName: 'drop'
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'test'
pool:
vmImage: 'windows-latest'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
artifactName: 'drop'
targetPath: '$(Pipeline.Workspace)/drop/'
- task: AzureFunctionApp#1
inputs:
azureSubscription: 'Visual Studio Enterprise Subscription – MPN (f1f3e234-557b-4acd-b353-2ff89c547e49)'
appType: 'functionAppLinux'
appName: 'categoriserfunctionapp'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
runtimeStack: 'PYTHON|3.9'
And this is the output from the CD end:
2022-09-27T15:59:26.6330661Z ##[section]Starting: AzureFunctionApp
2022-09-27T15:59:26.6442433Z ==============================================================================
2022-09-27T15:59:26.6442718Z Task : Azure Functions
2022-09-27T15:59:26.6443009Z Description : Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications
2022-09-27T15:59:26.6443282Z Version : 1.208.2
2022-09-27T15:59:26.6443454Z Author : Microsoft Corporation
2022-09-27T15:59:26.6443686Z Help : https://aka.ms/azurefunctiontroubleshooting
2022-09-27T15:59:26.6443957Z ==============================================================================
2022-09-27T15:59:27.4092341Z Got service connection details for Azure App Service:'categoriserfunctionapp'
2022-09-27T15:59:30.9793711Z Trying to update App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"https://categoriserfunc9c44.blob.core.windows.net/azure-pipelines-deploy/package_1664294369833.zip?***"}
2022-09-27T15:59:32.4412565Z Updated App Service Application settings.
2022-09-27T15:59:32.4414182Z Updated WEBSITE_RUN_FROM_PACKAGE Application setting to https://categoriserfunc9c44.blob.core.windows.net/azure-pipelines-deploy/package_1664294369833.zip?***
2022-09-27T15:59:37.4527980Z Syncing triggers for function app
2022-09-27T15:59:39.3782043Z Sync triggers for function app completed successfully
2022-09-27T15:59:41.0691225Z Successfully added release annotation to the Application Insight : categoriserfunctionapp
2022-09-27T15:59:41.3968439Z App Service Application URL: https://categoriserfunctionapp.azurewebsites.net
2022-09-27T15:59:41.4063927Z ##[section]Finishing: AzureFunctionApp
We tried changing the hardcode of WEBSITE_RUN_FROM_PACKAGE but it seems to have changed itself back since I refreshed the function app.
Does anyone have any ideas for fixing this?
I can successfully deploy to azure function app with a slight modification based on the YAML you provided.
trigger:
- none
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: '<ARM Service Connection Name>'
resourceGroupName: '<Resource Group Name of storage>'
# Function app name
functionAppName: '<Your Function App Name>'
# Agent VM image name
vmImageName: 'ubuntu-latest'
# Working Directory
workingDirectory: ''
storage_str: 'DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx;EndpointSuffix=core.windows.net'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: UsePythonVersion#0
displayName: 'Use Python 3.9'
inputs:
versionSpec: 3.9 # Functions V2 supports Python 3.6 as of today
architecture: 'x64'
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveType: zip
archiveFile: "$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip"
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip'
artifactName: 'drop'
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'test'
pool:
vmImage: 'windows-latest'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
artifactName: 'drop'
targetPath: '$(Pipeline.Workspace)/drop/'
- task: AzureAppServiceSettings#1
inputs:
azureSubscription: '$(azureSubscription)'
appName: '$(functionAppName)'
resourceGroupName: '$(resourceGroupName)'
appSettings: |
[
{
"name": "AzureWebJobsStorage",
"value": "$(storage_str)",
"slotSetting": false
}
]
- task: AzureFunctionApp#1
inputs:
azureSubscription: '$(azureSubscription)'
appType: 'functionAppLinux'
appName: '$(functionAppName)'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
runtimeStack: 'PYTHON|3.9'
From your description, the blob file doesn't exist? If so, the function will not execute successfully.
You must make sure there is a file to use for 'run from package'.
There are several problems with your YAML which may cause the issue:
Variables in YAML are not fully used. The service connection and variable definitions in the Deployment stage are different (I have changed to the same).
The python version used is different from the azure function app version (I have changed to the same).
By the way, In order to rule out the problem that the storage is controlled by some policy or program, you can create a new storage to test and provide the connection string in the above YAML file (the location of the package your function app is based on is determined by AzureWebJobsStorage, the above YAML can be Change settings before actual deployment.).
And additional, if you can deploy the function app with no problem on local(such as VS Code), then you can use something like below to deploy the function app.
trigger:
- none
variables:
- name: System.debug
value: true
pool:
VMAS #agent based on your local machine.
steps:
- task: AzurePowerShell#5
inputs:
azureSubscription: 'xxx'
ScriptType: 'InlineScript'
Inline: 'func azure functionapp publish xxx --build remote'
azurePowerShellVersion: 'LatestVersion'
My repo structure likes below:

Vue.js does not start in Azure App Service

I currently have a pipeline in Azure Dev Ops configured to build, copy, archive, and then deploy a Vue.js app to an Azure App Service running on Linux. When I SSH into the server I do see the outputs of the build appearing successfully in the wwwroot folder but when I pull up the URL of the App Service I'm just shown the default landing page. Below are screenshots of my wwwroot folder, the page I'm seeing when I pull up the URL and a copy of the yml file for the pipeline. Is there something else missing from the yml file that I need to add to tell the app service to start the vue.js app by chance, I'm fairly new to this stuff.
# Build a Node.js project that uses Vue.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
workingDirectory: $(Build.SourcesDirectory)/client-app
- task: CopyFiles#2
inputs:
Contents: '$(Build.SourcesDirectory)/client-app/dist/**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
verbose: true
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Azure subscription 1 (f719f76c-c23e-4160-aa93-914eb7851fdb)'
appType: 'webAppLinux'
WebAppName: 'trashbot'
packageForLinux: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
You need to add startup command on portal.
pm2 serve /home/site/wwwroot --no-daemon --spa
Related Posts:
1. Application is not loading when deployed via azure app service
2. Default Documents (custom 404) on Azure AppService Linux website

How to deploy Strapi to Azure?

I installed Strapi with Mongodb locally.
I need to deploy it to Azure.
Strapi is commitet on Azure Git-repository.
I have created a App Service with Ubuntu on Azure.
How to deploy my Strapi to this?
Can I use pipeline?
I can't find any good documentaion/example how to do it. Help!
*************
UPDATE
*************
My results after trying the method described here:
https://github.com/youkou2/Strapi-On-Azure-WebApp
Build pipeline works without any error
Deploy pipeline works without any error
Deployed web site is empty.
I can describe what I have done, may be somebody can help me to find what I did wrong.
a) Build pipeline is
pool:
name: Azure Pipelines
steps:
- bash: |
yarn install
set NODE_ENV=PRODUCTION
yarn build
rm -rf .cache
rm -rf .git
displayName: Build
- task: ArchiveFiles#2
displayName: 'Archive ./'
inputs:
rootFolderOrFile: ./
includeRootFolder: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
*** It works ok, no errors ***
b) Deploy pipeline
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy Azure App Service'
inputs:
azureSubscription: '$(Parameters.ConnectedServiceName)'
appType: '$(Parameters.WebAppKind)'
WebAppName: '$(Parameters.WebAppName)'
*** It works ok, no errors ***
c) Project is deployed to https://oskogencms.azurewebsites.net/
*** It is empty, why? ***
enter code here
Here is additional info around the deployment:
You can try to use zip deploy, The steps is npm install, create zip package, publish zip package, release zip package. For more information please have a look of this the offcial doc:
https://learn.microsoft.com/en-us/azure/app-service/deploy-zip
By the way, it seems deploy strapi to azure web app is not the recommended method.
https://strapi.io/documentation/3.0.0-beta.x/deployment/azure.html#azure
This is an article on deploying strapi to azure web app, the introduction is more detailed, also using zip deployment:(The only different between you is it is deployed to windows os. If you can use ftp, ftp deploy is also a choice.)
https://github.com/youkou2/Strapi-On-Azure-WebApp
Please check #ZiedBeta's sample in the following link:
https://github.com/strapi/strapi/issues/3580
Build pipeline:
pool:
name: Azure Pipelines
steps:
- bash: |
yarn install
yarn build
rm -rf .cache
rm -rf .git
displayName: build
- task: ArchiveFiles#2
displayName: 'Archive Strapi'
inputs:
rootFolderOrFile: ./
includeRootFolder: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
Development pipeline:
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy Azure App Service'
inputs:
azureSubscription: '$(Parameters.ConnectedServiceName)'
appType: '$(Parameters.WebAppKind)'
WebAppName: '$(Parameters.WebAppName)'
enableCustomDeployment: true
DeploymentType: zipDeploy

Azure DevOps Doesn't Publish Web App from ZIP Deploy, Runs It as Read-Only ZIP Package Instead

We have an Azure DevOps Pipeline that runs our application as ZIP package https://learn.microsoft.com/en-us/azure/app-service/deploy-run-package
as opposed to ZIP Deploy. So we are not able to SFTP into our Web App and change something. Why does the Pipeline runs our application as ZIP package and how can we change this?
This is the Pipeline:
trigger: none
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: 'Solution1.sln'
- task: VSBuild#1
inputs:
solution: '$(agent.builddirectory)\s\Folder\Project.csproj'
msbuildArgs: '/p:OutputPath="$(build.binariesDirectory)\Folder\bin" /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactStagingDirectory)\ProjectTempFolder"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
inputs:
SourceFolder: '$(build.artifactStagingDirectory)\ProjectTempFolder'
Contents: |
**
TargetFolder: '$(build.ArtifactStagingDirectory)\ProjectArtifacts'
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(build.ArtifactStagingDirectory)\ProjectArtifacts'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(build.ArtifactStagingDirectory)\Project.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(build.ArtifactStagingDirectory)\Project.zip'
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Subscription1'
appType: 'webApp'
WebAppName: 'CoolWebApp777'
packageForLinux: '$(build.ArtifactStagingDirectory)\Project.zip'
Why does the Pipeline runs our application as ZIP package and how can we change this?
It seems you want to disable to run your Web App from a package, AFAIK, the default version in the release pipeline is now set to Version 4. This version has the "Select deployment method" checkbox disabled, which in turn, allows the "Run as Package" feature by default as well. To change this value, go into the "Deploy Azure App Service" task for each environment and expand Additional Deployment Options. You’ll probably want to change it most often to Web Deploy:
Besides, you can turn that off by deleting the WEBSITE_RUN_FROM_ZIP or WEBSITE_RUN_FROM_PACKAGE application setting in the portal.
Note this will clear your web app until the next time you publish.
Hope this helps.

How to link build result of "plain React"/node app with release pipeline

To try to make it short, I have a React application that's build on Azure DevOps Build Pipeline like so
trigger:
- Release
queue:
name: Hosted
demands: npm
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm ci
npm run build
displayName: 'Do npm ci and build'
This does what the build would do locally too. Locally the results of build go to build directory (unzipped).
Now when I try to create release pipeline there isn't an artifact to be found using Azure Deploy Web Service task.
If I try to add PublishPipelineArtifact#0 to the build pipeline to create a publication, the YAML editor just tells string does not match pattern... and doesn't let save the definition.
I suppose I should zip the contents of the generated build directory, but what would be the right way? Also, Is using the Azure App Service Deploy task the right way to deploy Azure WebApp? It works for ASP.NET Core apps so it finds the code drop artefact (zipped) and deploys it.
<edit: Adding
- task: PublishPipelineArtifact#0
inputs:
artifactName: 'drop'
targetPath: '$(Build.ArtifactStagingDirectory)/build'
Can actually be saved and the build run. Though it errors with
2019-01-25T22:42:27.6896518Z ##[section]Starting:
PublishPipelineArtifact 2019-01-25T22:42:27.6898909Z
============================================================================== 2019-01-25T22:42:27.6898962Z Task : Publish Pipeline Artifact
2019-01-25T22:42:27.6899006Z Description : Publish Pipeline Artifact
2019-01-25T22:42:27.6899034Z Version : 0.139.0
2019-01-25T22:42:27.6899062Z Author : Microsoft Corporation
2019-01-25T22:42:27.6899090Z Help : Publish a local directory
or file as a named artifact for the current pipeline.
2019-01-25T22:42:27.6899137Z
============================================================================== 2019-01-25T22:42:28.0499917Z ##[error]Path not exist: D:\a\1\a\build
2019-01-25T22:42:28.0708878Z ##[section]Finishing:
PublishPipelineArtifact
< edit 2: It appears removing the /build does the trick. Feels a tad odd since this is what's produced locally. It doesn't produce a zip file which is expected by the release job, namely Azure App Service Deploy.
Have to examine this problem later today (two o'clock at night here).
There was another problem: The script ran only npm ci and didn't run the building part. Separating it to two different steps made the difference. It appears PublishPipelineArtifact#0 in this case isn't an ideal option if I'd like to have the results as zipped to the staging area.
A currently working solution seem to be
resources:
- repo: self
trigger:
- Release
queue:
name: Hosted
demands: npm
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm ci
displayName: 'npm ci'
- script: |
npm run build
displayName: 'npm run build'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/build'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/artifact.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
Maybe this can be simplified, but works for now and is flexible, it feels.

Resources