Esempio n. 1
0
def srcrpm(image, srcrpm, target_directory, additional_docker_options,
           verify_signature, bash_on_failure, sign_with, always_pull,
           target_ownership):
    uid, gid = parse_ownership(target_ownership)

    _logger.info("Now building %(srcrpm)s on image %(image)s", locals())
    if not os.path.exists(target_directory):
        os.mkdir(target_directory)

    dockerexec = which("docker")
    dockerscripts = getpath("drb/dockerscripts")
    srpms_temp = tempfile.mkdtemp("SRPMS")
    shutil.copy(srcrpm, srpms_temp)
    internal_docker_options = set()
    srcrpm_basename = os.path.basename(srcrpm)

    rpmbuild_options = "" if verify_signature else "--nosignature"

    bashonfail = ""
    spawn_func = sp
    if bash_on_failure:
        internal_docker_options.add("-i")
        internal_docker_options.add("-t")
        bashonfail = "bashonfail"
        spawn_func = spawn_interactive

    internal_docker_options = " ".join(internal_docker_options)
    encoded_signature = provide_encoded_signature(sign_with)

    if always_pull:
        pull(dockerexec, image)

    serialized_options = serialize({
        "CALLING_UID": uid,
        "CALLING_GID": gid,
        "BASH_ON_FAIL": bashonfail,
        "RPMBUILD_OPTIONS": rpmbuild_options,
        "SRCRPM": srcrpm_basename,
        "GPG_PRIVATE_KEY": encoded_signature
    })

    try:
        additional_docker_options = internal_docker_options + " ".join(
            additional_docker_options)
        srpms_inner_dir = sp(
            "{dockerexec} run --rm {image} rpm --eval %{{_srcrpmdir}}",
            **locals()).strip()
        rpms_inner_dir = sp(
            "{dockerexec} run --rm {image} rpm --eval %{{_rpmdir}}",
            **locals()).strip()
        spawn_func(
            "{dockerexec} run {additional_docker_options} -v {dockerscripts}:/dockerscripts -v {srpms_temp}:{srpms_inner_dir} -v {target_directory}:{rpms_inner_dir}"
            " -w /dockerscripts {image} ./rpmbuild-srcrpm-in-docker.sh {serialized_options}",
            **locals())
    finally:
        shutil.rmtree(srpms_temp)
Esempio n. 2
0
def srcrpm(image, srcrpm, target_directory, additional_docker_options, verify_signature, bash_on_failure,
           sign_with, always_pull, target_ownership):
    uid, gid = parse_ownership(target_ownership)

    _logger.info("Now building %(srcrpm)s on image %(image)s", locals())
    if not os.path.exists(target_directory):
        os.mkdir(target_directory)

    dockerexec = which("docker")
    dockerscripts = getpath("drb/dockerscripts")
    srpms_temp = tempfile.mkdtemp("SRPMS")
    shutil.copy(srcrpm, srpms_temp)
    internal_docker_options = set()
    srcrpm_basename = os.path.basename(srcrpm)

    rpmbuild_options = "" if verify_signature else "--nosignature"

    bashonfail = ""
    spawn_func = sp
    if bash_on_failure:
        internal_docker_options.add("-i")
        internal_docker_options.add("-t")
        bashonfail = "bashonfail"
        spawn_func = spawn_interactive

    internal_docker_options = " ".join(internal_docker_options)
    encoded_signature = provide_encoded_signature(sign_with)

    if always_pull:
        pull(dockerexec, image)

    serialized_options = serialize({"CALLING_UID": uid, "CALLING_GID": gid, "BASH_ON_FAIL":bashonfail, "RPMBUILD_OPTIONS": rpmbuild_options, "SRCRPM": srcrpm_basename,
                                    "GPG_PRIVATE_KEY": encoded_signature})

    try:
        additional_docker_options = internal_docker_options + " ".join(additional_docker_options)
        srpms_inner_dir = sp("{dockerexec} run --rm {image} rpm --eval %{{_srcrpmdir}}", **locals()).strip()
        rpms_inner_dir = sp("{dockerexec} run --rm {image} rpm --eval %{{_rpmdir}}", **locals()).strip()
        spawn_func("{dockerexec} run {additional_docker_options} -v {dockerscripts}:/dockerscripts -v {srpms_temp}:{srpms_inner_dir} -v {target_directory}:{rpms_inner_dir}"
           " -w /dockerscripts {image} ./rpmbuild-srcrpm-in-docker.sh {serialized_options}", **locals())
    finally:
        shutil.rmtree(srpms_temp)
