git 如何直接从我的 Gitlab 存储库部署到 Heroku

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37048511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:09:15  来源:igfitidea点击:

How to deploy to Heroku directly from my Gitlab repository

githerokudeploymentgitlabcontinuous-deployment

提问by Toanalien

In my team, we use Gitlab as a remote repository, so we are looking for a solution to auto deploy our apps to Heroku. We found Codeship for auto deploying apps to Heroku from Github.

在我的团队中,我们使用 Gitlab 作为远程存储库,因此我们正在寻找一种解决方案来将我们的应用程序自动部署到 Heroku。我们从 Github 找到了用于将应用程序自动部署到 Heroku 的 Codeship。

Any tips? Tricks?

有小费吗?招数?

回答by Zsolt

If you are not prepared to use Ruby/dpl you can deploy to Heroku as follows:

如果您不准备使用 Ruby/dpl,您可以按如下方式部署到 Heroku:

Look up your Heroku API key (Account settings -> API Key on the Heroku web console) and make it available as a Gitlab secret variable e.g. HEROKU_API_KEY (Please note the values is not the same as what heroku auth:token returns...)

查找您的 Heroku API 密钥(帐户设置 -> Heroku Web 控制台上的 API 密钥)并将其作为 Gitlab 秘密变量使用,例如 HEROKU_API_KEY(请注意这些值与 heroku auth:token 返回的值不同...)

Then add two script lines in your .gitlab-ci.ymlconfig file at the relevant job:

然后.gitlab-ci.yml在相关作业的配置文件中添加两个脚本行:

git remote add heroku https://heroku:[email protected]/<name of your heroku app>.git

git push -f heroku HEAD:master

You can see detailed explanation at http://blog.thecodewhisperer.com/permalink/deploying-jekyll-to-heroku-using-gitlab-ci

你可以在http://blog.thecodewhisperer.com/permalink/deploying-jekyll-to-heroku-using-gitlab-ci看到详细的解释

回答by dnit13

Hereis the solution I found , restating in case the link is broken:

是我找到的解决方案,重申以防链接断开:

Configure project

配置项目

This is what the .gitlab-ci.yml file looks like for this project:

这是这个项目的 .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

This project has three jobs:

这个项目有三份工作:

test - used to test Django application,

staging - used to automatically deploy staging environment every push to master branch

production - used to automatically deploy production environmnet for every created tag

test - 用于测试 Django 应用程序,

staging - 用于在每次推送到 master 分支时自动部署 staging 环境

生产 - 用于为每个创建的标签自动部署生产环境

Store API keys

存储 API 密钥

You'll need to create two variables in Project > Variables:

您需要在 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.