Exemplo n.º 1
0
def download_artifact(queue, task_id, artifact_name):
    logger.info('Download {} from {}'.format(artifact_name, task_id))

    # Build artifact url
    try:
        url = queue.buildSignedUrl('getLatestArtifact', task_id, artifact_name)
    except taskcluster.exceptions.TaskclusterAuthFailure:
        url = queue.buildUrl('getLatestArtifact', task_id, artifact_name)

    # Download the artifact in a temporary file
    _, path = tempfile.mkstemp(suffix='-taskboot.tar')
    retry(lambda: download_progress(url, path))

    return path
Exemplo n.º 2
0
def build_compose(target, args):
    """
    Read a compose file and build each image described as buildable
    """
    assert args.build_retries > 0, "Build retries must be a positive integer"
    build_tool = Img(cache=args.cache)

    # Check the dockerfile is available in target
    composefile = target.check_path(args.composefile)

    # Check compose file has version >= 3.0
    compose = yaml.load(open(composefile))
    version = compose.get("version")
    assert version is not None, "Missing version in {}".format(composefile)
    assert compose["version"].startswith(
        "3."), "Only docker compose version 3 is supported"

    # Check output folder
    output = None
    if args.write:
        output = os.path.realpath(args.write)
        os.makedirs(output, exist_ok=True)
        logger.info("Will write images in {}".format(output))

    # Load services
    services = compose.get("services")
    assert isinstance(services, dict), "Missing services"

    # All paths are relative to the dockerfile folder
    root = os.path.dirname(composefile)

    for name, service in services.items():
        build = service.get("build")
        if build is None:
            logger.info(
                "Skipping service {}, no build declaration".format(name))
            continue

        if args.service and name not in args.service:
            msg = "Skipping service {}, building only {}".format(
                name, args.service)
            logger.info(msg)
            continue

        # Build the image
        logger.info("Building image for service {}".format(name))
        context = os.path.realpath(
            os.path.join(root, build.get("context", ".")))
        dockerfile = os.path.realpath(
            os.path.join(context, build.get("dockerfile", "Dockerfile")))

        # We need to replace the FROM statements by their local versions
        # to avoid using the remote repository first
        patch_dockerfile(dockerfile, build_tool.list_images())

        docker_image = service.get("image", name)
        tags = gen_docker_images(docker_image, args.tag, args.registry)

        retry(
            lambda: build_tool.build(context, dockerfile, tags, args.build_arg
                                     ),
            wait_between_retries=1,
            retries=args.build_retries,
        )

        # Write the produced image
        if output:
            build_tool.save(tags, os.path.join(output, "{}.tar".format(name)))

    logger.info("Compose file fully processed.")
Exemplo n.º 3
0
def build_compose(target, args):
    '''
    Read a compose file and build each image described as buildable
    '''
    assert args.build_retries > 0, 'Build retries must be a positive integer'
    docker = Docker(cache=args.cache)

    # Check the dockerfile is available in target
    composefile = target.check_path(args.composefile)

    # Check compose file has version >= 3.0
    compose = yaml.load(open(composefile))
    version = compose.get('version')
    assert version is not None, 'Missing version in {}'.format(composefile)
    assert compose['version'].startswith('3.'), \
        'Only docker compose version 3 is supported'

    # Check output folder
    output = None
    if args.write:
        output = os.path.realpath(args.write)
        os.makedirs(output, exist_ok=True)
        logger.info('Will write images in {}'.format(output))

    # Load services
    services = compose.get('services')
    assert isinstance(services, dict), 'Missing services'

    # All paths are relative to the dockerfile folder
    root = os.path.dirname(composefile)

    for name, service in services.items():
        build = service.get('build')
        if build is None:
            logger.info(
                'Skipping service {}, no build declaration'.format(name))
            continue

        if args.service and name not in args.service:
            msg = 'Skipping service {}, building only {}'.format(
                name, args.service)
            logger.info(msg)
            continue

        # Build the image
        logger.info('Building image for service {}'.format(name))
        context = os.path.realpath(
            os.path.join(root, build.get('context', '.')))
        dockerfile = os.path.realpath(
            os.path.join(context, build.get('dockerfile', 'Dockerfile')))

        # We need to replace the FROM statements by their local versions
        # to avoid using the remote repository first
        patch_dockerfile(dockerfile, docker.list_images())

        docker_image = service.get('image', name)
        tags = gen_docker_images(docker_image, args.tag, args.registry)

        retry(
            lambda: docker.build(context, dockerfile, tags, args.build_arg),
            wait_between_retries=1,
            retries=args.build_retries,
        )

        # Write the produced image
        if output:
            for tag in tags:
                docker.save(tag, os.path.join(output, '{}.tar'.format(name)))

    logger.info('Compose file fully processed.')