GitLab CI 卡在正在运行的 NodeJS 服务器上 [英] GitLab CI stuck on running NodeJS server
问题描述
我正在尝试使用 GitLab CI 在服务器上构建、测试和部署 Express 应用程序(Runner 与 shell 执行器一起运行).但是,test:async
和 deploy_staging
作业不会终止.但是当检查 GitLab 中的终端时,Express 服务器确实启动了.什么给了?
I'm trying to use GitLab CI to build, test and deploy an Express app on a server (the Runner is running with the shell executor). However, the test:async
and deploy_staging
jobs do not terminate. But when checking the terminal inside GitLab, the Express server does indeed start. What gives ?
stages:
- build
- test
- deploy
### Jobs ###
build:
stage: build
script:
- npm install -q
- npm run build
- knex migrate:latest
- knex seed:run
artifacts:
paths:
- build/
- node_modules/
tags:
- database
- build
test:lint:
stage: test
script:
- npm run lint
tags:
- lint
# Run the Express server
test:async:
stage: test
script:
- npm start &
- curl http://localhost:3000
tags:
- server
deploy_staging:
stage: deploy
script:
- npm start
environment:
name: staging
url: my_url_here
tags:
- deployment
npm start
就是 node build/bundle.js
.构建脚本正在使用 Webpack.
The npm start
is just node build/bundle.js
. The build script is using Webpack.
推荐答案
您在测试阶段启动了一个永远不会终止的后台作业 - 因此该作业永远运行.
You are starting a background job during your test phase which never terminates - therefore the job runs forever.
GitLab CI 作业的理念是短期运行的任务——例如编译、执行单元测试或收集代码覆盖率等信息——这些任务以预定义的顺序执行.在您的情况下,顺序是 build ->测试->部署
;由于 test
作业没有完成,deploy
甚至没有被执行.
The idea of the GitLab CI jobs are shortly-running tasks - like compiling, executing unit tests or gathering information such as code coverage - which are executed in a predefined order. In your case, the order is build -> test -> deploy
; since the test
job doesn't finish, deploy
isn't even executed.
根据您的环境,您必须创建一个不同的作业来部署您的节点应用程序.例如,您可以使用 scp
之类的工具将构建输出推送到远程服务器或将其上传到 AWS;之后,您在 .gitlab-ci.yml
的 url:
字段中引用最终 URL.
Depending on your environment, you will have to create a different job for deploying your node app. For example, you can push the build output to a remote server using a tool like scp
or upload it to AWS; after that, you reference the final URL in the url:
field in your .gitlab-ci.yml
.
这篇关于GitLab CI 卡在正在运行的 NodeJS 服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!