Class: StellarCoreCommander::DockerProcess
- Inherits:
-
Process
- Object
- Process
- StellarCoreCommander::DockerProcess
show all
- Includes:
- Contracts
- Defined in:
- lib/stellar_core_commander/docker_process.rb
Instance Attribute Summary
Attributes inherited from Process
#base_port, #identity, #server, #working_dir
Instance Method Summary
collapse
Methods inherited from Process
#close_ledger, #close_timeout, #http_port, #initialize, #latest_ledger, #peer_port, #rm_working_dir, #sequence_for, #submit_transaction, #transaction_result, #wait_for_ready
Instance Method Details
#cleanup ⇒ Object
58
59
60
61
62
63
|
# File 'lib/stellar_core_commander/docker_process.rb', line 58
def cleanup
database.disconnect
shutdown
shutdown_state_container
rm_working_dir
end
|
#container_name ⇒ Object
98
99
100
|
# File 'lib/stellar_core_commander/docker_process.rb', line 98
def container_name
"c#{base_port}"
end
|
#database ⇒ Object
73
74
75
|
# File 'lib/stellar_core_commander/docker_process.rb', line 73
def database
@database ||= Sequel.postgres(database_name, host: docker_host, port: postgres_port, user: database_user, password: database_password)
end
|
#database_name ⇒ Object
78
79
80
|
# File 'lib/stellar_core_commander/docker_process.rb', line 78
def database_name
"stellar"
end
|
#database_password ⇒ Object
88
89
90
|
# File 'lib/stellar_core_commander/docker_process.rb', line 88
def database_password
@database_password ||= SecureRandom.hex
end
|
#database_user ⇒ Object
83
84
85
|
# File 'lib/stellar_core_commander/docker_process.rb', line 83
def database_user
"postgres"
end
|
#docker_host ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'lib/stellar_core_commander/docker_process.rb', line 108
def docker_host
docker_uri = URI.parse(ENV['DOCKER_HOST'])
if docker_uri.scheme == "tcp"
docker_uri.host
else
"127.0.0.1"
end
end
|
#dump_database ⇒ Object
66
67
68
69
70
|
# File 'lib/stellar_core_commander/docker_process.rb', line 66
def dump_database
Dir.chdir(working_dir) do
`docker exec #{state_container_name} pg_dump -U #{database_user} --clean --no-owner #{database_name}`
end
end
|
#http_host ⇒ Object
118
119
120
|
# File 'lib/stellar_core_commander/docker_process.rb', line 118
def http_host
docker_host
end
|
#launch_state_container ⇒ Object
15
16
17
18
|
# File 'lib/stellar_core_commander/docker_process.rb', line 15
def launch_state_container
run_cmd "docker", %W(run --name #{state_container_name} -p #{postgres_port}:5432 --env-file stellar-core.env -d stellar/stellar-core-state)
raise "Could not create state container" unless $?.success?
end
|
#postgres_port ⇒ Object
93
94
95
|
# File 'lib/stellar_core_commander/docker_process.rb', line 93
def postgres_port
base_port + 2
end
|
#required_ports ⇒ Object
10
11
12
|
# File 'lib/stellar_core_commander/docker_process.rb', line 10
def required_ports
3
end
|
#run ⇒ Object
40
41
42
43
|
# File 'lib/stellar_core_commander/docker_process.rb', line 40
def run
raise "already running!" if running?
launch_stellar_core
end
|
#running? ⇒ Boolean
46
47
48
49
|
# File 'lib/stellar_core_commander/docker_process.rb', line 46
def running?
run_cmd "docker", %W(inspect #{container_name})
$?.success?
end
|
#setup ⇒ Object
34
35
36
37
|
# File 'lib/stellar_core_commander/docker_process.rb', line 34
def setup
write_config
launch_state_container
end
|
#shutdown ⇒ Object
52
53
54
55
|
# File 'lib/stellar_core_commander/docker_process.rb', line 52
def shutdown
return true unless running?
run_cmd "docker", %W(rm -f #{container_name})
end
|
#shutdown_state_container ⇒ Object
21
22
23
24
|
# File 'lib/stellar_core_commander/docker_process.rb', line 21
def shutdown_state_container
run_cmd "docker", %W(rm -f -v #{state_container_name})
raise "Could not drop db: #{database_name}" unless $?.success?
end
|
#state_container_name ⇒ Object
103
104
105
|
# File 'lib/stellar_core_commander/docker_process.rb', line 103
def state_container_name
"db#{container_name}"
end
|
#write_config ⇒ Object
27
28
29
30
31
|
# File 'lib/stellar_core_commander/docker_process.rb', line 27
def write_config
IO.write("#{working_dir}/.pgpass", "#{docker_host}:#{postgres_port}:*:#{database_user}:#{database_password}")
FileUtils.chmod(0600, "#{working_dir}/.pgpass")
IO.write("#{working_dir}/stellar-core.env", config)
end
|