在我的团队中,我们使用Gitlab作为远程代码仓库,现在我们正在寻找一种自动部署应用到Heroku的解决方案。我们发现Codeship可以从Github自动部署应用到Heroku。
有什么技巧或诀窍吗?
在我的团队中,我们使用Gitlab作为远程代码仓库,现在我们正在寻找一种自动部署应用到Heroku的解决方案。我们发现Codeship可以从Github自动部署应用到Heroku。
有什么技巧或诀窍吗?
如果您不想使用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
您可以在http://blog.thecodewhisperer.com/permalink/deploying-jekyll-to-heroku-using-gitlab-ci上查看详细说明。-q
标志,否则你会在输出末尾泄露 $HEROKU_API_KEY
。 - Fery Wheroku:master
吗? - Théo Championgit remote add heroku ...
有时会导致 fatal: remote heroku already exists
的错误。为了强制返回代码为0,将其更改为 git remote add heroku ... || true
。 - dancypants配置项目
这个项目的 .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
这个项目有三项任务:
测试 - 用于测试 Django 应用程序,
暂存 - 用于在每次推送到主分支时自动部署暂存环境
生产 - 用于在每次创建标签时自动部署生产环境
存储 API 密钥
您需要在“项目” > “变量”中创建两个变量:
HEROKU_STAGING_API_KEY - Heroku API key used to deploy staging app,
HEROKU_PRODUCTION_API_KEY - Heroku API key used to deploy production app.
Project > Variables
在哪里?我在Gitlab中找不到它。 - Cynthia Sanchezdpl
的基本用法。staging:
stage: deploy
script:
- apt-get update -yq
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=my-app-staging --api_key=$HEROKU_STAGING_API_KEY
only:
- main
对于那些在这里寻找答案的人,请阅读GitLab DPL文档