Class: Docker::Compose::RakeTasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/docker/compose/rake_tasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ RakeTasks

Construct Rake wrapper tasks for docker-compose. If a block is given, yield self to the block before defining any tasks so their behavior can be configured by calling #server_env=, #file= and so forth.

Yields:

  • (_self)

Yield Parameters:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/docker/compose/rake_tasks.rb', line 58

def initialize
  self.dir = Rake.application.original_dir
  self.file = 'docker-compose.yml'
  self.host_env = {}
  self.extra_host_env = {}
  self.rake_namespace = 'docker:compose'
  yield self if block_given?

  @shell = Backticks::Runner.new
  @session = Docker::Compose::Session.new(@shell, dir: dir, file: file)
  @net_info = Docker::Compose::NetInfo.new
  @shell_printer = Docker::Compose::ShellPrinter.new

  @shell.interactive = true

  define
end

Instance Attribute Details

#dirString

Set the directory in which docker-compose commands will be run. Default is the directory in which Rakefile is located.

Returns:

  • (String)


18
19
20
# File 'lib/docker/compose/rake_tasks.rb', line 18

def dir
  @dir
end

#extra_host_envObject

Extra environment variables to set before invoking host processes. These are set _in addition_ to server_env, but are not substituted in any way and must not contain any service information.

Extra host env should be disjoint from host_env; if there is overlap between the two, then extra_host_env will “win.”



43
44
45
# File 'lib/docker/compose/rake_tasks.rb', line 43

def extra_host_env
  @extra_host_env
end

#fileString

Set the name of the docker-compose file. Default is`docker-compose.yml`.

Returns:

  • (String)


22
23
24
# File 'lib/docker/compose/rake_tasks.rb', line 22

def file
  @file
end

#host_envObject

Provide a mapping of environment variables that should be set in host processes, e.g. when running docker:compose:env or docker:compose:host.

The values of the environment variables can refer to names of services and ports defined in the docker-compose file, and this gem will substitute the actual IP and port that the containers are reachable on. This allows commands invoked via “docker:compose:host” to reach services running inside containers.



35
36
37
# File 'lib/docker/compose/rake_tasks.rb', line 35

def host_env
  @host_env
end

#host_servicesObject

Services to bring up with ‘docker-compose up` before running any hosted command. This is useful if your `docker-compose.yml` contains a service definition for the app you will be hosting; if you host the app, you want to specify all of the other services, but not the app itself, since that will run on the host.



50
51
52
# File 'lib/docker/compose/rake_tasks.rb', line 50

def host_services
  @host_services
end

#rake_namespaceObject

Namespace to define the rake tasks under. Defaults to “docker:compose’.



53
54
55
# File 'lib/docker/compose/rake_tasks.rb', line 53

def rake_namespace
  @rake_namespace
end