問題描述
我有一個用 NodeJS 開發的 API,并通過 .gitlab-ci.yml
文件成功設置了持續集成.如果所有測試都在 master 分支上通過,下一階段是設置持續部署到 Heroku.
I have an API developed in NodeJS and have successfully set up continuous integration via a .gitlab-ci.yml
file. The next stage is to set up continuous deployment to Heroku if all tests pass on the master branch.
有很多教程涵蓋了 Ruby 和 Python 應用程序的部署,但沒有關于 NodeJS 的教程.目前我的 .gitlab-ci.yml
文件如下所示:
There are plenty of tutorials covering the deployment of Ruby and Python apps but nothing on NodeJS. Currently my .gitlab-ci.yml
file looks like this:
image: node:latest
job1:
script: "ls -l"
test:
script: "npm install;npm test"
production:
type: deploy
script:
- npm install
- npm start
- gem install dpl
- dpl --provider=heroku --app=my-first-nodejs --api-key=XXXXXXXXXX
only:
- master
Ruby 和 Python 教程使用 dpl
工具進行部署,但部署后如何在服務器上啟動 NodeJS 腳本?
The Ruby and Python tutorials use the dpl
tool to deploy but how can I start the NodeJS script on the server once deployed?
添加生產部分并將其推送后,測試運行并通過,但部署階段卡在待處理狀態.控制臺是空白的.有人為 NodeJS 設置了成功的 CD 腳本嗎?
After adding the production section and pushing it the tests run and pass but the deploy stage gets stuck on pending. The console is blank. Has anyone set up a successful CD script for NodeJS?
推薦答案
您可以使用更簡單的 YAML 腳本,您可以在其中定義 CI 的階段(在生產部署之前運行測試),然后可以使用不同的圖像在 Heroku 部署階段.因此,對于節點應用程序,您將默認圖像定義為節點:最新.然后對于使用 dpl 的生產部署,您可以使用 ruby?? 映像.
you could use a much more simple YAML script where you can define the stages for the CI (to run test before production deploy) you can then use a different image at the Heroku deploy stage. So for a node app you define the default image as node:latest. Then for the production deployment using dpl you can use the ruby image.
image: node:latest
stages:
- job1
- test
- production
job1:
stage: job1
script: "ls -l"
test:
stage: test
script:
- npm install
- npm test
artifacts:
paths:
- dist/
production:
type: deploy
stage: production
image: ruby:latest
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=my-first-nodejs --api-key=XXXXXXXXXX
only:
- master
這篇關于使用 GitLab 持續部署 NodeJS的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!