コード例 #1
0
ファイル: build.py プロジェクト: trucnguyenlam/klio
def build(job_dir, conf, config_file, image_tag):
    image_name = conf.pipeline_options.worker_harness_container_image
    client = docker.from_env()

    if config_file:
        basename = os.path.basename(config_file)
        image_tag = "{}-{}".format(image_tag, basename)

    docker_utils.check_docker_connection(client)
    docker_utils.check_dockerfile_present(job_dir)
    docker_utils.build_docker_image(job_dir, image_name, image_tag,
                                    config_file)
コード例 #2
0
def test_build_docker_image(
    config_file,
    exp_config_file,
    mocker,
    mock_json_loads,
    mock_docker_api_client,
    caplog,
):
    mock_api_client = mocker.Mock()
    mock_docker_api_client.return_value = mock_api_client

    mock_api_client.build.return_value = (item
                                          for item in (b"BYTELOGS", "LOGS", "",
                                                       '{"stream":"\\n"}'))

    mock_json_loads.return_value = {"stream": "SUCCESS"}

    job_dir = "/test/dir/jobs/test_run_job"
    image_name = "gcr.io/sigint/test-image-name"
    image_tag = "foobar"
    image_name_and_tag = "{}:{}".format(image_name, image_tag)

    build_flag = {
        "path": job_dir,
        "tag": image_name_and_tag,
        "rm": True,
        "buildargs": {
            "tag": image_tag,
            "KLIO_CONFIG": exp_config_file
        },
    }

    docker_utils.build_docker_image(job_dir, image_name, image_tag,
                                    config_file)

    docker.APIClient.assert_called_once_with(
        base_url="unix://var/run/docker.sock")
    mock_api_client.build.assert_called_once_with(**build_flag)

    assert 2 == len(caplog.records)
コード例 #3
0
def test_build_docker_image_with_errors(mocker, mock_json_loads,
                                        mock_docker_api_client, caplog):
    mock_api_client = mocker.Mock()
    mock_docker_api_client.return_value = mock_api_client
    mock_api_client.build.return_value = "LOGS"

    mock_json_loads.return_value = {
        "error": "FAILURE",
        "errorDetail": {
            "message": "FAILURE"
        },
    }

    job_dir = "/test/dir/jobs/test_run_job"
    image_name = "gcr.io/sigint/test-image-name"
    image_tag = "foobar"
    image_name_and_tag = "{}:{}".format(image_name, image_tag)

    build_flag = {
        "path": job_dir,
        "tag": image_name_and_tag,
        "rm": True,
        "buildargs": {
            "tag": image_tag,
            "KLIO_CONFIG": "klio-job.yaml"
        },
    }

    with pytest.raises(SystemExit):
        docker_utils.build_docker_image(job_dir, image_name, image_tag)

    docker.APIClient.assert_called_once_with(
        base_url="unix://var/run/docker.sock")
    mock_api_client.build.assert_called_once_with(**build_flag)

    assert 3 == len(caplog.records)
コード例 #4
0
    def _setup_docker_image(self):
        image_exists = docker_utils.docker_image_exists(
            self._full_image_name, self._docker_client)

        if not image_exists or self.docker_runtime_config.force_build:
            logging.info("Building worker image: %s" % self._full_image_name)

            _pipe_opts = self.klio_config.pipeline_options
            return docker_utils.build_docker_image(
                self.job_dir,
                _pipe_opts.worker_harness_container_image,
                self.docker_runtime_config.image_tag,
                self.docker_runtime_config.config_file_override,
            )

        logging.info("Found worker image: %s" % self._full_image_name)