Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ Next Release

Breaking changes:

- deprecate :py:class:`~pytest_container.build.MultiStageBuild` in favor
:py:class:`~pytest_container.container.MultiStageContainer`

- change type of ``OciRuntimeBase.build_command`` from ``List[str]`` to
``Tuple[str, ...]``

- Change addition of SELinux flags to volumes: SELinux flags are only added if
:py:attr:`~pytest_container.container.ContainerVolumeBase.flags` is ``None``.

Improvements and new features:

- Add the class :py:class:`~pytest_container.container.MultiStageContainer` as a
replacement of :py:class:`~pytest_container.build.MultiStageBuild` to handle
container images built from a :file:`Containerfile` with multiple stages

- Add the function
:py:func:`~pytest_container.container.ContainerData.read_container_logs` to
get access to the logs of the running container
Expand Down Expand Up @@ -70,15 +80,16 @@ Internal changes:
Breaking changes:

- add the parameter ``container_runtime`` to
:py:func:`~pytest_container.container.ContainerBaseABC.prepare_container` and
:py:func:`~pytest_container.build.MultiStageBuild.prepare_build`.
``ContainerBaseABC.prepare_container`` (now called
:py:func:`~pytest_container.container._ContainerPrepareABC.prepare_container`)
and :py:func:`~pytest_container.build.MultiStageBuild.prepare_build`.

- deprecate the function ``pytest_container.container_from_pytest_param``,
please use
:py:func:`~pytest_container.container.container_and_marks_from_pytest_param`
instead.

- :py:func:`~pytest_container.container.ContainerBaseABC.get_base` no longer
- :py:func:`~pytest_container.container._ContainerBaseABC.get_base` no longer
returns the recursive base but the immediate base.


Expand Down Expand Up @@ -126,7 +137,7 @@ Breaking changes:

Improvements and new features:

- Add :py:attr:`~pytest_container.container.ContainerBaseABC.baseurl` property
- Add :py:attr:`~pytest_container.container._ContainerBaseABC.baseurl` property
to get the registry url of the container on which any currently existing
container is based on.

Expand Down Expand Up @@ -216,15 +227,16 @@ Improvements and new features:
Container Images exposing the same ports in parallel without marking them as
``singleton=True``.

- The attribute :py:attr:`~pytest_container.container.ContainerData.container`
was added to :py:class:`~pytest_container.container.ContainerData` (the
datastructure that is passed to test functions via the ``*container*``
fixtures). This attribute contains the
:py:class:`~pytest_container.container.ContainerBase` that was used to
parametrize this test run.
- The attribute ``ContainerData.container`` (is now
:py:attr:`~pytest_container.container.ContainerImageData.container`) was added
to :py:class:`~pytest_container.container.ContainerData` (the datastructure
that is passed to test functions via the ``*container*`` fixtures). This
attribute contains the :py:class:`~pytest_container.container.ContainerBase`
that was used to parametrize this test run.

- Add support to add tags to container images via
:py:attr:`~pytest_container.container.DerivedContainer.add_build_tags`.
``DerivedContainer.add_build_tags`` (is now called
:py:attr:`~pytest_container.container._ContainerForBuild.add_build_tags`)

- Lock container preparation so that only a single process is pulling & building
a container image.
Expand Down
2 changes: 2 additions & 0 deletions pytest_container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"container_from_pytest_param",
"container_to_pytest_param",
"DerivedContainer",
"MultiStageContainer",
"add_extra_run_and_build_args_options",
"add_logging_level_options",
"auto_container_parametrize",
Expand All @@ -31,6 +32,7 @@
from .container import container_from_pytest_param
from .container import container_to_pytest_param
from .container import DerivedContainer
from .container import MultiStageContainer
from .helpers import add_extra_run_and_build_args_options
from .helpers import add_logging_level_options
from .helpers import auto_container_parametrize
Expand Down
28 changes: 25 additions & 3 deletions pytest_container/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
builds via :py:class:`MultiStageBuild`.

"""
import sys
import tempfile
from dataclasses import dataclass
from os.path import basename
from os.path import join
from pathlib import Path
from string import Template
from subprocess import check_output
from typing import cast
from typing import Dict
from typing import List
from typing import Optional
Expand All @@ -18,13 +20,19 @@

from _pytest.config import Config
from _pytest.mark.structures import ParameterSet
from deprecation import deprecated
from pytest_container.container import Container
from pytest_container.container import container_and_marks_from_pytest_param
from pytest_container.container import DerivedContainer
from pytest_container.logging import _logger
from pytest_container.runtime import OciRuntimeBase
from pytest_container.runtime import ToParamMixin

if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata


@dataclass(frozen=True)
class GitRepositoryBuild(ToParamMixin):
Expand Down Expand Up @@ -83,6 +91,14 @@ def test_command(self) -> str:
return cd_cmd


_deprecated_multi_stage_build_kwargs = {
"deprecated_in": "0.5.0",
"removed_in": "0.6.0",
"current_version": metadata.version("pytest_container"),
"details": "use MultiStageContainer instead",
}


@dataclass
class MultiStageBuild:
"""Helper class to perform multi-stage container builds using the
Expand Down Expand Up @@ -165,6 +181,7 @@ def containerfile(self) -> str:
}
)

@deprecated(**_deprecated_multi_stage_build_kwargs) # type: ignore
def prepare_build(
self,
tmp_path: Path,
Expand Down Expand Up @@ -197,6 +214,7 @@ def prepare_build(
containerfile.write(self.containerfile)

@staticmethod
@deprecated(**_deprecated_multi_stage_build_kwargs) # type: ignore
def run_build_step(
tmp_path: Path,
runtime: OciRuntimeBase,
Expand All @@ -223,7 +241,7 @@ def run_build_step(
with tempfile.TemporaryDirectory() as tmp_dir:
iidfile = join(tmp_dir, str(uuid4()))
cmd = (
runtime.build_command
[*runtime.build_command]
+ (extra_build_args or [])
+ [f"--iidfile={iidfile}"]
+ (["--target", target] if target else [])
Expand All @@ -233,6 +251,7 @@ def run_build_step(
check_output(cmd)
return runtime.get_image_id_from_iidfile(iidfile)

@deprecated(**_deprecated_multi_stage_build_kwargs) # type: ignore
def build(
self,
tmp_path: Path,
Expand Down Expand Up @@ -278,6 +297,9 @@ def build(
root,
extra_build_args,
)
return MultiStageBuild.run_build_step(
tmp_path, runtime, target, extra_build_args
return cast(
str,
MultiStageBuild.run_build_step(
tmp_path, runtime, target, extra_build_args
),
)
Loading
Loading