module RubyYacht::Plugins::MySQL

This module provides the plugin for managing MySQL databases.

Public Class Methods

load() click to toggle source

This method loads the configuration for the MySQL plugin.

# File lib/ruby_yacht/plugins/mysql.rb, line 5
def self.load
  RubyYacht.configure do
    server_type :mysql do
      container_type :database
      baseline_image 'mysql'
      server_default port: 3306
    end
  end

  RubyYacht.configure do
    add_hooks(database_server_type: :mysql, container_type: :database, script_folder: File.join(File.dirname(__FILE__), 'mysql', 'scripts')) do
      during(:install_libraries) do
        set_environment_variable 'DEBIAN_FRONTEND', 'noninteractive'
        command 'apt-get install -y mysql-server'
      end
      during(:create_databases) { run_script :bash, 'setup.bash' }

      before(:startup) do
        set_environment_variable('MYSQL_PORT') { @database.port }
      end
      
      during(:startup) { command 'mysqld_safe --bind-address=0.0.0.0 --port=$MYSQL_PORT' }

      during :install_libraries do
        container_type :app
        command 'apt-get install -y mysql-client'
      end
    end
  end
end