我有一个简单的 Node.js 服务器,我正在使用 GitHub Actions 中的以下工作流程将其部署到 Azure 应用服务。它包括工件压缩和解压缩步骤这个答案 https://stackoverflow.com/a/69402502/197591,以提高部署性能。
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: .
这很好用。但是,我必须将代码移动到我的存储库的子文件夹“服务器”中,这意味着我必须根据以下问题的答案更改工作流程这个问题 https://stackoverflow.com/q/57806624/197591。我必须添加working-directory
的选项defaults
.
另外,根据here https://github.com/actions/upload-artifact/issues/232#issuecomment-1065422577,上传步骤不使用working-directory
,所以我必须明确指定这一步的路径。
我的工作流程现在如下所示:
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: .
可能不相关,但我应该提到我必须设置PROJECT=Server
在应用程序服务应用程序设置中,按照here https://github.com/projectkudu/kudu/wiki/Customizing-deployments#using-app-settings-instead-of-a-deployment-file.
在“部署到 Azure Web App”步骤中,发生错误。这些是日志:
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
问题似乎是From directory doesn't exist
(我在 Kudu 代码中找到了这个here https://github.com/projectkudu/KuduSync/blob/master/lib/FileUtils.ts#L17)。但我不明白为什么会发生这种情况。
非常感谢任何帮助。