Class: Rumination::DockerCompose::Container
- Inherits:
-
Struct
- Object
- Struct
- Rumination::DockerCompose::Container
- Includes:
- Sh
- Defined in:
- lib/rumination/docker_compose/container.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #compose_project_name ⇒ Object
- #cp_to_container(local_path, container_path, *args) ⇒ Object
- #exec(command, *args) ⇒ Object
- #full_name ⇒ Object
- #has_file?(path) ⇒ Boolean
- #restart(*args) ⇒ Object
- #run(command, *args) ⇒ Object
- #up? ⇒ Boolean
Methods included from Sh
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
6 7 8 |
# File 'lib/rumination/docker_compose/container.rb', line 6 def name @name end |
Instance Method Details
#compose_project_name ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/rumination/docker_compose/container.rb', line 44 def compose_project_name env = if File.exists?(".env") Dotenv::Parser.call(File.read(".env")) else {} end env["COMPOSE_PROJECT_NAME"] || File.basename(Dir.pwd) end |
#cp_to_container(local_path, container_path, *args) ⇒ Object
34 35 36 37 38 |
# File 'lib/rumination/docker_compose/container.rb', line 34 def cp_to_container local_path, container_path, *args args << local_path args << "#{full_name}:#{container_path}" sh "docker cp", *args end |
#exec(command, *args) ⇒ Object
19 20 21 22 |
# File 'lib/rumination/docker_compose/container.rb', line 19 def exec command, *args sh "docker-compose exec", name, command, *args self end |
#full_name ⇒ Object
40 41 42 |
# File 'lib/rumination/docker_compose/container.rb', line 40 def full_name "#{compose_project_name}_#{name}_1" end |
#has_file?(path) ⇒ Boolean
9 10 11 12 |
# File 'lib/rumination/docker_compose/container.rb', line 9 def has_file?(path) run "test -f #{path}" $? == 0 end |
#restart(*args) ⇒ Object
29 30 31 32 |
# File 'lib/rumination/docker_compose/container.rb', line 29 def restart *args sh "docker-compose restart", name, *args self end |
#run(command, *args) ⇒ Object
24 25 26 27 |
# File 'lib/rumination/docker_compose/container.rb', line 24 def run command, *args sh "docker-compose run --rm", name, command, *args self end |
#up? ⇒ Boolean
14 15 16 17 |
# File 'lib/rumination/docker_compose/container.rb', line 14 def up? exec "true" $? == 0 end |