Class: Rumination::DockerCompose::Container

Inherits:
Struct
  • Object
show all
Includes:
Sh
Defined in:
lib/rumination/docker_compose/container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sh

#sh

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/rumination/docker_compose/container.rb', line 6

def name
  @name
end

Instance Method Details

#compose_project_nameObject



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_nameObject



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

Returns:

  • (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

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/rumination/docker_compose/container.rb', line 14

def up?
  exec "true"
  $? == 0
end