|
|
@ -121,6 +121,75 @@ def get_docker_hostname(): # type: () -> str
|
|
|
|
return hostname
|
|
|
|
return hostname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
|
|
|
|
def get_podman_host_ip(): # type: () -> str
|
|
|
|
|
|
|
|
"""Return the IP of the Podman host."""
|
|
|
|
|
|
|
|
podman_host_ip = socket.gethostbyname(get_podman_hostname())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
display.info('Detected Podman host IP: %s' % podman_host_ip, verbosity=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return podman_host_ip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
|
|
|
|
def get_podman_default_hostname(): # type: () -> str
|
|
|
|
|
|
|
|
"""Return the default hostname of the Podman service.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--format was added in podman 3.3.0, this functionality depends on it's availability
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
stdout = raw_command(['podman', 'system', 'connection', 'list', '--format=json'], capture=True)[0]
|
|
|
|
|
|
|
|
except SubprocessError:
|
|
|
|
|
|
|
|
stdout = '[]'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections = json.loads(stdout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for connection in connections:
|
|
|
|
|
|
|
|
# A trailing indicates the default
|
|
|
|
|
|
|
|
if connection['Name'][-1] == '*':
|
|
|
|
|
|
|
|
hostname = connection['URI']
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
hostname = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return hostname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
|
|
|
|
def _get_podman_remote(): # type: () -> t.Optional[str]
|
|
|
|
|
|
|
|
# URL value resolution precedence:
|
|
|
|
|
|
|
|
# - command line value
|
|
|
|
|
|
|
|
# - environment variable CONTAINER_HOST
|
|
|
|
|
|
|
|
# - containers.conf
|
|
|
|
|
|
|
|
# - unix://run/podman/podman.sock
|
|
|
|
|
|
|
|
hostname = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
podman_host = os.environ.get('CONTAINER_HOST')
|
|
|
|
|
|
|
|
if not podman_host:
|
|
|
|
|
|
|
|
podman_host = get_podman_default_hostname()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if podman_host and podman_host.startswith('ssh://'):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
hostname = urllib.parse.urlparse(podman_host).hostname
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
display.warning('Could not parse podman URI "%s"' % podman_host)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
display.info('Detected Podman remote: %s' % hostname, verbosity=1)
|
|
|
|
|
|
|
|
return hostname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
|
|
|
|
def get_podman_hostname(): # type: () -> str
|
|
|
|
|
|
|
|
"""Return the hostname of the Podman service."""
|
|
|
|
|
|
|
|
hostname = _get_podman_remote()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not hostname:
|
|
|
|
|
|
|
|
hostname = 'localhost'
|
|
|
|
|
|
|
|
display.info('Assuming Podman is available on localhost.', verbosity=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return hostname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
@cache
|
|
|
|
def get_docker_container_id(): # type: () -> t.Optional[str]
|
|
|
|
def get_docker_container_id(): # type: () -> t.Optional[str]
|
|
|
|
"""Return the current container ID if running in a container, otherwise return None."""
|
|
|
|
"""Return the current container ID if running in a container, otherwise return None."""
|
|
|
@ -478,12 +547,14 @@ def docker_command(
|
|
|
|
): # type: (...) -> t.Tuple[t.Optional[str], t.Optional[str]]
|
|
|
|
): # type: (...) -> t.Tuple[t.Optional[str], t.Optional[str]]
|
|
|
|
"""Run the specified docker command."""
|
|
|
|
"""Run the specified docker command."""
|
|
|
|
env = docker_environment()
|
|
|
|
env = docker_environment()
|
|
|
|
command = require_docker().command
|
|
|
|
command = [require_docker().command]
|
|
|
|
return run_command(args, [command] + cmd, env=env, capture=capture, stdin=stdin, stdout=stdout, always=always, data=data)
|
|
|
|
if command[0] == 'podman' and _get_podman_remote():
|
|
|
|
|
|
|
|
command.append('--remote')
|
|
|
|
|
|
|
|
return run_command(args, command + cmd, env=env, capture=capture, stdin=stdin, stdout=stdout, always=always, data=data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def docker_environment(): # type: () -> t.Dict[str, str]
|
|
|
|
def docker_environment(): # type: () -> t.Dict[str, str]
|
|
|
|
"""Return a dictionary of docker related environment variables found in the current environment."""
|
|
|
|
"""Return a dictionary of docker related environment variables found in the current environment."""
|
|
|
|
env = common_environment()
|
|
|
|
env = common_environment()
|
|
|
|
env.update(dict((key, os.environ[key]) for key in os.environ if key.startswith('DOCKER_')))
|
|
|
|
env.update(dict((key, os.environ[key]) for key in os.environ if key.startswith('DOCKER_') or key.startswith('CONTAINER_')))
|
|
|
|
return env
|
|
|
|
return env
|
|
|
|