从 Github Actions 部署后应用程序立即崩溃
Posted
技术标签:
【中文标题】从 Github Actions 部署后应用程序立即崩溃【英文标题】:App crashing right away after deploy from Github Actions 【发布时间】:2021-12-07 16:09:01 【问题描述】:嗯,我已经将我的 TypeScript 项目推送到了 github,它有这些脚本:
"scripts":
"test": "jest",
"test:cov": "jest --coverage -i",
"test:unit": "jest unit --coverage -i",
"test:int": "jest int --coverage -i",
"build": "rimraf ./dist && tsc",
"start": "node ./dist/index.js",
"dev": "ts-node-dev --respawn --transpile-only --inspect -- ./src/index.ts"
之后,我创建了一个 github 操作工作流,让它运行我的测试,如果它们都通过了,它就会部署到 heroku,但是当部署完成时,heroku 应用程序会立即崩溃。
这是工作流程:
main.yml
:
name: Main workflow
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.18.1]
steps:
- uses: actions/checkout@v2
- name: Use Node.js $ matrix.node-version
uses: actions/setup-node@v2.4.1
with:
node-version: $ matrix.node-version
- name: Install deps
run: yarn --frozen-lockfile
- name: Test
env:
MONGODB_URL_TEST: $secrets.MONGODB_URL_TEST
AUTH_TOKEN: $secrets.AUTH_TOKEN
run: yarn test
- name: Build the project
run: yarn build
- name: Deploy the project
if: $github.ref == 'refs/heads/main'
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: $secrets.HEROKU_API_KEY
heroku_app_name: "testjvcapi"
heroku_email: "joaovitorcasarin@hotmail.com"
env:
HD_MONGODB_URL: $secrets.MONGODB_URL
HD_AUTH_TOKEN: $secrets.AUTH_TOKEN
这是我触发的最后一个操作:https://github.com/joaocasarin/test-selfapi/actions/runs/1365239970
这是回购:https://github.com/joaocasarin/test-selfapi/
这是部署到heroku后的日志:
2021-10-20T20:33:33.000000+00:00 app[api]: Build started by user *****@hotmail.com
2021-10-20T20:34:16.052764+00:00 app[api]: Release v6 created by user *****@hotmail.com
2021-10-20T20:34:16.052764+00:00 app[api]: Deploy 1192ce7c by user *****@hotmail.com
2021-10-20T20:34:16.359307+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-20T20:34:18.914264+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-20T20:34:20.660465+00:00 app[web.1]: [heroku-exec] Starting
2021-10-20T20:34:20.956196+00:00 app[web.1]:
2021-10-20T20:34:20.956213+00:00 app[web.1]: > self-api@1.0.0 start /app
2021-10-20T20:34:20.956214+00:00 app[web.1]: > node ./dist/index.js
2021-10-20T20:34:20.956214+00:00 app[web.1]:
2021-10-20T20:34:21.713756+00:00 app[web.1]: Listening on port 8260
2021-10-20T20:34:21.775734+00:00 heroku[web.1]: State changed from starting to up
2021-10-20T20:34:21.911902+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-20T20:34:21.912248+00:00 app[web.1]: npm ERR! errno 1
2021-10-20T20:34:21.926340+00:00 app[web.1]: npm ERR! self-api@1.0.0 start: `node ./dist/index.js`
2021-10-20T20:34:21.926408+00:00 app[web.1]: npm ERR! Exit status 1
2021-10-20T20:34:21.926490+00:00 app[web.1]: npm ERR!
2021-10-20T20:34:21.926548+00:00 app[web.1]: npm ERR! Failed at the self-api@1.0.0 start script.
2021-10-20T20:34:21.926604+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-20T20:34:21.933864+00:00 app[web.1]:
2021-10-20T20:34:21.933977+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-20T20:34:21.934035+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-20T20_34_21_928Z-debug.log
2021-10-20T20:34:22.121378+00:00 heroku[web.1]: Process exited with status 1
2021-10-20T20:34:22.265731+00:00 heroku[web.1]: State changed from up to crashed
2021-10-20T20:34:22.288685+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-20T20:34:24.000000+00:00 app[api]: Build succeeded
2021-10-20T20:34:24.543897+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-20T20:34:25.605048+00:00 app[web.1]: [heroku-exec] Starting
2021-10-20T20:34:25.900511+00:00 app[web.1]:
2021-10-20T20:34:25.900518+00:00 app[web.1]: > self-api@1.0.0 start /app
2021-10-20T20:34:25.900518+00:00 app[web.1]: > node ./dist/index.js
2021-10-20T20:34:25.900519+00:00 app[web.1]:
2021-10-20T20:34:26.661060+00:00 app[web.1]: Listening on port 33178
2021-10-20T20:34:26.671025+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-20T20:34:26.674395+00:00 app[web.1]: npm ERR! errno 1
2021-10-20T20:34:26.676324+00:00 app[web.1]: npm ERR! self-api@1.0.0 start: `node ./dist/index.js`
2021-10-20T20:34:26.676389+00:00 app[web.1]: npm ERR! Exit status 1
2021-10-20T20:34:26.676462+00:00 app[web.1]: npm ERR!
2021-10-20T20:34:26.676511+00:00 app[web.1]: npm ERR! Failed at the self-api@1.0.0 start script.
2021-10-20T20:34:26.676557+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-20T20:34:26.682667+00:00 app[web.1]:
2021-10-20T20:34:26.682776+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-20T20:34:26.682829+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-20T20_34_26_677Z-debug.log
2021-10-20T20:34:26.877812+00:00 heroku[web.1]: Process exited with status 1
2021-10-20T20:34:27.141848+00:00 heroku[web.1]: State changed from starting to crashed
谁能给我一盏灯?这是我第一次尝试github操作。
谢谢
编辑:这是Deploy the project
步骤信息:
Run akhileshns/heroku-deploy@v3.12.12
Created and wrote to ~/.netrc
Successfully logged into heroku
› Warning: Our terms of service have changed:
› https://dashboard.heroku.com/terms-of-service
Added git remote heroku
Setting MONGODB_URL, AUTH_TOKEN and restarting testjvcapi... done, v5
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/nodejs
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: USE_YARN_CACHE=true
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote: engines.yarn (package.json): unspecified (use default)
remote:
remote: Resolving node version 14.x...
remote: Downloading and installing node 14.18.1...
remote: Using default npm version: 6.14.15
remote: Resolving yarn version 1.22.x...
remote: Downloading and installing yarn (1.22.17)
remote: Installed yarn 1.22.17
remote:
remote: -----> Restoring cache
remote: - yarn cache
remote:
remote: -----> Installing dependencies
remote: Installing node modules (yarn.lock)
remote: yarn install v1.22.17
remote: [1/4] Resolving packages...
remote: [2/4] Fetching packages...
remote: [3/4] Linking dependencies...
remote: [4/4] Building fresh packages...
remote: Done in 7.59s.
remote:
remote: -----> Build
remote: Running build (yarn)
remote: yarn run v1.22.17
remote: $ rimraf ./dist && tsc
remote: Done in 11.61s.
remote:
remote: -----> Pruning devDependencies
remote: yarn install v1.22.17
remote: [1/4] Resolving packages...
remote: [2/4] Fetching packages...
remote: [3/4] Linking dependencies...
remote: [4/4] Building fresh packages...
remote: warning Ignored scripts due to flag.
remote: Done in 3.65s.
remote:
remote: -----> Caching build
remote: - yarn cache
remote:
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote: Default types for buildpack -> web
remote:
remote: -----> Compressing...
remote: Done: 41.9M
remote: -----> Launching...
remote: Released v6
remote: https://testjvcapi.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/testjvcapi.git
f9075d9..1192ce7 HEAD -> main
【问题讨论】:
可能来自the connectMongodb function,需要记录错误才能了解更多 嘿@BertrandMartel 你说得对!我刚刚发现我的github秘密MONGODB_URL
没有设置,只有MONGODB_URL_TEST
。那是在 heroku 上设置一个空的环境变量,从而使应用程序崩溃。
【参考方案1】:
正如Bertrand所说,mongodb连接有问题,所以我刚刚发现变量MONGODB_URL
没有设置,只有测试一个,所以它使应用程序崩溃,因为它是undefined
猫鼬,让它退出。
【讨论】:
以上是关于从 Github Actions 部署后应用程序立即崩溃的主要内容,如果未能解决你的问题,请参考以下文章
Github Actions简单部署一个vue/react项目
在GitHub Actions上进行Flutter 的测试和部署
Github Actions Artifact 在 Azure Web Apps 中部署需要花费很多时间