Magnum CI is a CI environment which we can use for free. Here, I wrote how I setup Rails code into Magnum CI, which is managed at Bitbucket.
Basically, applying codes in Bitbucket to Magnum CI is not so difficult.
Add Magnum Enivronment
For Magnum CI integration, add Magnum Environment. If you use test environment in Magnum CI, you don’t have to do anything.
- Add
magnum.rb
intoconfig/environments
directory. And createmagnum
environment label. - Add secret key for magnum environment. Write it into
config/secrets.yml
. - Add database setting for magnum environment. Write it into
config/database.yml
. Mydatabase.yml
is like the following, username is root.12345678910magnum:<<: *defaultadapter: mysql2database: somedbcharset: utf8mb4encoding: utf8mb4collation: utf8mb4_general_cihost: localhostusername: rootport: 3306 - Create other magnum setting when you have to change other setting for magnum environment.
That’s it. Change in Rails code is finished. After that, you can control Magnum CI build setting by creating script, but I didn’t. In my project, I controlled build instruction on Magnum CI setting page.
Build Configuration
I assume you can add project to Magnum CI. Here, I wrote Build Configuration setting example I used in the project.
- Runtime Version
Set version of Ruby. When I used Magnum CI, the maximum Ruby version that Magnum CI supported was Ruby 2.2.0. On the other hand, Ruby version of the project was 2.2.2. I couldn’t set correct Ruby version in here, but I apply correct version in other way. Build Steps can solve it, that I wrote below.
- Resources
Add required database or redis, etc.
- Environment Variables
Set
RAILS_ENV
.1RAILS_ENV=magnum- Build Step
-
- Before installation
Set correct Ruby version.
12rvm install 2.2.2rvm use ruby-2.2.2- Before test execution
Create DB.
123mysql -u root -e 'create database somedb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;'bundle exec rake db:migratebundle exec rake db:seed- Test suit commands
Execute test.
1bundle exec rspec