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:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/docker/compose/rake_tasks.rb', line 62

def initialize
  self.dir = Rake.application.original_dir
  self.project_name = nil
  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, project_name: project_name, 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.”



47
48
49
# File 'lib/docker/compose/rake_tasks.rb', line 47

def extra_host_env
  @extra_host_env
end

#fileString

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

Returns:

  • (String)


26
27
28
# File 'lib/docker/compose/rake_tasks.rb', line 26

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.



39
40
41
# File 'lib/docker/compose/rake_tasks.rb', line 39

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.



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

def host_services
  @host_services
end

#project_nameString

Set the project name. Default is not to pass a custom name.

Returns:

  • (String)


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

def project_name
  @project_name
end

#rake_namespaceObject

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



57
58
59
# File 'lib/docker/compose/rake_tasks.rb', line 57

def rake_namespace
  @rake_namespace
end