Toa*_*ien 31 git deployment heroku continuous-deployment gitlab
在我的团队中,我们使用Gitlab作为远程存储库,因此我们正在寻找一种解决方案,直接将我们的应用程序自动部署到Heroku.我们从Github找到了从Heroku自动部署应用程序的Codeship.
有小费吗?窍门?
小智 38
如果您不准备使用Ruby/dpl,可以按如下方式部署到Heroku:
查找您的Heroku API密钥(帐户设置 - > Heroku Web控制台上的API密钥)并将其作为Gitlab秘密变量提供,例如HEROKU_API_KEY(请注意,这些值与heroku auth:token返回的值不同...)
然后在相关作业的.gitlab-ci.yml配置文件中添加两个脚本行:
git remote add heroku https://heroku:$HEROKU_API_KEY@git.heroku.com/<name of your heroku app>.git
git push -f heroku HEAD:master
Run Code Online (Sandbox Code Playgroud)
您可以在http://blog.thecodewhisperer.com/permalink/deploying-jekyll-to-heroku-using-gitlab-ci上查看详细说明.
dni*_*t13 29
这是我找到的解决方案,如果链接断开则重述:
配置项目
这就是.gitlab-ci.yml文件对于这个项目的样子:
test:
script:
# this configures Django application to use attached postgres database that is run on `postgres` host
- export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app
- apt-get update -qy
- apt-get install -y python-dev python-pip
- pip install -r requirements.txt
- python manage.py test
staging:
type: deploy
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=gitlab-ci-python-test-staging --api-key=$HEROKU_STAGING_API_KEY
only:
- master
production:
type: deploy
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=gitlab-ci-python-test-prod --api-key=$HEROKU_PRODUCTION_API_KEY
only:
- tags
Run Code Online (Sandbox Code Playgroud)
这个项目有三个工作:
test - 用于测试Django应用程序,
staging - 用于每次推送到主分支时自动部署登台环境
生产 - 用于为每个创建的标签自动部署生产环境
存储API密钥
您需要在Project> Variables中创建两个变量:
HEROKU_STAGING_API_KEY - Heroku API key used to deploy staging app,
HEROKU_PRODUCTION_API_KEY - Heroku API key used to deploy production app.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38178 次 |
| 最近记录: |