gpt4 book ai didi

node.js - Azure Web 应用程序的 GitHub 部署不会停止 Node.js API 服务器的 'build' 作业(无错误)

转载 作者:行者123 更新时间:2023-12-03 02:00:37 25 4
gpt4 key购买 nike

我正在尝试将node.js api 服务器部署到Azure。我创建了一个 Azure Web 应用程序,并通过 Azure 门户创建了一个 GitHub 部署。当我推送到存储库时,Action 启动,运行构建脚本,启动 api 服务器,然后挂起而不会出现错误。关于工作流程无法完成的原因有什么想法吗?

我的app.js文件如下:

const express = require('express');
const cors = require('cors');
require('../db/mongoose');

const port = 8897
console.log("Setting port to " + port);

const userRouter = require('../routers/users');

const app = express();

app.use(cors());

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Methods");
next();
});

app.use(express.json());
app.use(userRouter);

app.listen(port, () => {
console.log('API service is up on port ' + port); //<-- this prints in Action logs
});

我的package.json文件如下:

{
"name": "api-dir",
"version": "1.0.0",
"description": "",
"main": "src/app.js",
"scripts": {
"build": "node src/app.js",
"start": "node src/app.js",
"dev": "env-cmd nodemon ./src/app.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.15"
},
"dependencies": {
"@sendgrid/mail": "^7.6.1",
"bcrypt": "^5.0.1",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"env-cmd": "^10.1.0",
"express": "^4.17.2",
"jsonwebtoken": "^9.0.0",
"mongoose": "^6.7.2",
"multer": "^1.4.4",
"sharp": "^0.30.3",
"validator": "^13.7.0"
}
}

我的 GitHub 工作流程如下:

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js app to Azure Web App - kc-api-server

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: '18.x'

- name: npm install and build
run: |
npm install
npm run build
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
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@v3
with:
name: node-app

- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'kc-api-server'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_35B0A707361B49B0865006CA24333347 }}
package: .

工作流日志(我取消工作流后)如下:

