This example will guide you how to run tests in your Ruby application and deploy it automatiacally as Heroku application.
You can checkout the example source and check CI status.
This is what the .gitlab-ci.yml
file looks like for this project:
test:
script:
- apt-get update -qy
- apt-get install -y nodejs
- bundle install --path /cache
- bundle exec rake db:create RAILS_ENV=test
- bundle exec rake test
staging:
type: deploy
script:
- gem install dpl
- dpl --provider=heroku --app=gitlab-ci-ruby-test-staging --api-key=$HEROKU_STAGING_API_KEY
only:
- master
production:
type: deploy
script:
- gem install dpl
- dpl --provider=heroku --app=gitlab-ci-ruby-test-prod --api-key=$HEROKU_PRODUCTION_API_KEY
only:
- tags
This project has three jobs:
test
- used to test rails application,staging
- used to automatically deploy staging environment every push to master
branchproduction
- used to automatically deploy production environmnet for every created tagYou'll need to create two variables in 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.Find your Heroku API key in Manage Account.
For each of your environments, you'll need to create a new Heroku application. You can do this through the Dashboard.
First install Docker Engine.
To build this project you also need to have GitLab Runner.
You can use public runners available on ci.gitlab.com
, but you can register your own:
gitlab-ci-multi-runner register \
--non-interactive \
--url "https://ci.gitlab.com/" \
--registration-token "PROJECT_REGISTRATION_TOKEN" \
--description "ruby-2.1" \
--executor "docker" \
--docker-image ruby:2.1 \
--docker-postgres latest
With the command above, you create a runner that uses ruby:2.1 image and uses postgres database.
To access PostgreSQL database you need to connect to host: postgres
as user postgres
without password.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。