Class: Conjure::Service::Database::Postgres
- Inherits:
-
Object
- Object
- Conjure::Service::Database::Postgres
- Defined in:
- lib/conjure/service/database/postgres.rb
Instance Method Summary collapse
- #adapter_name ⇒ Object
- #base_image ⇒ Object
- #bin_path ⇒ Object
- #client_options ⇒ Object
- #container ⇒ Object
- #export(file) ⇒ Object
- #import(file) ⇒ Object
-
#initialize(options) ⇒ Postgres
constructor
A new instance of Postgres.
- #ip_address ⇒ Object
- #name ⇒ Object
- #run ⇒ Object
- #server_image ⇒ Object
Constructor Details
#initialize(options) ⇒ Postgres
Returns a new instance of Postgres.
5 6 7 8 |
# File 'lib/conjure/service/database/postgres.rb', line 5 def initialize() @host = [:docker_host] @db_name = [:database_name] end |
Instance Method Details
#adapter_name ⇒ Object
73 74 75 |
# File 'lib/conjure/service/database/postgres.rb', line 73 def adapter_name "postgresql" end |
#base_image ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/conjure/service/database/postgres.rb', line 10 def base_image @base_image ||= @host.images.create( label: "postgres", base_image: "ubuntu", setup_commands: [ "apt-get install -y python-software-properties software-properties-common", "add-apt-repository -y ppa:pitti/postgresql", "apt-get update", "apt-get install -y postgresql-9.2 postgresql-client-9.2 postgresql-contrib-9.2", ], ) end |
#bin_path ⇒ Object
69 70 71 |
# File 'lib/conjure/service/database/postgres.rb', line 69 def bin_path "/usr/lib/postgresql/9.2/bin" end |
#client_options ⇒ Object
65 66 67 |
# File 'lib/conjure/service/database/postgres.rb', line 65 def "-U root -h #{ip_address}" end |
#container ⇒ Object
41 42 43 |
# File 'lib/conjure/service/database/postgres.rb', line 41 def container @container ||= server_image.run end |
#export(file) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/conjure/service/database/postgres.rb', line 53 def export(file) File.open file, "w" do |f| f.write base_image.command("#{bin_path}/pg_dump #{client_options} #{@db_name}") end Conjure.log "[export] #{File.size file} bytes exported to #{file}" end |
#import(file) ⇒ Object
60 61 62 63 |
# File 'lib/conjure/service/database/postgres.rb', line 60 def import(file) base_image.command "#{bin_path}/psql #{client_options} -d #{@db_name} -f /files/#{File.basename file}", files: [file] Conjure.log "[import] #{File.size file} bytes imported from #{file}" end |
#ip_address ⇒ Object
49 50 51 |
# File 'lib/conjure/service/database/postgres.rb', line 49 def ip_address container.ip_address end |
#name ⇒ Object
45 46 47 |
# File 'lib/conjure/service/database/postgres.rb', line 45 def name @db_name end |
#run ⇒ Object
37 38 39 |
# File 'lib/conjure/service/database/postgres.rb', line 37 def run container end |
#server_image ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/conjure/service/database/postgres.rb', line 23 def server_image @server_image ||= @host.images.create( label: "pgserver", base_image: base_image, setup_commands: [ "service postgresql start; su postgres -c 'createuser -d -r -s root; createdb -O root root'; service postgresql stop", "echo 'host all all 0.0.0.0/0 trust' >>/etc/postgresql/9.2/main/pg_hba.conf", "echo \"listen_addresses='*'\" >>/etc/postgresql/9.2/main/postgresql.conf", ], daemon_command: "su postgres -c '#{bin_path}/postgres -c config_file=/etc/postgresql/9.2/main/postgresql.conf'", volumes: ["/var/lib/postgresql/9.2/main"], ) end |