我在gitlab.com上托管了一个Rails应用程序,并按照以下指南将其配置为部署到heroku:http://docs.gitlab.com/ce/ci/examples/test-and-deploy-ruby-application-to-heroku.html。它工作正常。
我的问题是,每次部署到heroku时如何运行迁移?通过CLI部署时,我通常会执行以下操作:
git push heroku master && heroku run rake db:migrate
但是使用gitlab-ci.yml我不知道如何执行此操作...
最佳答案
如果您想在GitLab CI流程中充分利用Heroku CLI的全部功能(包括由于某种原因而导致迁移失败导致构建失败),也可以尝试这种方法,该方法将安装Heroku CLI并提供状态Heroku命令的代码返回到GitLab,当然还有命令行输出。在命令行上使用没有凭据的heroku run
时,需要将HEROKU_API_KEY
环境变量设置为可以访问相关应用程序的键。
before_script:
- echo "deb http://toolbelt.heroku.com/ubuntu ./" > /etc/apt/sources.list.d/heroku.list
- wget -O- https://toolbelt.heroku.com/apt/release.key | apt-key add -
- apt-get update
- apt-get install -y heroku-toolbelt
- gem install dpl
stages:
- deploy
test_on_heroku:
type: deploy
script:
- dpl --provider=heroku --app=my_heroku_app --api-key=$HEROKU_API_KEY
- heroku run <your command here> --exit-code --app my_heroku_app
我确实在Heroku实例上运行测试,以确保环境完全相同。这是真正方便的地方。
关于ruby-on-rails - Gitlab CI-部署到Heroku并运行迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514755/