I have a simple Node.js server that I'm deploying to Azure App Service using the following workflow in GitHub Actions. It includes artifact zip and unzip steps as per this answer, to improve deployment performance.
name: Build and deploy Node.js app to Azure Web App - myapp
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: '16.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Zip artifact for deployment
run: zip release.zip ./* -r
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: node-app
path: release.zip
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'nodetest'
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: Unzip artifact for deployment
run: unzip release.zip
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'myapp'
slot-name: 'nodetest'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_9E52572382474FD2A31555D64BEBCB1D }}
package: .
This works fine. However, I must move the code into subfolder 'Server' of my repo, which means I must change the workflow according to the answers to this questions. I must add the working-directory
option to the defaults
.
Also, as per here, the upload step doesn't use working-directory
, so I have to explicitly specify the path for this step.
My workflow now looks like this:
name: Build and deploy Node.js app to Azure Web App - myapp
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
defaults:
run:
working-directory: Server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js version
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Zip artifact for deployment
run: zip release.zip ./* -r
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: node-app
path: Server/release.zip
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'nodetest'
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: Unzip artifact for deployment
run: unzip release.zip
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'myapp'
slot-name: 'nodetest'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_9E52572382474FD2A31555D64BEBCB1D }}
package: .
Probably not relevant, but I should mention that I have to set PROJECT=Server
in the App Service application settings as per here.
During the 'Deploy to Azure Web App' step, an error occurs. These are the logs:
Run azure/webapps-deploy@v2
with:
app-name: myapp
slot-name: test
publish-profile: ***
package: .
Package deployment using ZIP Deploy initiated.
Updating submodules.
Preparing deployment for commit id '3fa8fc89-4'.
Generating deployment script.
Using the following command to generate deployment script: 'azure site deploymentscript -y --no-dot-deployment -r "/tmp/zipdeploy/extracted" -o "/home/site/deployments/tools" --basic --sitePath "/tmp/zipdeploy/extracted/Server"'.
The site directory path: ./Server
Generating deployment script for Web Site
Generated deployment script files
Running deployment command...
Command: "/home/site/deployments/tools/deploy.sh"
Handling Basic Web Site deployment.
Error: From directory doesn't exist
An error has occurred during web site deployment.
Kudu Sync failed
\n/opt/Kudu/Scripts/starter.sh "/home/site/deployments/tools/deploy.sh"
Deployment Failed.
Error: Failed to deploy web package to App Service.
Error: Deployment Failed with Error: Package deployment using ZIP Deploy failed. Refer logs for more details.
App Service Application URL: http://myapp-test.azurewebsites.net
The problem appears to be From directory doesn't exist
(I found this in the Kudu code here). But I can't see why this is happening.
Any help greatly appreciated.
Server
in front of the path foractions/upload-artifact@v2
, so note to anyone else who didn't knowactions/upload-artifact@v2
doesn't account forworking-directory
as its not a run command – Spruill