Skip to content

Commit 0e8d058

Browse files
committed
(GH-819) Introduce tmpdir property
This commit introduces a new tmpdir property for the docker_compose resource that allows the module consumer to decide on the value of TMPDIR (The location that docker compose uses for temp files). With the new implementation: If the tmpdir property is not set, the docker compose will use it's default value of /tmp. If the tmpdir property is set, the docker compose will use the value of the tmpdir property. It is the responsibility of the consumer to ensure that the directory passed to the tmpdir is available and writable by the user that is running puppet.
1 parent d2c44c5 commit 0e8d058

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

Diff for: lib/puppet/provider/docker_compose/ruby.rb

+14-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
end
1515

1616
has_command(:docker_compose, command(:dockercompose)) do
17-
Dir.mkdir('/tmp_docker') unless Dir.exist?('/tmp_docker')
18-
ENV.store('TMPDIR', '/tmp_docker')
17+
environment(HOME: '/root')
1918
end
2019

2120
def exists?
@@ -76,33 +75,40 @@ def get_image(service_name, compose_services)
7675
def create
7776
Puppet.info("Running compose project #{name}")
7877
args = [compose_files, '-p', name, 'up', '-d', '--remove-orphans'].insert(3, resource[:options]).insert(5, resource[:up_args]).compact
79-
dockercompose(args)
78+
exec_dockercompose(args)
8079
return unless resource[:scale]
8180
instructions = resource[:scale].map { |k, v| "#{k}=#{v}" }
8281
Puppet.info("Scaling compose project #{name}: #{instructions.join(' ')}")
8382
args = [compose_files, '-p', name, 'scale'].insert(3, resource[:options]).compact + instructions
84-
dockercompose(args)
83+
exec_dockercompose(args)
8584
end
8685

8786
def destroy
8887
Puppet.info("Removing all containers for compose project #{name}")
8988
kill_args = [compose_files, '-p', name, 'kill'].insert(3, resource[:options]).compact
90-
dockercompose(kill_args)
89+
exec_dockercompose(kill_args)
9190
rm_args = [compose_files, '-p', name, 'rm', '--force', '-v'].insert(3, resource[:options]).compact
92-
dockercompose(rm_args)
91+
exec_dockercompose(rm_args)
9392
end
9493

9594
def restart
9695
return unless exists?
9796
Puppet.info("Rebuilding and Restarting all containers for compose project #{name}")
9897
kill_args = [compose_files, '-p', name, 'kill'].insert(3, resource[:options]).compact
99-
dockercompose(kill_args)
98+
exec_dockercompose(kill_args)
10099
build_args = [compose_files, '-p', name, 'build'].insert(3, resource[:options]).compact
101-
dockercompose(build_args)
100+
exec_dockercompose(build_args)
102101
create
103102
end
104103

105104
def compose_files
106105
resource[:compose_files].map { |x| ['-f', x] }.flatten
107106
end
107+
108+
def exec_dockercompose(args)
109+
ENV.store('TMPDIR', resource[:tmpdir]) unless tmpdir.nil?
110+
dockercompose(args)
111+
end
112+
113+
private :exec_dockercompose
108114
end

Diff for: lib/puppet/type/docker_compose.rb

+15
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,19 @@ def refresh
4747
isnamevar
4848
desc 'The name of the project'
4949
end
50+
51+
newproperty(:tmpdir) do
52+
desc "Override the temporary directory used by docker-compose.
53+
54+
This property is useful when the /tmp directory has been mounted
55+
with the noexec option. Or is otherwise being prevented It allows the module consumer to redirect
56+
docker-composes temporary files to a known directory.
57+
58+
The directory passed to this property must exist and be accessible
59+
by the user that is executing the puppet agent.
60+
"
61+
validate do |value|
62+
raise _('tmpdir should be a String') unless value.is_a? String
63+
end
64+
end
5065
end

0 commit comments

Comments
 (0)