2023-05-07T18:28:05.8747790Z Requested labels: ubuntu-latest
2023-05-07T18:28:05.8748121Z Job defined at: KC/api-server/.github/workflows/main_kc-api-server.yml@refs/heads/main
2023-05-07T18:28:05.8748279Z Waiting for a runner to pick up this job...
2023-05-07T18:28:06.1295341Z Job is waiting for a hosted runner to come online.
2023-05-07T18:28:08.2484152Z Job is about to start running on the hosted runner: GitHub Actions 1 (hosted)
2023-05-07T18:28:10.4107610Z Current runner version: '2.304.0'
2023-05-07T18:28:10.4135592Z ##[group]Operating System
2023-05-07T18:28:10.4136169Z Ubuntu
2023-05-07T18:28:10.4136415Z 22.04.2
2023-05-07T18:28:10.4136812Z LTS
2023-05-07T18:28:10.4137128Z ##[endgroup]
2023-05-07T18:28:10.4137402Z ##[group]Runner Image
2023-05-07T18:28:10.4137766Z Image: ubuntu-22.04
2023-05-07T18:28:10.4138088Z Version: 20230426.1
2023-05-07T18:28:10.4138589Z Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20230426.1/images/linux/Ubuntu2204-Readme.md
2023-05-07T18:28:10.4139231Z Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20230426.1
2023-05-07T18:28:10.4139687Z ##[endgroup]
2023-05-07T18:28:10.4139987Z ##[group]Runner Image Provisioner
2023-05-07T18:28:10.4140941Z 2.0.171.1
2023-05-07T18:28:10.4141289Z ##[endgroup]
2023-05-07T18:28:10.4141930Z ##[group]GITHUB_TOKEN Permissions
2023-05-07T18:28:10.4142495Z Contents: read
2023-05-07T18:28:10.4142910Z Metadata: read
2023-05-07T18:28:10.4143447Z Packages: read
2023-05-07T18:28:10.4143870Z ##[endgroup]
2023-05-07T18:28:10.4147641Z Secret source: Actions
2023-05-07T18:28:10.4148112Z Prepare workflow directory
2023-05-07T18:28:10.4873640Z Prepare all required actions
2023-05-07T18:28:10.5054813Z Getting action download info
2023-05-07T18:28:10.7704627Z Download action repository 'actions/checkout@v3' (SHA:8e5e7e5ab8b370d6c329ec480221332ada57f0ab)
2023-05-07T18:28:11.0686996Z Download action repository 'actions/setup-node@v3' (SHA:64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c)
2023-05-07T18:28:11.2834538Z Download action repository 'actions/upload-artifact@v3' (SHA:0b7f8abb1508181956e8e162db84b466c27e18ce)
2023-05-07T18:28:11.5954871Z Complete job name: build
2023-05-07T18:28:11.6881053Z ##[group]Run actions/checkout@v3
2023-05-07T18:28:11.6881442Z with:
2023-05-07T18:28:11.6881762Z repository: KC/api-server
2023-05-07T18:28:11.6882323Z token: ***
2023-05-07T18:28:11.6882603Z ssh-strict: true
2023-05-07T18:28:11.6882908Z persist-credentials: true
2023-05-07T18:28:11.6883221Z clean: true
2023-05-07T18:28:11.6883471Z fetch-depth: 1
2023-05-07T18:28:11.6883728Z lfs: false
2023-05-07T18:28:11.6883994Z submodules: false
2023-05-07T18:28:11.6884287Z set-safe-directory: true
2023-05-07T18:28:11.6884577Z ##[endgroup]
2023-05-07T18:28:11.9099056Z Syncing repository: KC/api-server
2023-05-07T18:28:11.9101128Z ##[group]Getting Git version info
2023-05-07T18:28:11.9101704Z Working directory is '/home/runner/work/api-server/api-server'
2023-05-07T18:28:11.9102333Z [command]/usr/bin/git version
2023-05-07T18:28:11.9203415Z git version 2.40.1
2023-05-07T18:28:11.9234794Z ##[endgroup]
2023-05-07T18:28:11.9254375Z Temporarily overriding HOME='/home/runner/work/_temp/e5a13de1-3fbf-48ba-9450-b2e37dfb7e21' before making global git config changes
2023-05-07T18:28:11.9254954Z Adding repository directory to the temporary git global config as a safe directory
2023-05-07T18:28:11.9255581Z [command]/usr/bin/git config --global --add safe.directory /home/runner/work/api-server/api-server
2023-05-07T18:28:11.9298830Z Deleting the contents of '/home/runner/work/api-server/api-server'
2023-05-07T18:28:11.9304474Z ##[group]Initializing the repository
2023-05-07T18:28:11.9308057Z [command]/usr/bin/git init /home/runner/work/api-server/api-server
2023-05-07T18:28:11.9366920Z hint: Using 'master' as the name for the initial branch. This default branch name
2023-05-07T18:28:11.9368047Z hint: is subject to change. To configure the initial branch name to use in all
2023-05-07T18:28:11.9368632Z hint: of your new repositories, which will suppress this warning, call:
2023-05-07T18:28:11.9369122Z hint:
2023-05-07T18:28:11.9369641Z hint: git config --global init.defaultBranch <name>
2023-05-07T18:28:11.9369946Z hint:
2023-05-07T18:28:11.9370345Z hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
2023-05-07T18:28:11.9370861Z hint: 'development'. The just-created branch can be renamed via this command:
2023-05-07T18:28:11.9371175Z hint:
2023-05-07T18:28:11.9371776Z hint: git branch -m <name>
2023-05-07T18:28:11.9380553Z Initialized empty Git repository in /home/runner/work/api-server/api-server/.git/
2023-05-07T18:28:11.9393100Z [command]/usr/bin/git remote add origin https://github.com/KC/api-server
2023-05-07T18:28:11.9434092Z ##[endgroup]
2023-05-07T18:28:11.9444802Z ##[group]Disabling automatic garbage collection
2023-05-07T18:28:11.9445672Z [command]/usr/bin/git config --local gc.auto 0
2023-05-07T18:28:11.9490864Z ##[endgroup]
2023-05-07T18:28:11.9491361Z ##[group]Setting up auth
2023-05-07T18:28:11.9491939Z [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
2023-05-07T18:28:11.9520646Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
2023-05-07T18:28:11.9861926Z [command]/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
2023-05-07T18:28:11.9946698Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :"
2023-05-07T18:28:12.0123068Z [command]/usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
2023-05-07T18:28:12.0164122Z ##[endgroup]
2023-05-07T18:28:12.0164669Z ##[group]Fetching the repository
2023-05-07T18:28:12.0170945Z [command]/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +409db5910df0c85b48b01c289762072f7785dc8b:refs/remotes/origin/main
2023-05-07T18:28:12.2754223Z remote: Enumerating objects: 20, done.
2023-05-07T18:28:12.2760761Z remote: Counting objects: 5% (1/20)
2023-05-07T18:28:12.2767020Z remote: Counting objects: 10% (2/20)
2023-05-07T18:28:12.2773896Z remote: Counting objects: 15% (3/20)
2023-05-07T18:28:12.2778768Z remote: Counting objects: 20% (4/20)
2023-05-07T18:28:12.2779537Z remote: Counting objects: 25% (5/20)
2023-05-07T18:28:12.2782672Z remote: Counting objects: 30% (6/20)
2023-05-07T18:28:12.2783251Z remote: Counting objects: 35% (7/20)
2023-05-07T18:28:12.2784494Z remote: Counting objects: 40% (8/20)
2023-05-07T18:28:12.2785187Z remote: Counting objects: 45% (9/20)
2023-05-07T18:28:12.2785855Z remote: Counting objects: 50% (10/20)
2023-05-07T18:28:12.2786474Z remote: Counting objects: 55% (11/20)
2023-05-07T18:28:12.2787159Z remote: Counting objects: 60% (12/20)
2023-05-07T18:28:12.2787711Z remote: Counting objects: 65% (13/20)
2023-05-07T18:28:12.2788229Z remote: Counting objects: 70% (14/20)
2023-05-07T18:28:12.2796404Z remote: Counting objects: 75% (15/20)
2023-05-07T18:28:12.2796995Z remote: Counting objects: 80% (16/20)
2023-05-07T18:28:12.2797483Z remote: Counting objects: 85% (17/20)
2023-05-07T18:28:12.2797957Z remote: Counting objects: 90% (18/20)
2023-05-07T18:28:12.2798383Z remote: Counting objects: 95% (19/20)
2023-05-07T18:28:12.2798826Z remote: Counting objects: 100% (20/20)
2023-05-07T18:28:12.2834776Z remote: Counting objects: 100% (20/20), done.
2023-05-07T18:28:12.2835147Z remote: Compressing objects: 6% (1/15)
2023-05-07T18:28:12.2835471Z remote: Compressing objects: 13% (2/15)
2023-05-07T18:28:12.2835799Z remote: Compressing objects: 20% (3/15)
2023-05-07T18:28:12.2836126Z remote: Compressing objects: 26% (4/15)
2023-05-07T18:28:12.2836439Z remote: Compressing objects: 33% (5/15)
2023-05-07T18:28:12.2836776Z remote: Compressing objects: 40% (6/15)
2023-05-07T18:28:12.2837103Z remote: Compressing objects: 46% (7/15)
2023-05-07T18:28:12.2837411Z remote: Compressing objects: 53% (8/15)
2023-05-07T18:28:12.2837735Z remote: Compressing objects: 60% (9/15)
2023-05-07T18:28:12.2838327Z remote: Compressing objects: 66% (10/15)
2023-05-07T18:28:12.2838659Z remote: Compressing objects: 73% (11/15)
2023-05-07T18:28:12.2838974Z remote: Compressing objects: 80% (12/15)
2023-05-07T18:28:12.2839301Z remote: Compressing objects: 86% (13/15)
2023-05-07T18:28:12.2839624Z remote: Compressing objects: 93% (14/15)
2023-05-07T18:28:12.2839933Z remote: Compressing objects: 100% (15/15)
2023-05-07T18:28:12.2840276Z remote: Compressing objects: 100% (15/15), done.
2023-05-07T18:28:12.2840937Z remote: Total 20 (delta 0), reused 13 (delta 0), pack-reused 0
2023-05-07T18:28:12.2872990Z From https://github.com/KC/api-server
2023-05-07T18:28:12.2873563Z * [new ref] 409db5910df0c85b48b01c289762072f7785dc8b -> origin/main
2023-05-07T18:28:12.3041076Z ##[endgroup]
2023-05-07T18:28:12.3041610Z ##[group]Determining the checkout info
2023-05-07T18:28:12.3044729Z ##[endgroup]
2023-05-07T18:28:12.3045196Z ##[group]Checking out the ref
2023-05-07T18:28:12.3049675Z [command]/usr/bin/git checkout --progress --force -B main refs/remotes/origin/main
2023-05-07T18:28:12.3104824Z Switched to a new branch 'main'
2023-05-07T18:28:12.3110744Z branch 'main' set up to track 'origin/main'.
2023-05-07T18:28:12.3115007Z ##[endgroup]
2023-05-07T18:28:12.3157344Z [command]/usr/bin/git log -1 --format='%H'
2023-05-07T18:28:12.3186581Z '409db5910df0c85b48b01c289762072f7785dc8b'
2023-05-07T18:28:12.3533586Z ##[group]Run actions/setup-node@v3
2023-05-07T18:28:12.3533891Z with:
2023-05-07T18:28:12.3534116Z node-version: 18.x
2023-05-07T18:28:12.3534372Z always-auth: false
2023-05-07T18:28:12.3534632Z check-latest: false
2023-05-07T18:28:12.3535072Z token: ***
2023-05-07T18:28:12.3535289Z ##[endgroup]
2023-05-07T18:28:12.5684641Z Found in cache @ /opt/hostedtoolcache/node/18.16.0/x64
2023-05-07T18:28:12.5685236Z ##[group]Environment details
2023-05-07T18:28:18.2281526Z node: v18.16.0
2023-05-07T18:28:18.2282323Z npm: 9.5.1
2023-05-07T18:28:18.2282705Z yarn: 1.22.19
2023-05-07T18:28:18.2283659Z ##[endgroup]
2023-05-07T18:28:18.2454901Z ##[group]Run npm install
2023-05-07T18:28:18.2455206Z [36;1mnpm install[0m
2023-05-07T18:28:18.2455428Z [36;1mnpm run build[0m
2023-05-07T18:28:18.2513432Z shell: /usr/bin/bash -e {0}
2023-05-07T18:28:18.2513683Z ##[endgroup]
2023-05-07T18:28:28.0153756Z npm WARN deprecated <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="18756d746c7d6a5829362c362c" rel="noreferrer noopener nofollow">[email protected]</a>: Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.
2023-05-07T18:28:29.8360526Z
2023-05-07T18:28:29.8361601Z added 323 packages, and audited 324 packages in 11s
2023-05-07T18:28:29.8362063Z
2023-05-07T18:28:29.8362472Z 25 packages are looking for funding
2023-05-07T18:28:29.8362961Z run `npm fund` for details
2023-05-07T18:28:29.8389572Z
2023-05-07T18:28:29.8399556Z 3 high severity vulnerabilities
2023-05-07T18:28:29.8400055Z
2023-05-07T18:28:29.8400606Z Some issues need review, and may require choosing
2023-05-07T18:28:29.8401076Z a different dependency.
2023-05-07T18:28:29.8401372Z
2023-05-07T18:28:29.8401798Z Run `npm audit` for details.
2023-05-07T18:28:30.2467086Z
2023-05-07T18:28:30.2468430Z > <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6f7e67236a677c4e3f203e203e" rel="noreferrer noopener nofollow">[email protected]</a> build
2023-05-07T18:28:30.2469058Z > node src/app.js
2023-05-07T18:28:30.2469500Z
2023-05-07T18:28:30.5864539Z Connecting to ***cluster0.hcwrc.mongodb.net/KC?authSource=test&replicaSet=atlas-xaxq3n-shard-0&readPreference=primary&ssl=true
2023-05-07T18:28:30.6003857Z Setting port to 8897
2023-05-07T18:28:30.7253249Z (node:1831) [MONGOOSE] DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7. Use `mongoose.set('strictQuery', false);` if you want to prepare for this change. Or use `mongoose.set('strictQuery', true);` to suppress this warning.
2023-05-07T18:28:30.7254519Z **API service is up on port 8897**
2023-05-07T18:28:30.7255759Z (Use `node --trace-deprecation ...` to show where the warning was created)
2023-05-07T18:50:41.1827979Z ##[error]The operation was canceled.
2023-05-07T18:50:41.1883321Z Post job cleanup.
2023-05-07T18:50:41.3642123Z [command]/usr/bin/git version
2023-05-07T18:50:41.3642407Z git version 2.40.1
2023-05-07T18:50:41.3645275Z Temporarily overriding HOME='/home/runner/work/_temp/d2e11fe2-4452-4f9f-8d29-1c86bb3938ff' before making global git config changes
2023-05-07T18:50:41.3645854Z Adding repository directory to the temporary git global config as a safe directory
2023-05-07T18:50:41.3646677Z [command]/usr/bin/git config --global --add safe.directory /home/runner/work/api-server/api-server
2023-05-07T18:50:41.3647731Z [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
2023-05-07T18:50:41.3649130Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
2023-05-07T18:50:41.3650436Z [command]/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
2023-05-07T18:50:41.3651017Z http.https://github.com/.extraheader
2023-05-07T18:50:41.3652180Z [command]/usr/bin/git config --local --unset-all http.https://github.com/.extraheader
2023-05-07T18:50:41.3653835Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :"
2023-05-07T18:50:41.3784140Z Cleaning up orphan processes
2023-05-07T18:50:41.4016340Z Terminate orphan process: pid (1819) (npm run build)
2023-05-07T18:50:41.4068420Z Terminate orphan process: pid (1830) (sh)
2023-05-07T18:50:41.4088311Z Terminate orphan process: pid (1831) (node)

最佳答案

问题已经解决了。我在 package.json 中有一个“构建”脚本,它与“启动”脚本执行相同的操作,即

"build": "node src/app.js"

GitHub 工作流程将运行构建脚本,从而启动服务器,当然,服务器不会终止。

从 package.json 中删除“构建”脚本可以让工作流程完成。

关于node.js - Azure Web 应用程序的 GitHub 部署不会停止 Node.js API 服务器的 'build' 作业(无错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76195851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com