有一些教程涵盖了 Ruby 和 Python 应用程序的部署,但我找不到很好的 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项目
- 选择新 -> 创建新应用
- 设置应用名称 & 选择地区
- 点击创建应用
Gitlab setup 创建新的 repo 或添加到 gitlab 网站上给出的现有项目
创建一个 .gitlab-ci.yml 文件
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
- 设置HEROKU_API_KEY
- 设置 -> CI/CD -> 变量 -> 展开
- 输入变量键 -> .gitlab-ci.yml 中的变量名
- 输入变量值 -> Heroku Api Key
获取 Heroku Api key
- Heroki Dashborad -> 账户设置
在 Gitlab 上设置 Runner
将文件推送到 gitlab 它将自动部署在 heroku 上
git add . #to add all the files) git commit -m "message" #to commit files git push origin master
关于node.js - 使用 GitLab 将 Node.js 应用程序持续部署到 Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38885185/