Ejemplo n.º 1
0
def mock_repo_config(workflow, tmpdir, multiple_remote_sources=False):
    data = ""

    if multiple_remote_sources:
        data = dedent("""\
            remote_sources:
            - name: first
              remote_source:
                repo: test_repo
                ref: e1be527f39ec31323f0454f7d1422c6260b00580
            """)

    if not os.path.exists(tmpdir):
        os.makedirs(tmpdir)

    with open(os.path.join(tmpdir, 'container.yaml'), 'w') as f:
        f.write(data)
        f.flush()

    class MockSource(StubSource):
        def __init__(self, workdir):
            super(MockSource, self).__init__()
            self.workdir = workdir

    workflow.source = MockSource(str(tmpdir))
    workflow.source.config = SourceConfig(str(tmpdir))
Ejemplo n.º 2
0
    def _create_source_config(self, tmpdir, yml_config):
        tmpdir_str = str(tmpdir)
        path = os.path.join(tmpdir_str, REPO_CONTAINER_CONFIG)
        # store container configuration into expected file
        with open(path, 'w') as f:
            f.write(yml_config)
            f.flush()

        return SourceConfig(tmpdir_str)
def mock_repo_config(workflow, data=None):
    if data is None:
        data = dedent("""\
            remote_source:
                repo: {}
                ref: {}
            """.format(REMOTE_SOURCE_REPO, REMOTE_SOURCE_REF))

    workflow._tmpdir.joinpath('container.yaml').write_text(data, "utf-8")

    # The repo config is read when SourceConfig is initialized. Force
    # reloading here to make usage easier.
    workflow.source.config = SourceConfig(str(workflow._tmpdir))
Ejemplo n.º 4
0
def mock_workflow(tmpdir, container_yaml):
    workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image')
    mock_source = MockSource(tmpdir)
    setattr(workflow, 'builder', MockBuilder())
    workflow.builder.source = mock_source
    flexmock(workflow, source=mock_source)

    with open(mock_source.container_yaml_path, "w") as f:
        f.write(container_yaml)
    workflow.builder.source.config = SourceConfig(str(tmpdir))

    setattr(workflow.builder, 'df_dir', str(tmpdir))

    return workflow
Ejemplo n.º 5
0
def mock_workflow(
    workflow, source_dir: Path, container_yaml, platforms: List[str], user_params=None
):
    mock_source = MockSource(str(source_dir))
    setattr(workflow, 'builder', MockBuilder())
    flexmock(workflow, source=mock_source)

    if user_params is None:
        workflow.user_params.update(USER_PARAMS)

    with open(mock_source.container_yaml_path, "w") as f:
        f.write(container_yaml)
    workflow.source.config = SourceConfig(str(source_dir))
    workflow.build_dir.init_build_dirs(platforms, workflow.source)

    return workflow
Ejemplo n.º 6
0
def mock_workflow(workflow, build_dir: Path, container_yaml, user_params=None, platforms=None):
    if user_params is None:
        user_params = USER_PARAMS
    mock_source = MockSource(str(build_dir))
    flexmock(workflow, source=mock_source)

    with open(mock_source.container_yaml_path, "w") as f:
        f.write(container_yaml)
    workflow.source.config = SourceConfig(str(build_dir))
    workflow.user_params = user_params
    if not platforms:
        platforms = ['x86_64']
    Path(workflow.source.path, "Dockerfile").write_text(DF_CONTENT)
    workflow.build_dir.init_build_dirs(platforms, workflow.source)

    return workflow
def mock_workflow(tmpdir, container_yaml, user_params=None):
    if user_params is None:
        user_params = USER_PARAMS
    workflow = DockerBuildWorkflow(source=MOCK_SOURCE)
    mock_source = MockSource(tmpdir)
    setattr(workflow, 'builder', MockBuilder())
    workflow.builder.source = mock_source
    flexmock(workflow, source=mock_source)
    workflow.user_params = user_params

    with open(mock_source.container_yaml_path, "w") as f:
        f.write(container_yaml)
    workflow.builder.source.config = SourceConfig(str(tmpdir))

    setattr(workflow.builder, 'df_dir', str(tmpdir))

    return workflow
Ejemplo n.º 8
0
def mock_workflow(tmpdir, container_yaml):
    workflow = DockerBuildWorkflow('test-image', source=MOCK_SOURCE)
    mock_source = MockSource(tmpdir)
    setattr(workflow, 'builder', MockBuilder())
    workflow.builder.source = mock_source
    flexmock(workflow, source=mock_source)

    with open(mock_source.container_yaml_path, "w") as f:
        f.write(container_yaml)
    workflow.builder.source.config = SourceConfig(str(tmpdir))

    df = df_parser(str(tmpdir))
    df.content = DF_CONTENT

    setattr(workflow.builder, 'df_dir', str(tmpdir))
    setattr(workflow.builder, 'df_path', df.dockerfile_path)

    return workflow
Ejemplo n.º 9
0
def mock_workflow(workflow,
                  source_dir: Path,
                  container_yaml,
                  user_params=None):
    if user_params is None:
        user_params = USER_PARAMS

    if user_params is None:
        workflow.user_params.update(USER_PARAMS)
    else:
        workflow.user_params.update(user_params)

    mock_source = MockSource(source_dir)
    flexmock(workflow, source=mock_source)

    with open(mock_source.container_yaml_path, "w") as f:
        f.write(container_yaml)
    workflow.source.config = SourceConfig(str(source_dir))

    (source_dir / "Dockerfile").write_text(DF_CONTENT)

    workflow.build_dir.init_build_dirs(["aarch64", "x86_64"], workflow.source)
Ejemplo n.º 10
0
 def config(self):
     self._config = self._config or SourceConfig(self.path)
     return self._config
Ejemplo n.º 11
0
 def config(self):  # lazy load after container.yaml has been created
     self._config = self._config or SourceConfig(self.path)
     return self._config