使用GitLab将Node.js应用程序连续部署到Heroku [英] Continuous Deployment of a Node.js app to Heroku using GitLab
问题描述
有一些教程介绍了Ruby和Python应用程序的部署,但是我找不到关于NodeJS的好的文档或示例.
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
有人共享.gitlab-ci.yml
吗?
推荐答案
- 创建项目
npm init -y
npm i #install dependencies
- 在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
}
-
创建一个heroku项目
create a heroku project
- 选择 NEW -> 创建新应用
- 设置应用名称& 选择一个地区
- 点击创建应用
- select NEW -> Create new app
- set the App name & choose a region
- click on Create app
Gitlab安装程序创建新的仓库或添加到gitlab网站上给出的现有项目
Gitlab setup create new repo or add to exist project given on gitlab website
创建一个.gitlab-ci.yml文件
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
- 设置-> CI/CD->变量->展开
- 输入变量键-> .gitlab-ci.yml中的变量名
- 输入变量值-> Heroku Api键
获取Heroku Api密钥
Get the Heroku Api Key
- Heroki Dashborad->帐户设置
在Gitlab上设置跑步者
set the Runner on Gitlab
- 设置-> CI/CD->变量->展开
- Setting -> CI/CD -> Variable -> Expand
- 特定跑步者
- Specific Runners
- Install the gitlab-runner
- Windows
- Linux
- MacOS
- For setup steps here
- 只需单击禁用共享运行程序以启用共享运行程序
- just click Disable shared Runners to enable the shared runner
将文件推送到gitlab,它将自动部署在heroku上
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
这篇关于使用GitLab将Node.js应用程序连续部署到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!