Esempio n. 1
0
    def wrapper(*args, **kwargs):  # pragma: no cover
        from dallinger.docker.tools import build_image
        from dallinger.command_line.docker import push
        import docker

        config = get_config()
        config.load()
        image_name = config.get("docker_image_name", None)
        if image_name:
            client = docker.from_env()
            try:
                check_output(["docker", "manifest", "inspect", image_name])
                print(f"Image {image_name} found on remote registry")
                return f(*args, **kwargs)
            except CalledProcessError:
                # The image is not on the registry. Check if it's available locally
                # and push it if it is. If images.get succeeds it means the image is available locally
                print(
                    f"Image {image_name} not found on remote registry. Trying to push"
                )
                raw_result = client.images.push(image_name)
                # This is brittle, but it's an edge case not worth more effort
                if not json.loads(raw_result.split("\r\n")[-2]).get("error"):
                    print(f"Image {image_name} pushed to remote registry")
                    return f(*args, **kwargs)
                # The image is not available, neither locally nor on the remote registry
                print(
                    f"Could not find image {image_name} specified in experiment config as `docker_image_name`"
                )
                raise click.Abort
        _, tmp_dir = setup_experiment(Output().log,
                                      exp_config=config.as_dict(),
                                      local_checks=False)
        build_image(tmp_dir,
                    config.get("docker_image_base_name"),
                    out=Output())

        pushed_image = push.callback(use_existing=True)
        add_image_name(LOCAL_CONFIG, pushed_image)
        return f(*args, **kwargs)
Esempio n. 2
0
 def _result(self, cmd):
     output = check_output(cmd)
     try:
         return output.decode(self.sys_encoding)
     except AttributeError:
         return output
Esempio n. 3
0
def container_log_in():
    """Ensure that the user is logged in to Heroku container registry."""
    check_output(["heroku", "container:login"])
Esempio n. 4
0
def log_in():
    """Ensure that the user is logged in to Heroku."""
    try:
        check_output(["heroku", "auth:whoami"])
    except Exception:
        raise Exception("You are not logged into Heroku.")
Esempio n. 5
0
def auth_token():
    """A Heroku authenication token."""
    return check_output(["heroku", "auth:token"]).rstrip().decode("utf8")
Esempio n. 6
0
 def _result(self, cmd):
     return check_output(cmd).decode(self.sys_encoding)