I have a rails 5 repository that's trying to run CI with pipeline. It's running a custom image using the following Dockerfile
# Use an official Ruby runtime as a parent image
FROM ruby:2.3.1-slim
MAINTAINER mmhan
# Install curl
RUN apt-get update && apt-get install -y curl
# Update packagelist
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# Install further requirements to run ruby on rails
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libmysqlclient-dev \
nodejs \
yarn \
vim
# Configure the main working directory
RUN mkdir -p /app
WORKDIR /app
The steps in pipelines.yml are as followed:
- step:
caches:
- bundler
- yarn
services:
- mysql
script:
# set up database
- export DATABASE_URL=mysql://test_user:test_user_password@localhost/mmcdb_ci_production
- cp ./config/database.ci.yml ./config/database.yml
# set up bundle
- bundle install --deployment --path vendor/bundle
# run tests
- pwd
- cat config/database.yml
- bundle exec rails runner 'pp Rails.configuration.database_configuration'
The `cat` command always outputs the correct configuration with `mysql2` adapter. However, when `config/environment.rb` is ran it complains that it cannot find `mysql` adapter.
By catching the exception in environment.rb, I can see the output of the configuration being over-written:
puts 'Rails environment: ' + Rails.env.to_s
begin
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
rescue LoadError
pp Rails.configuration.database_configuration #output 1
pp ActiveRecord::Base.configurations #output 2
end
The output 1 is always correct as followed:
{"default"=>{"adapter"=>"mysql2", "encoding"=>"utf8", "host"=>"localhost"},
"development"=>
{"adapter"=>"mysql2",
"encoding"=>"utf8",
"host"=>"localhost",
"database"=>"mmcdb_ci_development"},
"test"=>
{"adapter"=>"mysql2",
"encoding"=>"utf8",
"host"=>"localhost",
"database"=>"mmcdb_ci_test",
"username"=>"test_user",
"password"=>"test_user_password"},
"production"=>
{"adapter"=>"mysql2",
"encoding"=>"utf8",
"host"=>"localhost",
"database"=>"mmcdb_ci_production"}}
And the output 2 is the one that's being overwritten:
{"default"=>{"adapter"=>"mysql2", "encoding"=>"utf8", "host"=>"localhost"},
"development"=>
{"adapter"=>"mysql2",
"encoding"=>"utf8",
"host"=>"localhost",
"database"=>"mmcdb_ci_development"},
"test"=>
{"adapter"=>"mysql",
"encoding"=>"utf8",
"host"=>"localhost",
"database"=>"mmcdb_ci_production",
"username"=>"test_user",
"password"=>"test_user_password"},
"production"=>
{"adapter"=>"mysql2",
"encoding"=>"utf8",
"host"=>"localhost",
"database"=>"mmcdb_ci_production"}}
What's going on here? Was there something in the pipeline that's doing some kind of automagic configurations for me that I should take note of? Or is it all rails?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.