Set docker-machine env from unpacked-info for run
@@ -135,33 +135,36 @@ def run(directory, unpacker=None, runs=None,
return ("Couldn't find reprounzip command -- is reprounzip installed?",
'critical')
+ env = {}
+
+ with open(os.path.join(directory, '.reprounzip'), 'rb') as fp:
+ docker_host = pickle.load(fp).get('docker_host')
+ if docker_host and docker_host['type']:
+ if docker_host['type'] == 'docker-machine':
+ env.update(docker_machine_env(docker_host['name']))
+ elif docker_host['type'] == 'custom':
+ env.update(docker_host['env'])
+ else:
+ raise ValueError("Unrecognized docker host type %r" %
+ docker_host['type'])
+
run_in_system_terminal(
[reprounzip, unpacker, 'run'] +
args +
[os.path.abspath(directory)] +
([','.join('%d' % r for r in runs)] if runs is not None else []),
+ env=env,
root=root)
return True
-def unpack(package, unpacker, directory, options=None):
- if options is None:
- options = {}
-
- reprounzip = find_command('reprounzip')
- if reprounzip is None:
- return ("Couldn't find reprounzip command -- is reprounzip installed?",
- 'critical')
-
- env = {}
-
- docker_machine = options.get('docker-machine', None)
- if docker_machine:
- cmd = ['docker-machine', 'env', docker_machine]
+def docker_machine_env(machine):
+ cmd = ['docker-machine', 'env', machine]
getconf = subprocess.Popen(cmd, stdout=subprocess.PIPE)
out, _ = getconf.communicate()
if getconf.returncode != 0:
raise subprocess.CalledProcessError(getconf.returncode, cmd)
+ env = {}
for line in out.splitlines():
line = line.strip()
if not line or line[0] == b'#':
@@ -174,6 +177,23 @@ def unpack(package, unpacker, directory, options=None):
raise ValueError("docker-machine env format not recognized")
value = line[sep + 2:-1]
env[key] = value
+ return env
+
+
+def unpack(package, unpacker, directory, options=None):
+ if options is None:
+ options = {}
+
+ reprounzip = find_command('reprounzip')
+ if reprounzip is None:
+ return ("Couldn't find reprounzip command -- is reprounzip installed?",
+ 'critical')
+
+ env = {}
+
+ docker_machine = options.get('docker-machine', None)
+ if docker_machine:
+ env.update(docker_machine_env(docker_machine))
cmd = ([reprounzip, unpacker, 'setup'] +
options.get('args', []) +