Esempio n. 3
0
def dir(image, source_directory, target_directory, additional_docker_options, download_sources,
        bash_on_failure, sign_with, always_pull, target_ownership):
    # TODO: let spectemplate and/or spec be optional parameters
    # TODO: let the user choose $-delimited templates
    uid, gid = parse_ownership(target_ownership)

    deletespec = False
    spectemplates = [os.path.join(source_directory, fn) for fn in glob.glob1(source_directory, "*.spectemplate")]
    specfiles = [os.path.join(source_directory, fn) for fn in glob.glob1(source_directory, "*.spec")]
    if len(spectemplates) > 1:
        raise ValueError("More than one spectemplate found in source directory")

    if not os.path.exists(target_directory):
        os.mkdir(target_directory)

    if spectemplates:
        if specfiles:
            raise ValueError("Found both .spec and .spectemplate in source directory.")
        spectemplate = spectemplates[0]
        template = DoubleDelimiterTemplate(codecs.open(spectemplate, "rb", "utf-8").read())
        with_substitutions = template.substitute(os.environ)
        finalspec = os.path.splitext(spectemplate)[0] + ".spec"
        with codecs.open(finalspec, "wb", "utf-8") as f:
            f.write(with_substitutions)
        specfiles.append(finalspec)
        deletespec = True

    if not specfiles or len(specfiles) > 1:
        raise ValueError("No specfiles or more than one specfile in source directory")

    specfile = specfiles[0]

    if download_sources:
        downloadsources(source_directory, specfile)

    _logger.info("Now building project from %s on image %s", source_directory, image)
    dockerexec = which("docker")

    bashonfail = "dontspawn"
    bashonfail_options = ""
    spawn_func = sp
    if bash_on_failure:
        bashonfail = "bashonfail"
        bashonfail_options = "-i -t"
        spawn_func = spawn_interactive

    sign_with_encoded = provide_encoded_signature(sign_with)

    if always_pull:
        pull(dockerexec, image)

    serialized_options = serialize({"CALLING_UID": uid, "CALLING_GID": gid, "BASH_ON_FAIL":bashonfail, "GPG_PRIVATE_KEY": sign_with_encoded})

    try:
        additional_docker_options = " ".join(additional_docker_options)
        dockerscripts = getpath("drb/dockerscripts")
        rpms_inner_dir = sp("{dockerexec} run --rm {image} rpm --eval %{{_rpmdir}}", **locals()).strip()
        sources_inner_dir = sp("{dockerexec} run --rm {image} rpm --eval %{{_sourcedir}}", **locals()).strip()
        spawn_func("{dockerexec} run {additional_docker_options} -v {dockerscripts}:/dockerscripts -v {source_directory}:{sources_inner_dir} -v {target_directory}:{rpms_inner_dir} {bashonfail_options} -w /dockerscripts {image}  ./rpmbuild-dir-in-docker.sh {serialized_options}", **locals())
    finally:
        if deletespec:
            os.unlink(specfile)
Esempio n. 4
0
def dir(image, source_directory, target_directory, additional_docker_options,
        download_sources, bash_on_failure, sign_with, always_pull,
        target_ownership):
    # TODO: let spectemplate and/or spec be optional parameters
    # TODO: let the user choose $-delimited templates
    uid, gid = parse_ownership(target_ownership)

    deletespec = False
    spectemplates = [
        os.path.join(source_directory, fn)
        for fn in glob.glob1(source_directory, "*.spectemplate")
    ]
    specfiles = [
        os.path.join(source_directory, fn)
        for fn in glob.glob1(source_directory, "*.spec")
    ]
    if len(spectemplates) > 1:
        raise ValueError(
            "More than one spectemplate found in source directory")

    if not os.path.exists(target_directory):
        os.mkdir(target_directory)

    if spectemplates:
        if specfiles:
            raise ValueError(
                "Found both .spec and .spectemplate in source directory.")
        spectemplate = spectemplates[0]
        template = DoubleDelimiterTemplate(
            codecs.open(spectemplate, "rb", "utf-8").read())
        with_substitutions = template.substitute(os.environ)
        finalspec = os.path.splitext(spectemplate)[0] + ".spec"
        with codecs.open(finalspec, "wb", "utf-8") as f:
            f.write(with_substitutions)
        specfiles.append(finalspec)
        deletespec = True

    if not specfiles or len(specfiles) > 1:
        raise ValueError(
            "No specfiles or more than one specfile in source directory")

    specfile = specfiles[0]

    if download_sources:
        downloadsources(source_directory, specfile)

    _logger.info("Now building project from %s on image %s", source_directory,
                 image)
    dockerexec = which("docker")

    bashonfail = "dontspawn"
    bashonfail_options = ""
    spawn_func = sp
    if bash_on_failure:
        bashonfail = "bashonfail"
        bashonfail_options = "-i -t"
        spawn_func = spawn_interactive

    sign_with_encoded = provide_encoded_signature(sign_with)

    if always_pull:
        pull(dockerexec, image)

    serialized_options = serialize({
        "CALLING_UID": uid,
        "CALLING_GID": gid,
        "BASH_ON_FAIL": bashonfail,
        "GPG_PRIVATE_KEY": sign_with_encoded
    })

    try:
        additional_docker_options = " ".join(additional_docker_options)
        dockerscripts = getpath("drb/dockerscripts")
        rpms_inner_dir = sp(
            "{dockerexec} run --rm {image} rpm --eval %{{_rpmdir}}",
            **locals()).strip()
        sources_inner_dir = sp(
            "{dockerexec} run --rm {image} rpm --eval %{{_sourcedir}}",
            **locals()).strip()
        spawn_func(
            "{dockerexec} run {additional_docker_options} -v {dockerscripts}:/dockerscripts -v {source_directory}:{sources_inner_dir} -v {target_directory}:{rpms_inner_dir} {bashonfail_options} -w /dockerscripts {image}  ./rpmbuild-dir-in-docker.sh {serialized_options}",
            **locals())
    finally:
        if deletespec:
            os.unlink(specfile)