diff --git a/src/bci_build/package/__init__.py b/src/bci_build/package/__init__.py index 62a4f8257..edecb66a9 100755 --- a/src/bci_build/package/__init__.py +++ b/src/bci_build/package/__init__.py @@ -1422,6 +1422,7 @@ def generate_disk_size_constraints(size_gb: int) -> str: from .appcontainers import MARIADB_CLIENT_CONTAINERS # noqa: E402 from .appcontainers import MARIADB_CONTAINERS # noqa: E402 from .appcontainers import NGINX_CONTAINERS # noqa: E402 +from .appcontainers import OSC_CONTAINER # noqa: E402 from .appcontainers import PCP_CONTAINERS # noqa: E402 from .appcontainers import POSTGRES_CONTAINERS # noqa: E402 from .appcontainers import PROMETHEUS_CONTAINERS # noqa: E402 @@ -1488,6 +1489,7 @@ def generate_disk_size_constraints(size_gb: int) -> str: GITEA_RUNNER_CONTAINER, *TOMCAT_CONTAINERS, *GCC_CONTAINERS, + OSC_CONTAINER, ) } diff --git a/src/bci_build/package/appcontainers.py b/src/bci_build/package/appcontainers.py index c21bd25c3..a5cf9885f 100644 --- a/src/bci_build/package/appcontainers.py +++ b/src/bci_build/package/appcontainers.py @@ -18,6 +18,7 @@ from bci_build.package import SupportLevel from bci_build.package import _build_tag_prefix from bci_build.package import generate_disk_size_constraints +from bci_build.package.basecontainers import _get_os_container_package_names _PCP_FILES = {} for filename in ( @@ -808,3 +809,62 @@ def _get_nginx_kwargs(os_version: OsVersion): ) for tomcat_major, os_version in product(_TOMCAT_VERSIONS, ALL_BASE_OS_VERSIONS) ] + + +OSC_CONTAINER = ApplicationStackContainer( + name="osc", + pretty_name="Packaging", + package_name="packaging-image", + os_version=OsVersion.TUMBLEWEED, + is_latest=True, + version_in_uid=False, + version="%%osc_version%%", + replacements_via_service=[ + Replacement(regex_in_build_description="%%osc_version%%", package_name="osc") + ], + extra_files={ + "entrypoint.sh": (Path(__file__).parent / "osc" / "entrypoint.sh").read_bytes() + }, + package_list=[ + "osc", + "obs-service-appimage", + "obs-service-cargo", + "obs-service-cdi_containers_meta", + "obs-service-compose_kiwi_description", + "obs-service-docker_label_helper", + "obs-service-download_assets", + "obs-service-download_files", + "obs-service-download_url", + "obs-service-extract_file", + "obs-service-format_spec_file", + "obs-service-go_modules", + "obs-service-kiwi_label_helper", + "obs-service-kiwi_metainfo_helper", + "obs-service-kubevirt_containers_meta", + "obs-service-node_modules", + "obs-service-obs_scm", + "cpio", + "obs-service-product_converter", + "obs-service-recompress", + "obs-service-refresh_patches", + "obs-service-replace_using_env", + "obs-service-replace_using_package_version", + "obs-service-set_version", + "obs-service-snapcraft", + "obs-service-source_validator", + "obs-service-tar", + "obs-service-tar_scm", + "obs-service-verify_file", + *_get_os_container_package_names(OsVersion.TUMBLEWEED), + ], + custom_end="""WORKDIR /src/ +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh +""", + entrypoint=["/usr/local/bin/entrypoint.sh"], + env={"OSC_APIURL": "https://api.opensuse.org"}, + volumes=[ + # default location of the build root & package cache + "/var/tmp" + ], +) diff --git a/src/bci_build/package/osc/README.md.j2 b/src/bci_build/package/osc/README.md.j2 new file mode 100644 index 000000000..442679267 --- /dev/null +++ b/src/bci_build/package/osc/README.md.j2 @@ -0,0 +1,47 @@ +# Packaging Container + +This is the openSUSE packaging container image, it includes all the necessary +software to create and modify packages on the [Open Build +Service](https://build.opensuse.org/) using +[osc](https://github.com/openSUSE/osc/). + + +## How to use this container image + +This container image is intended for interactive usage with your `.oscrc` +mounted into the container: + +```ShellSession +# podman run --rm -it -v ~/.config/osc/oscrc:/root/.config/osc/oscrc:Z \ + {{ image.reference }} +``` + +The above command launches an interactive shell where your local osc config will +be used. You can then proceed to checkout packages, perform modifications and +send submissions to OBS. + +You can also let the container image's entrypoint generate a `oscrc` for you +using the environment variables `OSC_USER` and `OSC_PASSWORD`. It will create a +configuration for the OBS instance with the API URL saved in the environment variable +`OSC_APIURL` (defaults to api.opensuse.org): + +```ShellSession +# podman run --rm -it -e OSC_USER=my_user -e OSC_PASSWORD=mySecretPassword \ + {{ image.reference }} +``` + +Note that you should disable your shell's history as it will otherwise container +your password in plain text. + + +## Limitations + +- It is currently not possible to build packages in a container. + +- Cannot communicate with build.suse.de + + +## Volumes + +The container image is preconfigured to put `/var/tmp` into a volume. This +directory is used by `osc` to store the buildroot and the package cache. diff --git a/src/bci_build/package/osc/entrypoint.sh b/src/bci_build/package/osc/entrypoint.sh new file mode 100644 index 000000000..92ac76eea --- /dev/null +++ b/src/bci_build/package/osc/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -eo pipefail + +if [ ! -f "$HOME/.config/osc/oscrc" ]; then + mkdir -p "$HOME/.config/osc" + if [ -z ${OSC_USER+x} ] && [ -z ${OSC_PASSWORD+y} ]; then + echo "[general] +apiurl = ${OSC_APIURL} + +[${OSC_APIURL}] +user = ${OSC_USER} +pass = ${OSC_PASSWORD} +" > "$HOME/.config/osc/oscrc" + fi +fi + +exec "$@"