class Conjure::Postgres
Public Class Methods
new(container_host)
click to toggle source
# File lib/conjure/postgres.rb, line 6 def initialize(container_host) @container_host = container_host @name = "conjure_db_#{SecureRandom.hex 8}" @password = new_password end
Public Instance Methods
container_link()
click to toggle source
# File lib/conjure/postgres.rb, line 27 def container_link {container_name => container_name} end
install()
click to toggle source
# File lib/conjure/postgres.rb, line 12 def install server_template.start(@container_host, "/sbin/my_init", start_options) end
pending_files()
click to toggle source
# File lib/conjure/postgres.rb, line 31 def pending_files [] end
rails_config()
click to toggle source
# File lib/conjure/postgres.rb, line 16 def rails_config { "adapter" => "postgresql", "database" => @name, "host" => container_name, "username" => "db", "password" => @password, "template" => "template0", } end
Private Instance Methods
container_name()
click to toggle source
# File lib/conjure/postgres.rb, line 44 def container_name "postgres" end
new_password()
click to toggle source
# File lib/conjure/postgres.rb, line 63 def new_password SecureRandom.urlsafe_base64 20 end
server_template()
click to toggle source
# File lib/conjure/postgres.rb, line 48 def server_template file = Docker::Template.new("atbaker/sd-postgres") file.run "useradd db" file.run "/sbin/my_init -- /sbin/setuser postgres sh -c \"sleep 1; psql -h localhost -c 'CREATE USER db CREATEDB'\"" file.run "/sbin/my_init -- /sbin/setuser db sh -c \"sleep 1; createdb db\"" file.run "echo 'local all all ident' >/usr/local/pgsql/data/pg_hba.conf" file.run "echo 'host all all 0.0.0.0/0 md5' >>/usr/local/pgsql/data/pg_hba.conf" file.run "echo 'host all all ::1/128 md5' >>/usr/local/pgsql/data/pg_hba.conf" file.run "echo \"ALTER USER db PASSWORD '#{@password}'\" >/tmp/setpass" file.run "/sbin/my_init -- /sbin/setuser postgres sh -c \"sleep 1; psql -f /tmp/setpass\"" file.run "rm /tmp/setpass" file.run "/sbin/my_init -- /sbin/setuser db sh -c \"sleep 1; /usr/bin/createdb #{@name}\"" file end
start_options()
click to toggle source
# File lib/conjure/postgres.rb, line 37 def start_options { :name => container_name, :volumes => {"postgres_data" => "/var/lib/postgresql/9.3/main"} } end