I am trying to configure the CircleCi setup.
When I try to run the tests in my own environment then everything works out, but when I try to run it in Circle CI, then I haave got this error.
PHPUnit 5.6.0 by Sebastian Bergmann and contributors.
IIIII.IIIIIIIIIIIIIIIIIIIIIIIIIIIIIFFFFFFFFFFFFIIII..IIIIIIIIIIII 65 / 89 ( 73%)
IIIIIIIIIIIIIIIIIIIIIII. 89 / 89 (100%)
Time: 1.27 seconds, Memory: 56.00MB
There were 12 failures:
1) App\Test\TestCase\Controller\TagsControllerTest::testStages
exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /home/ubuntu/cemcloud2/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php:48
This is the first part of the error.
I am getting that I have an error with my database configuration.
We are using Vagrant with the script (not sure if this is viable).
Also we are using mariaDB 10.1.19 and I have built up a test database for PHPUnit to run the tests against.
I don't know how to add this database with the configuration of mariadb and specific database.
I know that I have to add the
database.yml.ci
to my config file so I have added it in there and it looks like this.
test:
adapter: mysql
database: cemcloudTest
username: root
password: ''
Also I have added the circle.yml to our project root and it looks like this.
machine:
php:
version: 7.0
mysql:
version: 10.1.19
database:
override:
- cp config/database.yml.ci config/database.yml
- bundle exec rake db:create db:schema:load
Could someone help me out ?
in your cicle.yml database have to be created with name you use in your test config.
database:
override:
- mysql -u ubuntu -e "create database circle_ruby_test"
So that, this is the db conf:
test: # connection name
adapter: mysql2
encoding: utf8
reconnect: false
host: localhost
database: circle_ruby_test #your created DB
username: ubuntu #default circle user
pool: 25
socket: /var/run/mysqld/mysqld.sock # default sock location for circle
HTH:)
Related
Related to this thread, I am trying to create 2 containers: 1 with a rails app, and the other with a MySQL database but I keep getting the Mysql2::Error (Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' in my apps production.log file after I hit the container's IP http://192.168.59.103
When I start the rails container, I am attempting to link them and do get an error if I specify an incorrect MySQL name. What am I missing to successfully link the containers so the full app runs in containers?
Rails container command
docker run --name games-app --link test-mysql:mysql -p 8080 -d -e SECRET_KEY_BASE=test sample_rails_games_app
Here are my files:
Dockerfile
# Publish port 8080
EXPOSE 8080
CMD ["bundle", "exec","unicorn", "-p", "8080"]
CMD ["bunde", "exec", "rake", "db:migrate"]
Rails database.yml (dev and test are the same as production)
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: root
host: localhost
#socket: /tmp/mysql.sock
production:
<<: *default
database: weblog_production
7/31/15 Edit
The docker log shows the unicorn server running:
docker logs a13bf7851c6d
I, [2015-07-31T18:10:59.860203 #1] INFO -- : listening on addr=0.0.0.0:8080 fd=9
I, [2015-07-31T18:10:59.860583 #1] INFO -- : worker=0 spawning...
I, [2015-07-31T18:10:59.864143 #1] INFO -- : master process ready
I, [2015-07-31T18:10:59.864859 #7] INFO -- : worker=0 spawned pid=7
I, [2015-07-31T18:10:59.865097 #7] INFO -- : Refreshing Gem list
I, [2015-07-31T18:11:01.796690 #7] INFO -- : worker=0 ready
7/31/15 Solution Thanks to #Rico
db:migrate was having problems running so I ultimately ran it by hand in a docker run command. Make sure you do this after the container is already created, or during the creation process as it needs the linking to the DB container
This linking article helped me understand that my link was not being created so there was no way to communicate properly.
Once I understood how to accurately make the link, I did update my database.yml with the host and port values
Use this command to check the names of your env variables docker run --rm --name <unique-value> --link <db-name> <non-db-image> env.
Use this to see the value of the links in your app container docker inspect -f "{{ .HostConfig.Links }}" <app-name>
Actually your bundle exec unicorn -p 8080 CMD is superseding the bundle exec rake db:migrate as it doesn't return.
You should run your db:migrate first and you should run it with the RUN command as CMD is the primary command in docker.
But the other problem is with your database.yml file. You are pointing your db to a db server that runs on the same container as in the application. You should populate the values of your database.yml from the env variables created after you link your source container (application) to destination container (db server container). The env variables are created in the source container.
More info here: https://docs.docker.com/userguide/dockerlinks/
So for example:
$ docker run --rm --name web2 --link db:db training/webapp env
. . .
DB_NAME=/web2/db
DB_PORT=tcp://172.17.0.5:5432
DB_PORT_5432_TCP=tcp://172.17.0.5:5432
DB_PORT_5432_TCP_PROTO=tcp
DB_PORT_5432_TCP_PORT=5432
DB_PORT_5432_TCP_ADDR=172.17.0.5
Your database.yml should look something like this:
default: &default
adapter: mysql2
encoding: utf8
pool: 5
database: <%= ENV['DB_NAME'] %>
username: root
password: root
host: <%= ENV['DB_PORT_5432_TCP_ADDR'] %>
port: <%= ENV['DB_PORT_5432_TCP_PORT'] %>
You can't have 2 CMD commands in your Dockerfile, in fact only the last one is kept. The CMD command executed is `
CMD ["bunde", "exec", "rake", "db:migrate"]`
the other, the
CMD ["bundle", "exec","unicorn", "-p", "8080"]
is superseded.
See Supervisor
https://docs.docker.com/articles/using_supervisord/
if you want to run more than one rocess in your container, or run 2 differnet containers
In my current application i am using PostgreSQL Data base,
but I want to change the PostgreSQL database into MYSQL DB.
if it's impossible ?
Step 1
Make a backup copy of your data
For Rails 3, install the YAML DB gem: https://github.com/ludicast/yaml_db
For Rails 2.x install the YAML DB plugin:
script/plugin install git://github.com/adamwiggins/yaml_db.git
Run the dump task
rake db:dump
Step 2
Update your config/database.yml file.
Step 3 :
gem install mysql
Have rake create your database
rake db:create
rake db:schema:load
Step 4
Use YamlDb to reload your data into MySql
rake db:load
this is a duplicate
Migrate database from Postgres to MySQL
dont forget to change the gems and your database config file to something like this:
development:
adapter: mysql2
encoding: utf8
database: my_db_name
username: root
password: my_password
host: 127.0.0.1
port: 3306
I'm currently working on getting the activerecord_any_of library set up to use TravisCI for automated testing across multiple database types.
Currently I have the following:
In .travis.yml
language: ruby
script:
- bundle exec rake test
before_script:
- mysql -e 'create database activerecord_any_of_test;'
- psql -c 'create database activerecord_any_of_test;' -U postgres
before_install:
- gem install bundler # use the latest bundler, since Travis doesn't update for us
rvm:
- 1.9.3
- 2.0.0
- 2.1.1
- rbx
- jruby-19mode
env:
- DB=mysql
- DB=sqlite3
- DB=sqlite3mem
- DB=postgresql
gemfile:
- gemfiles/rails3.gemfile
- gemfiles/rails4.gemfile
- gemfiles/rails_edge.gemfile
matrix:
allow_failures:
- gemfile: gemfiles/rails_edge.gemfile
- env: DB=postgresql
- env: DB=mysql
And database.yml:
sqlite3:
adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
database: activerecord_any_of.sqlite3.db
sqlite3mem:
adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
database: ":memory:"
postgresql:
adapter: postgresql
encoding: unicode
database: activerecord_any_of_test
pool: 5
username: postgres
password:
min_messages: warning
mysql:
adapter: <%= defined?(JRUBY_VERSION) ? "jdbcmysql" : "mysql2" %>
host: localhost
username: root
password:
database: activerecord_any_of_test
encoding: utf8
## Add DB Configuration to run Oracle tests
oracle:
adapter: oracle_enhanced
host: localhost
username: activerecord_any_of_dev
password:
database: xe
And my test_helper.rb
plugin_test_dir = File.dirname(__FILE__)
require 'rubygems'
require 'bundler/setup'
require 'rails'
require 'active_record'
require 'activerecord_any_of'
require "rails/test_help"
require 'combustion/database'
require 'database_cleaner'
require 'pry'
require 'logger'
require 'yaml'
require 'erb'
require 'support/models'
ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)
ActiveRecord::Base.establish_connection(ENV["DB"] ||= "sqlite3mem")
ActiveRecord::Migration.verbose = false
Combustion::Database.create_database(ActiveRecord::Base.configurations[ENV["DB"]])
load(File.join(plugin_test_dir, "db", "schema.rb"))
ActiveSupport::TestCase.fixture_path = "#{plugin_test_dir}/fixtures"
ActiveSupport::TestCase.use_transactional_fixtures = true
ActiveSupport::TestCase.teardown do
unless /sqlite/ === ENV['DB']
Combustion::Database.drop_database(ActiveRecord::Base.configurations[ENV['DB']])
end
end
When I run the tests on TravisCI, I get sqlite and sqlitemem matrices running just fine in most cases. However, when running against MySQL, I get the following errors:
Mysql2::Error: Unknown database activerecord_any_of_test
And when running against PostgreSQL I get the error:
ActiveRecord::StatementInvalid: PG::ConnectionBad: connection is closed: ROLLBACK
Since I'm creating the databases, I don't see why there would be any problems. As far as I can tell, I've configured the database.yml to use the proper credentials. Maybe I'm using Combustion::Database wrong? How can I properly connect to my databases in my tests?
I've adapted the setup used in awesome_nested_set for setting up the tests for activerecord_any_of. Failing tests can be seen on Travis.
My deployment is running fine until the migration .. which fails
rake aborted!
DEBUG [874287b0] ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
DEBUG [874287b0] /home/kadoudal/rails/swim-tech.eu/site/swimtech/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection'
I run : cap staging deploy:check:linked_files, whic is successful , database.yml is symlinked correctly and contains :
# encoding: utf-8
defaults: &defaults
adapter: mysql2
host: localhost
timeout: 60000
encoding: utf8
production:
<<: *defaults
database: mydb_production
username: xxxxxxxxxxx
password: xxxxxxxxxxxxxx
why the Adapter is not found ?
forgot I was running a cap staging.... and there is no staging db in the database.yml
I created a staging server by cloning the production server on Rackspace. In this scenario, I want the staging server to still use the 'production' rails environment and the production db (on the staging server), so I set this in the config/deploy/staging.rb file:
set :stage, :production
and it works great.
I just created a new Rails 4 app with MySql as follows:
rails new mysqltest -d mysql
And modified the database.yml with the right credentials.
I generated a sample contoller and updated the routes for root route.
When I start using WEBrick in production,
rails s -e production
The site works. I see the index page.
When I start using Passenger without 3000 port, I see the following error:
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
Passsenger is running in Production environment.
My database.yml
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
The case I used in database.yml file and the apache config file were different.
Both should be same. eg. production.
In apache config, I gave as Production. After changing it to production it worked.
Source - https://groups.google.com/forum/#!topic/phusion-passenger/Kr-R0gSw6i8
Did you create your local production database?
rake db:create:all
RAILS_ENV=production bundle exec rake db:migrate
Is your database.yml file setup properly to use a production database?
Do you have a mysql gem in your gem file.
Common problems.