Ejemplo n.º 1
0
def build_verify_and_push(namespace,
                          repository,
                          revision,
                          token,
                          source_dir=None,
                          yamls=None):
    """Build verify and push constructs the operator bundle, verifies it, and pushes it to an external app registry.
    Currently the only supported app registry is the one located at Quay.io (https://quay.io/cnr/api/v1/packages/)

    :param namespace: Quay namespace where the repository we are pushing the bundle is located.
    :param repository: Application repository name the application is bundled for.
    :param revision: Release version of the bundle.
    :param source_dir: Path to local directory of yaml files to be read
    :param yamls: List of yaml strings to create bundle with
    """

    bundle = build_and_verify(source_dir, yamls)

    if bundle is not None:
        with TemporaryDirectory() as temp_dir:
            with open('%s/bundle.yaml' % temp_dir, 'w') as outfile:
                yaml.dump(bundle, outfile, default_flow_style=False)
                outfile.flush()

            PushCmd().push(temp_dir, namespace, repository, revision, token)
    else:
        logger.error("Bundle is invalid. Will not attempt to push.")
        raise ValueError(
            "Resulting bundle is invalid, input yaml is improperly defined.")
Ejemplo n.º 2
0
def test_create_base64_bundle(bundle_dir):
    with TemporaryDirectory() as scratch:
        directory_name = "directory-abcd"
        # make a subdirectory with a known name so that the bundle is always the same
        inpath = os.path.join(scratch, directory_name)
        os.mkdir(inpath)

        copy_tree(bundle_dir, inpath)
        out = PushCmd()._create_base64_bundle(inpath, "repo")

        outpath = os.path.join(scratch, "out")
        os.mkdir(outpath)

        # write the output tar
        tardata = base64.b64decode(out)
        tarfile_name = os.path.join(outpath, "bundle.tar.gz")
        with open(tarfile_name, "wb") as bundle:
            bundle.write(tardata)

        # uncompress the bundle
        with tarfile.open(tarfile_name) as bundle:
            bundle.extractall(path=outpath)

        outfiles = os.listdir(outpath)

        # ensure the surrouding directory was packed into the tar archive
        assert directory_name in outfiles
Ejemplo n.º 3
0
def build_verify_and_push(namespace,
                          repository,
                          revision,
                          token,
                          source_dir=None,
                          yamls=None,
                          validation_output=None):
    """Build verify and push constructs the operator bundle,
    verifies it, and pushes it to an external app registry.
    Currently the only supported app registry is the one
    located at Quay.io (https://quay.io/cnr/api/v1/packages/)

    :param namespace: Quay namespace where the repository we are
                      pushing the bundle is located.
    :param repository: Application repository name the application is bundled for.
    :param revision: Release version of the bundle.
    :param token: Basic authentication token used to authorize push to external datastore
    :param source_dir: Path to local directory of yaml files to be read
    :param yamls: List of yaml strings to create bundle with
    :param validation_output: Path to optional output file for validation logs

    :raises TypeError: When called with both source_dir and yamls specified

    :raises OpCourierBadYaml: When an invalid yaml file is encountered
    :raises OpCourierBadArtifact: When a file is not any of {CSV, CRD, Package}
    :raises OpCourierBadBundle: When the resulting bundle fails validation

    :raises OpCourierQuayCommunicationError: When communication with Quay fails
    :raises OpCourierQuayErrorResponse: When Quay responds with an error
    :raises OpCourierQuayError: When the request fails in an unexpected way
    """
    verified_manifest = build_and_verify(source_dir,
                                         yamls,
                                         repository=repository,
                                         validation_output=validation_output)

    if not verified_manifest.nested:
        with TemporaryDirectory() as temp_dir:
            with open(os.path.join(temp_dir, 'bundle.yaml'), 'w') as outfile:
                yaml.dump(verified_manifest.bundle,
                          outfile,
                          default_flow_style=False)
            PushCmd().push(temp_dir, namespace, repository, revision, token)
    else:
        with TemporaryDirectory() as temp_dir:
            copy_tree(source_dir, temp_dir)
            PushCmd().push(temp_dir, namespace, repository, revision, token)