Created
October 30, 2017 13:26
-
-
Save iaintshine/81093dd39d64355a1eea9ce27f1f2a27 to your computer and use it in GitHub Desktop.
Use docker-compose in Ruby tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Docker::Compose | |
class Session | |
def wait(timeout = 10) | |
Timeout.timeout(timeout) do | |
loop do | |
containers = ps | |
return if containers | |
.map { |container| running?(container.id) } | |
.all? | |
end | |
end | |
end | |
def running?(container_id) | |
cmd = @shell.run('docker', 'inspect', container_id, format: "{{.State.Running}}").join | |
status, out, err = cmd.status, cmd.captured_output, cmd.captured_error | |
unless status.success? | |
raise Error.new("docker inspect #{container_id} -f {{.State.Running}}", status, out+err) | |
end | |
lines = out.split(/[\r\n]+/) | |
return false if lines.empty? | |
lines.first == "true" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem.add_development_dependency('docker-compose', '~> 1.1') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compose = Docker::Compose.new | |
compose.up(detached: true) | |
compose.wait | |
at_exit { compose.down } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment