问题
There are tutorials covering the deployment of Ruby and Python apps but I can't find good documentation or examples for NodeJS.
http://docs.gitlab.com/ce/ci/examples/test-and-deploy-python-application-to-heroku.html
http://docs.gitlab.com/ce/ci/examples/test-and-deploy-ruby-application-to-heroku.html
Does anyone have a .gitlab-ci.yml
to share?
回答1:
I have found a detailed article for continuous integration on Heroku:
https://medium.com/@seulkiro/deploy-node-js-app-with-gitlab-ci-cd-214d12bfeeb5
Sample .gitlab-ci.yml file :
https://gitlab.com/seulkiro/node-heroku-dpl
回答2:
- create a project
npm init -y
npm i #install dependencies
- add the following lines in package.json
"engines": {
"node": "8.12.0", //node version
"npm": "6.4.1" //npm version
},
"scripts": {
"start": "node app.js", //heroku will using the following script to run node app
}
create a heroku project
- select NEW -> Create new app
- set the App name & choose a region
- click on Create app
Gitlab setup create new repo or add to exist project given on gitlab website
create a .gitlab-ci.yml file
image: node:latest stages: - production 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=APPNAME_OF_Heroku App --api-key=$HEROKU_API_KEY # security add the heroku api to CI/CD setting only: - master #branch name to deploy on heroku
- Setting HEROKU_API_KEY
- Setting -> CI/CD -> Variable -> Expand
- Input Variable key -> variable name in .gitlab-ci.yml
- Input Variable value -> Heroku Api Key
Get the Heroku Api Key
- Heroki Dashborad -> Account Settings
set the Runner on Gitlab
- Setting -> CI/CD -> Variable -> Expand
- Specific Runners
- Install the gitlab-runner
- Windows
- Linux
- MacOS
- For setup steps here
- Shared Runners
- just click Disable shared Runners to enable the shared runner
- Specific Runners
- Setting -> CI/CD -> Variable -> Expand
push the files to gitlab it will automatically deploy on heroku
git add . #to add all the files) git commit -m "message" #to commit files git push origin master
来源:https://stackoverflow.com/questions/38885185/continuous-deployment-of-a-node-js-app-to-heroku-using-gitlab