Class: Mcrain::Mysql
Constant Summary collapse
- DB_DIR_ON_CONTAINER =
'/var/lib/mysql'.freeze
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#db_dir ⇒ Object
Returns the value of attribute db_dir.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Base
Instance Method Summary collapse
- #build_docker_options ⇒ Object
- #client_class ⇒ Object
- #client_init_args ⇒ Object
- #client_require ⇒ Object
- #wait_for_ready ⇒ Object
Methods inherited from Base
#initialize, #logger, #reset, #setup, #start, #start_callback, #stop_or_kill_and_remove, #teardown, #wait, #wait_port, work_dir
Methods included from ClientProvider
#build_client, #client, #client_instantiation_script, #client_script
Methods included from ContainerController
#add_volume_options, #container, #container_image, #find_portno, #host, included, #info, #ip, #name, #port, #ssh_uri, #url
Constructor Details
This class inherits a constructor from Mcrain::Base
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
36 37 38 |
# File 'lib/mcrain/mysql.rb', line 36 def database @database end |
#db_dir ⇒ Object
Returns the value of attribute db_dir.
35 36 37 |
# File 'lib/mcrain/mysql.rb', line 35 def db_dir @db_dir end |
#password ⇒ Object
Returns the value of attribute password.
37 38 39 |
# File 'lib/mcrain/mysql.rb', line 37 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
37 38 39 |
# File 'lib/mcrain/mysql.rb', line 37 def username @username end |
Instance Method Details
#build_docker_options ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mcrain/mysql.rb', line 41 def r = super username = self.username || "root" # overwrite locally key_user = (username == "root") ? nil : "MYSQL_USER" key_pw = (username == "root") ? "MYSQL_ROOT_PASSWORD" : "MYSQL_PASSWORD" envs = [] envs << (password.blank? ? "MYSQL_ALLOW_EMPTY_PASSWORD=yes" : "#{key_pw}=#{password}") envs << "#{key_user}=#{username}" if key_user envs << "MYSQL_DATABASE=#{database}" if database (r, DB_DIR_ON_CONTAINER, File.(db_dir)) if db_dir && !db_dir.empty? r['Env'] = envs unless envs.empty? return r end |
#client_class ⇒ Object
16 17 18 |
# File 'lib/mcrain/mysql.rb', line 16 def client_class ::Mysql2::Client end |
#client_init_args ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mcrain/mysql.rb', line 20 def client_init_args = { host: host, port: port, username: username || "root" } [:password] = password if password.present? [:database] = database if database.present? return [] end |
#client_require ⇒ Object
12 13 14 |
# File 'lib/mcrain/mysql.rb', line 12 def client_require 'mysql2' end |
#wait_for_ready ⇒ Object
31 32 33 |
# File 'lib/mcrain/mysql.rb', line 31 def wait_for_ready client.query("show databases").to_a end |