Class: Minke::Docker::DockerCompose
- Inherits:
-
Object
- Object
- Minke::Docker::DockerCompose
- Defined in:
- lib/minke/docker/docker_compose.rb
Instance Method Summary collapse
- #create_compose_network_file ⇒ Object
-
#down ⇒ Object
stop the containers in a stack and removes them as defined by the docker compose file.
- #execute_command(command) ⇒ Object
-
#initialize(compose_file, system_runner, project_name) ⇒ DockerCompose
constructor
A new instance of DockerCompose.
-
#logs ⇒ Object
stream the logs for the current running stack.
-
#public_address(container, private_port) ⇒ Object
return the local address and port of a containers private port.
-
#rm ⇒ Object
remove the containers started in a stack defined by the docker compose file.
-
#up ⇒ Object
start the containers in a stack defined by the docker compose file.
Constructor Details
#initialize(compose_file, system_runner, project_name) ⇒ DockerCompose
Returns a new instance of DockerCompose.
17 18 19 20 21 |
# File 'lib/minke/docker/docker_compose.rb', line 17 def initialize compose_file, system_runner, project_name @project_name = project_name @compose_file = compose_file @system_runner = system_runner end |
Instance Method Details
#create_compose_network_file ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/minke/docker/docker_compose.rb', line 65 def create_compose_network_file content = { 'version' => '2'.to_s, 'networks' => {'default' => { 'external' => { 'name' => ENV['DOCKER_NETWORK'] } } } } directory = @system_runner.mktmpdir temp_file = directory + '/docker-compose.yml' @system_runner.write_file temp_file, YAML.dump(content) directory end |
#down ⇒ Object
stop the containers in a stack and removes them as defined by the docker compose file
32 33 34 |
# File 'lib/minke/docker/docker_compose.rb', line 32 def down execute_command "down -v" end |
#execute_command(command) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/minke/docker/docker_compose.rb', line 54 def execute_command command unless ENV['DOCKER_NETWORK'].to_s.empty? directory = create_compose_network_file @system_runner.execute "docker-compose -f #{@compose_file} -f #{directory + '/docker-compose.yml'} -p #{@project_name} #{command}" @system_runner.remove_entry_secure directory else @system_runner.execute "docker-compose -f #{@compose_file} -p #{@project_name} #{command}" end end |
#logs ⇒ Object
stream the logs for the current running stack
44 45 46 |
# File 'lib/minke/docker/docker_compose.rb', line 44 def logs execute_command 'logs -f' end |
#public_address(container, private_port) ⇒ Object
return the local address and port of a containers private port
50 51 52 |
# File 'lib/minke/docker/docker_compose.rb', line 50 def public_address container, private_port @system_runner.execute_and_return "docker-compose -f #{@compose_file} port #{container} #{private_port}" end |
#rm ⇒ Object
remove the containers started in a stack defined by the docker compose file
38 39 40 |
# File 'lib/minke/docker/docker_compose.rb', line 38 def rm execute_command 'rm -v' unless ::Docker.info["Driver"] == "btrfs" end |
#up ⇒ Object
start the containers in a stack defined by the docker compose file
25 26 27 28 |
# File 'lib/minke/docker/docker_compose.rb', line 25 def up execute_command "up -d" sleep 2 end |