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() @target = [:target] @db_name = [:database_name] end |
Instance Method Details
#adapter_name ⇒ Object
71 72 73 |
# File 'lib/conjure/service/database/postgres.rb', line 71 def adapter_name "postgresql" end |
#base_image ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/conjure/service/database/postgres.rb', line 10 def base_image @base_image ||= @target.shell.prepare( label: "postgres", 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
67 68 69 |
# File 'lib/conjure/service/database/postgres.rb', line 67 def bin_path "/usr/lib/postgresql/9.2/bin" end |
#client_options ⇒ Object
63 64 65 |
# File 'lib/conjure/service/database/postgres.rb', line 63 def "-U root -h #{ip_address}" end |
#container ⇒ Object
39 40 41 |
# File 'lib/conjure/service/database/postgres.rb', line 39 def container @container ||= server_image.run end |
#export(file) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/conjure/service/database/postgres.rb', line 51 def export(file) File.open file, "w" do |f| f.write base_image.command("#{bin_path}/pg_dump #{} #{@db_name}") end Log.info "[export] #{File.size file} bytes exported to #{file}" end |
#import(file) ⇒ Object
58 59 60 61 |
# File 'lib/conjure/service/database/postgres.rb', line 58 def import(file) base_image.command "#{bin_path}/psql #{} -d #{@db_name} -f /files/#{File.basename file}", files: [file] Log.info "[import] #{File.size file} bytes imported from #{file}" end |
#ip_address ⇒ Object
47 48 49 |
# File 'lib/conjure/service/database/postgres.rb', line 47 def ip_address container.ip_address end |
#name ⇒ Object
43 44 45 |
# File 'lib/conjure/service/database/postgres.rb', line 43 def name @db_name end |
#run ⇒ Object
35 36 37 |
# File 'lib/conjure/service/database/postgres.rb', line 35 def run container end |
#server_image ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/conjure/service/database/postgres.rb', line 22 def server_image @server_image ||= base_image.prepare( label: "pgserver", 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 |