Class: Conjure::Service::Database::Mysql
- Inherits:
-
Object
- Object
- Conjure::Service::Database::Mysql
- Defined in:
- lib/conjure/service/database/mysql.rb
Instance Method Summary collapse
- #adapter_name ⇒ Object
- #base_image ⇒ Object
- #client_options ⇒ Object
- #container ⇒ Object
- #export(file) ⇒ Object
- #import(file) ⇒ Object
-
#initialize(options) ⇒ Mysql
constructor
A new instance of Mysql.
- #ip_address ⇒ Object
- #name ⇒ Object
- #run ⇒ Object
- #server_image ⇒ Object
Constructor Details
#initialize(options) ⇒ Mysql
Returns a new instance of Mysql.
5 6 7 8 9 |
# File 'lib/conjure/service/database/mysql.rb', line 5 def initialize() @target = [:target] @db_name = [:database_name] @adapter_name = [:adapter_name] end |
Instance Method Details
#adapter_name ⇒ Object
63 64 65 |
# File 'lib/conjure/service/database/mysql.rb', line 63 def adapter_name @adapter_name || "mysql2" end |
#base_image ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/conjure/service/database/mysql.rb', line 11 def base_image @base_image ||= @target.shell.prepare( label: "mysql", setup_commands: [ "apt-get install -y mysql-server mysql-client" ], ) end |
#client_options ⇒ Object
59 60 61 |
# File 'lib/conjure/service/database/mysql.rb', line 59 def "-u root -h #{ip_address} #{@db_name}" end |
#container ⇒ Object
35 36 37 |
# File 'lib/conjure/service/database/mysql.rb', line 35 def container @container ||= server_image.run end |
#export(file) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/conjure/service/database/mysql.rb', line 47 def export(file) File.open file, "w" do |f| f.write base_image.command("/usr/bin/mysqldump #{}") end Log.info "[export] #{File.size file} bytes exported to #{file}" end |
#import(file) ⇒ Object
54 55 56 57 |
# File 'lib/conjure/service/database/mysql.rb', line 54 def import(file) base_image.command "echo 'source /files/#{File.basename file}' | /usr/bin/mysql #{}", files: [file] Log.info "[import] #{File.size file} bytes imported from #{file}" end |
#ip_address ⇒ Object
43 44 45 |
# File 'lib/conjure/service/database/mysql.rb', line 43 def ip_address container.ip_address end |
#name ⇒ Object
39 40 41 |
# File 'lib/conjure/service/database/mysql.rb', line 39 def name @db_name end |
#run ⇒ Object
31 32 33 |
# File 'lib/conjure/service/database/mysql.rb', line 31 def run container end |
#server_image ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/conjure/service/database/mysql.rb', line 20 def server_image @server_image ||= base_image.prepare( label: "mysqlserver", setup_commands: [ "/usr/sbin/mysqld & sleep 5; echo \"GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '' WITH GRANT OPTION\" | /usr/bin/mysql", ], daemon_command: "/usr/sbin/mysqld --bind-address=0.0.0.0", volumes: ["/var/lib/mysql"], ) end |