Exemple #1
0
def test_keep_container_running(temp_repo_func):
    backend = DockerBackend(verbosity=2, keep_container_running=True)

    arca = Arca(backend=backend, base_dir=BASE_DIR)

    task = Task("test_file:return_str_function")

    backend.check_docker_access()  # init docker client

    container_count = len(backend.client.containers.list())

    assert arca.run(temp_repo_func.url, temp_repo_func.branch,
                    task).output == "Some string"

    count_after_run = len(backend.client.containers.list())

    assert count_after_run == container_count + 1  # let's assume no changes are done to containers elsewhere
    assert arca.run(temp_repo_func.url, temp_repo_func.branch,
                    task).output == "Some string"

    count_after_second_run = len(backend.client.containers.list())

    assert count_after_second_run == container_count + 1  # the count is still the same

    backend.stop_containers()

    count_after_stop = len(backend.client.containers.list())

    assert count_after_stop == container_count
Exemple #2
0
    def run(self):
        import requests
        import arca
        from arca import DockerBackend

        backend = DockerBackend()
        backend.check_docker_access()

        response = requests.get(
            "https://hub.docker.com/v2/repositories/mikicz/arca/tags/",
            params={"page_size": 1000})
        response = response.json()
        available_tags = [x["name"] for x in response["results"]]

        if arca.__version__ in available_tags:
            print("This version was already pushed into the registry.")
            base_arca_name, base_arca_tag = backend.get_arca_base()
            print(
                f"Pulled image {base_arca_name}:{base_arca_tag}, might have to build new python versions."
            )
        else:
            base_arca_name, base_arca_tag = backend.get_arca_base(pull=False)
            print(f"Built image {base_arca_name}:{base_arca_tag}")

            if self.verbose:
                for x in backend.client.images.push(base_arca_name,
                                                    tag=base_arca_tag,
                                                    stream=True):
                    print(x.decode("utf-8"), end="")
            else:
                backend.client.images.push(base_arca_name, tag=base_arca_tag)

            print(f"Pushed image {base_arca_name}:{base_arca_tag}")

        for python_version in self.list_python_versions():
            tag = backend.get_python_base_tag(python_version)
            if tag in available_tags:
                print(
                    f"Skipping Python version {python_version}, already built for this version of arca."
                )
                continue

            image_name, image_tag = backend.get_python_base(python_version,
                                                            pull=False)

            print(f"Built image {image_name}:{image_tag}")

            if self.verbose:
                for x in backend.client.images.push(image_name,
                                                    tag=image_tag,
                                                    stream=True):
                    print(x.decode("utf-8"), end="")
            else:
                backend.client.images.push(image_name, tag=image_tag)

            print(f"Pushed image {image_name}:{image_tag}")