lib/minke/docker/docker_compose.rb in minke-1.5.9 vs lib/minke/docker/docker_compose.rb in minke-1.6.0
- old
+ new
@@ -19,18 +19,33 @@
end
##
# start the containers in a stack defined by the docker compose file
def up
- @system_runner.execute "docker-compose -f #{@compose_file} up -d"
+ 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'} up -d"
+ @system_runner.remove_entry_secure directory
+ else
+ @system_runner.execute "docker-compose -f #{@compose_file} up -d"
+ end
+
sleep 2
end
##
- # stop the containers in a stack defined by the docker compose file
- def stop
- @system_runner.execute "docker-compose -f #{@compose_file} stop"
+ # stop the containers in a stack and removes them as defined by the docker compose file
+ def down
+ 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'} down"
+ @system_runner.remove_entry_secure directory
+ else
+ @system_runner.execute "docker-compose -f #{@compose_file} down -d"
+ end
end
##
# remove the containers started in a stack defined by the docker compose file
def rm
@@ -45,9 +60,20 @@
##
# return the local address and port of a containers private port
def public_address container, private_port
@system_runner.execute_and_return "docker-compose -f #{@compose_file} port #{container} #{private_port}"
+ end
+
+ 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
end
end
end