Skip to content

Commit

Permalink
Merge pull request #2002 from SUSE/mariadb_client_micro
Browse files Browse the repository at this point in the history
Switch mariadb* images to bci-micro
  • Loading branch information
dcermak authored Nov 25, 2024
2 parents 8155787 + 0812b10 commit 9d88626
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/bci_build/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ class BaseContainerImage(abc.ABC):
#: is not possible and will result in an error.
custom_end: str = ""

#: This string is appended to the the build stage in a multistage build and can
#: contain arbitrary instructions valid for a :file:`Dockerfile`.
build_stage_custom_end: str | None = None

#: A script that is put into :file:`config.sh` if a kiwi image is
#: created. If a :file:`Dockerfile` based build is used then this script is
#: prependend with a :py:const:`~bci_build.package.DOCKERFILE_RUN` and added
Expand Down
4 changes: 4 additions & 0 deletions src/bci_build/package/cosign.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bci_build.package import ParseVersion
from bci_build.package import Replacement
from bci_build.package.helpers import generate_from_image_tag
from bci_build.package.helpers import generate_package_version_check
from bci_build.package.versions import format_version
from bci_build.package.versions import get_pkg_version

Expand All @@ -22,6 +23,9 @@
tag_version=format_version(
cosign_ver := get_pkg_version("cosign", os_version), ParseVersion.MINOR
),
build_stage_custom_end=generate_package_version_check(
"cosign", cosign_ver, ParseVersion.MINOR, use_target=True
),
version_in_uid=False,
additional_versions=[format_version(cosign_ver, ParseVersion.MAJOR)],
replacements_via_service=[
Expand Down
16 changes: 13 additions & 3 deletions src/bci_build/package/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@


def generate_package_version_check(
pkg_name: str, pkg_version: str, parse_version: ParseVersion = ParseVersion.MINOR
pkg_name: str,
pkg_version: str,
parse_version: ParseVersion = ParseVersion.MINOR,
use_target: bool = False,
) -> str:
"""Generate a RUN instruction for a :file:`Dockerfile` that will fail if the
package with the name ``pkg_name`` is not at the provided version
``pkg_version``. The optional parameter ``parse_version`` allows you to
``pkg_version``.
The optional parameter ``parse_version`` allows you to
restrict the version check to only match the major, major+minor, or
major+minor+patch version.
The optional parameter "use_target" generates a RUN instruction that checks
for the ``pkg_name`` in the directory `/target` which is used in multi-stage
builds.
"""
cut_count = {
ParseVersion.MAJOR: 1,
Expand All @@ -28,7 +36,9 @@ def generate_package_version_check(
)

return f"""# sanity check that the version from the tag is equal to the version of {pkg_name} that we expect
{DOCKERFILE_RUN} [ "$(rpm -q --qf '%{{version}}' {pkg_name} | cut -d '.' -f -{cut_count})" = "{pkg_version}" ]"""
{DOCKERFILE_RUN} \\
[ "$(rpm{' --root /target' if use_target else ''} -q --qf '%{{version}}' {pkg_name} | \\
cut -d '.' -f -{cut_count})" = "{pkg_version}" ]"""


def generate_from_image_tag(os_version: OsVersion, container_name: str) -> str:
Expand Down
25 changes: 15 additions & 10 deletions src/bci_build/package/mariadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from bci_build.package import ParseVersion
from bci_build.package import Replacement
from bci_build.package import generate_disk_size_constraints
from bci_build.package.helpers import generate_from_image_tag
from bci_build.package.helpers import generate_package_version_check
from bci_build.package.versions import get_pkg_version

Expand Down Expand Up @@ -43,10 +44,6 @@
prefix = "rmt-"
additional_names = ["mariadb"]

version_check_lines = generate_package_version_check(
"mariadb-client", mariadb_version
)

docker_entrypoint = (
Path(__file__).parent / "mariadb" / str(mariadb_version) / "entrypoint.sh"
).read_text()
Expand Down Expand Up @@ -77,6 +74,10 @@
is_latest=os_version in CAN_BE_LATEST_OS_VERSION,
version_in_uid=False,
pretty_name="MariaDB Server",
from_target_image=generate_from_image_tag(os_version, "bci-micro"),
build_stage_custom_end=generate_package_version_check(
"mariadb", mariadb_version, use_target=True
),
replacements_via_service=[
Replacement(
regex_in_build_description=_MARIADB_VERSION_PLACEHOLDER,
Expand All @@ -90,12 +91,15 @@
),
],
package_list=[
"coreutils",
"findutils",
"gawk",
"mariadb",
"mariadb-tools",
"gawk",
"openssl",
"sed",
"timezone",
"util-linux",
"findutils",
"zstd",
],
entrypoint=[_ENTRYPOINT_FNAME],
Expand All @@ -114,9 +118,7 @@
cmd=["mariadbd"],
volumes=["/var/lib/mysql"],
exposes_ports=[TCP(3306)],
custom_end=rf"""{version_check_lines}
{DOCKERFILE_RUN} mkdir /docker-entrypoint-initdb.d
custom_end=rf"""{DOCKERFILE_RUN} mkdir /docker-entrypoint-initdb.d
# docker-entrypoint from https://github.com/MariaDB/mariadb-docker.git
COPY {_ENTRYPOINT_FNAME} /usr/local/bin/
Expand Down Expand Up @@ -151,6 +153,10 @@
version_in_uid=False,
additional_names=[f"{name}-client" for name in additional_names],
version=_MARIADB_VERSION_PLACEHOLDER,
from_target_image=generate_from_image_tag(os_version, "bci-micro"),
build_stage_custom_end=generate_package_version_check(
"mariadb-client", mariadb_version, use_target=True
),
tag_version=mariadb_version,
pretty_name="MariaDB Client",
support_level=SupportLevel.L3,
Expand All @@ -163,6 +169,5 @@
package_name="mariadb-client",
),
],
custom_end=version_check_lines,
)
)
3 changes: 3 additions & 0 deletions src/bci_build/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
zypper -n clean; \\
{{ LOG_CLEAN }}
{%- endif %}
{%- if image.build_stage_custom_end %}
{{ image.build_stage_custom_end }}
{%- endif %}
{% if image.from_target_image %}FROM {{ image.dockerfile_from_target_ref }}
COPY --from=builder /target /{% endif %}
# Define labels according to https://en.opensuse.org/Building_derived_containers
Expand Down

0 comments on commit 9d88626

Please sign in to comment.