Class: Kaiser::Databases::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/kaiser/databases/postgres.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Postgres

Returns a new instance of Postgres.



6
7
8
# File 'lib/kaiser/databases/postgres.rb', line 6

def initialize(options)
  @options = options
end

Instance Method Details

#image_nameObject



40
41
42
43
# File 'lib/kaiser/databases/postgres.rb', line 40

def image_name
  version = @options[:version] || 'alpine'
  "postgres:#{version}"
end

#options_hashObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kaiser/databases/postgres.rb', line 10

def options_hash
  testpass = @options[:root_password] || 'testpassword'
  parameters = @options[:parameters] || ''
  port = @options[:port] || 3306
  platform = @options[:platform] || 'linux/amd64'

  {
    port: port,
    data_dir: '/var/lib/postgresql/data',
    params: "-e POSTGRES_PASSWORD=#{testpass}",
    commands: parameters,
    platform: platform,
    waitscript_params: "
      -e PG_HOST=<%= db_container_name %>
      -e PG_USER=postgres
      -e PGPASSWORD=#{testpass}
      -e PG_DATABASE=postgres",
    waitscript: <<~SCRIPT
      #!/bin/sh

      RETRIES=5

      until psql -h $PG_HOST -U $PG_USER -d $PG_DATABASE -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do
       echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..."
       sleep 1
      done
    SCRIPT
  }
end