def docker_image(): """ pytest fixture which returns instance of DockerImage """ backend = DockerBackend().__enter__() image = backend.ImageClass(FEDORA_MINIMAL_REPOSITORY, tag=FEDORA_MINIMAL_REPOSITORY_TAG) yield image backend.__exit__(None, None, None)
def docker_container(): """ pytest fixture which returns instance of DockerImage """ backend = DockerBackend().__enter__() image = backend.ImageClass(FEDORA_MINIMAL_REPOSITORY, tag=FEDORA_MINIMAL_REPOSITORY_TAG) container = image.run_via_binary(command=["sleep", "infinity"]) yield container container.delete(force=True) backend.__exit__(None, None, None)
def test_oc_s2i_template(self): api_key = get_oc_api_token() with OpenshiftBackend(api_key=api_key, logging_level=logging.DEBUG) as openshift_backend: with DockerBackend(logging_level=logging.DEBUG) as backend: python_image = backend.ImageClass("centos/python-36-centos7", tag="latest") psql_image = backend.ImageClass("centos/postgresql-96-centos7", tag="9.6") OpenshiftBackend.login_to_registry('developer') app_name = openshift_backend.new_app( image=python_image, template="https://raw.githubusercontent.com/sclorg/django-ex" "/master/openshift/templates/django-postgresql.json", oc_new_app_args=["-p", "SOURCE_REPOSITORY_REF=master", "-p", "PYTHON_VERSION=3.6", "-p", "POSTGRESQL_VERSION=9.6"], name_in_template={"python": "3.6"}, other_images=[{psql_image: "postgresql:9.6"}], project='myproject') try: openshift_backend.wait_for_service( app_name=app_name, expected_output='Welcome to your Django application on OpenShift', timeout=300) finally: # pass name from template as argument openshift_backend.clean_project('django-psql-example')
def login_to_registry(username): """ Login within docker daemon to docker registry running in this OpenShift cluster :return: """ with DockerBackend() as backend: token = get_oc_api_token() backend.login(username, password=token, registry=OpenshiftBackend.get_internal_registry_ip(), reauth=True)
def test_oc_s2i_local(): with OpenshiftBackend(logging_level=logging.DEBUG) as openshift_backend: with DockerBackend() as backend: python_image = backend.ImageClass("centos/python-36-centos7") openshift_backend.login_to_registry('developer') app_name = openshift_backend.new_app( python_image, source="examples/openshift/standalone-test-app", project='myproject') try: openshift_backend.wait_for_service( app_name=app_name, expected_output= "Hello World from standalone WSGI application!") finally: openshift_backend.clean_project(app_name)
def test_oc_s2i_remote(): with OpenshiftBackend() as openshift_backend: with DockerBackend() as backend: python_image = backend.ImageClass("centos/python-36-centos7") openshift_backend.login_to_registry('developer') app_name = openshift_backend.new_app( python_image, source="https://github.com/openshift/django-ex.git", project='myproject') try: openshift_backend.wait_for_service( app_name=app_name, expected_output= 'Welcome to your Django application on OpenShift') finally: openshift_backend.clean_project(app_name)
import logging from conu.backend.origin.backend import OpenshiftBackend from conu.backend.docker.backend import DockerBackend # insert your API key - oc whoami -t API_KEY = 'luqIZzSJ8RT33yIi_lo3aNRZlA34wfftYTR0r9zRtw4' with OpenshiftBackend(api_key=API_KEY, logging_level=logging.DEBUG) as openshift_backend: with DockerBackend(logging_level=logging.DEBUG) as backend: # builder image python_image = backend.ImageClass("centos/python-36-centos7") # docker login inside OpenShift internal registry openshift_backend.login_to_registry('developer') # create new app from local source in OpenShift cluster app_name = openshift_backend.new_app( python_image, source="examples/openshift/standalone-test-app", project='myproject') try: # wait until service is ready to accept requests openshift_backend.wait_for_service( app_name=app_name, expected_output="Hello World from standalone WSGI application!" ) finally: openshift_backend.clean_project(app_name)
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # import logging from conu.backend.origin.backend import OpenshiftBackend from conu.backend.docker.backend import DockerBackend from conu.utils import get_oc_api_token api_key = get_oc_api_token() with OpenshiftBackend(api_key=api_key, logging_level=logging.DEBUG) as openshift_backend: with DockerBackend() as backend: # images which this template uses python_image = backend.ImageClass("centos/python-36-centos7", tag="latest") psql_image = backend.ImageClass("centos/postgresql-96-centos7", tag="9.6") # docker login inside OpenShift internal registry OpenshiftBackend.login_to_registry('developer') # create new app from remote source in OpenShift cluster app_name = openshift_backend.new_app( image=python_image, template="https://raw.githubusercontent.com/sclorg/django-ex" "/master/openshift/templates/django-postgresql.json", oc_new_app_args=[
def setup_class(cls): cls.backend = DockerBackend().__enter__() cls.image = cls.backend.ImageClass(FEDORA_MINIMAL_REPOSITORY, tag=FEDORA_MINIMAL_REPOSITORY_TAG)
def setup_class(cls): cls.backend = DockerBackend().__enter__() cls.image = cls.backend.ImageClass(FEDORA_MINIMAL_REPOSITORY, tag=FEDORA_MINIMAL_REPOSITORY_TAG) cls.container = cls.image.run_via_binary( DockerRunBuilder(command=["sleep", "infinity"]))