Example #1
0
def short_test():
    # TODO: run unitests as well here
    click.echo("Starting short self test. Requires networking and may take a bit of time especially at the first run, because data will be downloaded")

    dockerexec = which("docker")
    testpath = getpath("drb/test")
    result = sp("{dockerexec} run --rm -v {testpath}:/testpath phusion/baseimage /bin/bash -c 'cat /testpath/everythinglooksgood.txt'", **locals())
    if result.strip() != "everything looks good":
        click.echo("Basic self test failed: docker run failed. Checklist:\n\nVerify the docker service is running\n"
                   "Verify the 'docker' group exists and your user belongs to it\n"
                   "If you had to add the group, verify you've restarted the 'docker' service after such addition\n"
                   "Verify you've logged out+in after adding your user to the group\n"
                   "Verify selinux is disabled\n"
                   "Verify your disk has enough free space\n"
                   "Error:\n%s\n" % result)
        sys.exit(1)

    tmpdir = mkdtemp()
    try:
        downloadsources(tmpdir, getpath("drb/test/spectooltest.spec"))
        if not os.path.exists(os.path.join(tmpdir, "README.md")):
            click.echo("Basic self test failed, could not download sources; probably a spectool issue (missing perl or wrong version?)")
            sys.exit(1)
    finally:
        shutil.rmtree(tmpdir)

    for fn in os.listdir(getpath("drb/dockerscripts")):
        if not os.access(os.path.join(getpath("drb/dockerscripts"), fn), os.X_OK):
            click.echo("File {0} is not executable, probably an install error has happened. Make sure you're using a recent python+virtualenv".format(fn))
            sys.exit(1)

    click.echo("Short self test succeeded.")
Example #2
0
def short_test():
    # TODO: run unitests as well here
    click.echo(
        "Starting short self test. Requires networking and may take a bit of time especially at the first run, because data will be downloaded"
    )

    dockerexec = which("docker")
    testpath = getpath("drb/test")
    result = sp(
        "{dockerexec} run --rm -v {testpath}:/testpath phusion/baseimage /bin/bash -c 'cat /testpath/everythinglooksgood.txt'",
        **locals())
    if result.strip() != "everything looks good":
        click.echo(
            "Basic self test failed: docker run failed. Checklist:\n\nVerify the docker service is running\n"
            "Verify the 'docker' group exists and your user belongs to it\n"
            "If you had to add the group, verify you've restarted the 'docker' service after such addition\n"
            "Verify you've logged out+in after adding your user to the group\n"
            "Verify selinux is disabled\n"
            "Verify your disk has enough free space\n"
            "Error:\n%s\n" % result)
        sys.exit(1)

    tmpdir = mkdtemp()
    try:
        downloadsources(tmpdir, getpath("drb/test/spectooltest.spec"))
        if not os.path.exists(os.path.join(tmpdir, "README.md")):
            click.echo(
                "Basic self test failed, could not download sources; probably a spectool issue (missing perl or wrong version?)"
            )
            sys.exit(1)
    finally:
        shutil.rmtree(tmpdir)

    for fn in os.listdir(getpath("drb/dockerscripts")):
        if not os.access(os.path.join(getpath("drb/dockerscripts"), fn),
                         os.X_OK):
            click.echo(
                "File {0} is not executable, probably an install error has happened. Make sure you're using a recent python+virtualenv"
                .format(fn))
            sys.exit(1)

    click.echo("Short self test succeeded.")
Example #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)
Example #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)