使用GitLab连续部署NodeJS [英] Continuous Deployment of a NodeJS using GitLab

查看:643
本文介绍了使用GitLab连续部署NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NodeJS中开发了一个API,并通过 .gitlab-ci.yml 文件成功建立了持续集成。下一个阶段是如果所有测试都通过master分支,那么就要对Heroku进行连续部署。



有很多关于Ruby和Python应用程序部署的教程,但没有任何在NodeJS上。目前我的 .gitlab-ci.yml 文件看起来像这样:

  image:node:latest 

job1:
脚本:ls -l

测试:
脚本:npm install; npm test

生产:
类型:部署
脚本:
- npm install
- npm start
- gem install dpl
- dpl --provider = heroku --app = my-first-nodejs --api-key = XXXXXXXXXX
only:
- master

Ruby和Python教程使用 dpl 工具进行部署,但是如何在部署后在服务器上启动NodeJS脚本?

在添加生产部分并推送它之后,测试运行并通过,但部署阶段陷入挂起状态。控制台是空白的。有没有人为NodeJS设置了一个成功的CD脚本?

解决方案

您可以使用更简单的YAML脚本, (在生产部署之前运行测试),然后您可以在Heroku部署阶段使用不同的映像。因此,对于节点应用程序,您将默认图像定义为node:latest。


$ b

  image:node:latest 
$ b $然后对于使用dpl的生产部署,您可以使用红宝石图像。 b阶段:
- job1
- 测试
- 生产

job1:
阶段:job1
脚本:ls -l

测试:
阶段:测试
脚本:
- npm安装
- npm测试
工件:
路径:
- dist /

制作:
类型:部署
阶段:制作
image:ruby:latest
脚本:
- 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


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.

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

The Ruby and Python tutorials use the dpl tool to deploy but how can I start the NodeJS script on the server once deployed?

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?

解决方案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