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