Adapt to new dockercfg file location and structure

This commit is contained in:
Olaf Kilian 2015-10-28 10:04:55 +01:00 committed by Matt Clay
parent d330f72213
commit 348cab4511

View file

@ -58,7 +58,7 @@ options:
description: description:
- Use a custom path for the .dockercfg file - Use a custom path for the .dockercfg file
required: false required: false
default: ~/.dockercfg default: ~/.docker/config.json
docker_url: docker_url:
descriptions: descriptions:
- Refers to the protocol+hostname+port where the Docker server is hosted - Refers to the protocol+hostname+port where the Docker server is hosted
@ -176,6 +176,9 @@ class DockerLoginManager:
# Create dockercfg file if it does not exist. # Create dockercfg file if it does not exist.
if not os.path.exists(self.dockercfg_path): if not os.path.exists(self.dockercfg_path):
dockercfg_path_dir = os.path.dirname(self.dockercfg_path)
if not os.path.exists(dockercfg_path_dir):
os.makedirs(dockercfg_path_dir)
open(self.dockercfg_path, "w") open(self.dockercfg_path, "w")
self.log.append("Created new Docker config file at %s" % self.dockercfg_path) self.log.append("Created new Docker config file at %s" % self.dockercfg_path)
else: else:
@ -186,9 +189,11 @@ class DockerLoginManager:
docker_config = json.load(open(self.dockercfg_path, "r")) docker_config = json.load(open(self.dockercfg_path, "r"))
except ValueError: except ValueError:
docker_config = dict() docker_config = dict()
if not docker_config.has_key(self.registry): if not docker_config.has_key("auths"):
docker_config[self.registry] = dict() docker_config["auths"] = dict()
docker_config[self.registry] = dict( if not docker_config["auths"].has_key(self.registry):
docker_config["auths"][self.registry] = dict()
docker_config["auths"][self.registry] = dict(
auth = base64.b64encode(self.username + b':' + self.password), auth = base64.b64encode(self.username + b':' + self.password),
email = self.email email = self.email
) )
@ -220,7 +225,7 @@ def main():
password = dict(required=True), password = dict(required=True),
email = dict(required=False, default=None), email = dict(required=False, default=None),
reauth = dict(required=False, default=False, type='bool'), reauth = dict(required=False, default=False, type='bool'),
dockercfg_path = dict(required=False, default='~/.dockercfg'), dockercfg_path = dict(required=False, default='~/.docker/config.json'),
docker_url = dict(default='unix://var/run/docker.sock'), docker_url = dict(default='unix://var/run/docker.sock'),
timeout = dict(default=10, type='int') timeout = dict(default=10, type='int')
), ),