Examples

Run a container

For running a container, you need to have image initialized. Image holds information of repository and tag and provides other methods. To run image using docker binary (as user would) use conu.apidefs.image.Image.run_via_binary() method with conu.backend.docker.container.DockerRunBuilder as parameter.

Wait for service to be ready

conu.backend.docker.container.DockerContainer.wait_for_port() tries to reach 8080 till it’s opened. You can use your own timeout to limit time spent on waiting.

Extend image using source-to-image

Extends acts as s2i binary. It extends builder image in form of conu.backend.docker.image.S2IDockerImage using provided source and desired name of resulting image.

    container.delete()

Run image in pod

Run image inside k8s conu.backend.k8s.pod.Pod

    namespace = k8s_backend.create_namespace()

    with DockerBackend(logging_level=logging.DEBUG) as backend:
        image = backend.ImageClass("openshift/hello-openshift")

        pod = image.run_in_pod(namespace=namespace)

        try:
            pod.wait(200)
            assert pod.is_ready()
            assert pod.get_phase() == PodPhase.RUNNING
        finally:
            pod.delete()
            assert pod.get_phase() == PodPhase.TERMINATING
            k8s_backend.delete_namespace(namespace)

Deploy new application in OpenShift using remote source

Build and deploy new application in OpenShift using centos/python-36-centos7 image and remote source.

    python_image = openshift_backend.import_image("python-36-centos7",
                                                  "docker.io/centos/python-36-centos7")

    # create new app from remote source in OpenShift cluster
    app_name = openshift_backend.create_new_app_from_source(
        python_image,
        source="https://github.com/openshift/django-ex.git",
        project='myproject')

    try:
        # wait until service is ready to accept requests

        openshift_backend.wait_for_service(
            app_name=app_name,
            port=8080,
            expected_output='Welcome to your Django application on OpenShift',
            timeout=300)
    finally:
        openshift_backend.get_logs(app_name)
        openshift_backend.clean_project(app_name)