diff --git a/.hadolint.yaml b/.hadolint.yaml index b851230d..8e62e76f 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -6,3 +6,4 @@ override: info: - DL3006 - DL3008 + - DL3013 diff --git a/Makefile b/Makefile index 18cd7960..dc46e37c 100644 --- a/Makefile +++ b/Makefile @@ -110,6 +110,7 @@ CAPELLA_BUILD_TYPE ?= online INSTALL_OLD_GTK_VERSION ?= true PURE_VARIANTS_LICENSE_SERVER ?= http://localhost:8080 +PURE_VARIANTS_KNOWN_SERVERS ?= '[{"name": "test", "url": "http://example.localhost"}]' # Inject libraries from the capella/libs directory INJECT_LIBS_CAPELLA ?= false @@ -332,6 +333,7 @@ run-eclipse/remote/pure-variants: eclipse/remote/pure-variants docker run $(DOCKER_RUN_FLAGS) \ -e RMT_PASSWORD=$(RMT_PASSWORD) \ -e PURE_VARIANTS_LICENSE_SERVER=$(PURE_VARIANTS_LICENSE_SERVER) \ + -e PURE_VARIANTS_KNOWN_SERVERS=$(PURE_VARIANTS_KNOWN_SERVERS) \ -e CONNECTION_METHOD=$(CONNECTION_METHOD) \ -e XPRA_SUBPATH=$(XPRA_SUBPATH) \ -e WORKSPACE_DIR=/workspace/eclipse_pv \ @@ -381,6 +383,7 @@ run-t4c/client/remote/pure-variants: t4c/client/remote/pure-variants -e RMT_PASSWORD=$(RMT_PASSWORD) \ -e T4C_USERNAME=$(T4C_USERNAME) \ -e PURE_VARIANTS_LICENSE_SERVER=$(PURE_VARIANTS_LICENSE_SERVER) \ + -e PURE_VARIANTS_KNOWN_SERVERS=$(PURE_VARIANTS_KNOWN_SERVERS) \ -v $$(pwd)/volumes/pure-variants:/inputs/pure-variants \ -v $$(pwd)/volumes/workspace:/workspace \ -e AUTOSTART_CAPELLA=$(AUTOSTART_CAPELLA) \ diff --git a/base/Dockerfile b/base/Dockerfile index 624a3de1..752f6fd8 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -59,7 +59,7 @@ RUN ln -s "$(which python3.11)" /usr/bin/python && \ ln -sf "$(which pip3.11)" /usr/local/bin/pip3 && \ python -m venv /opt/.venv && \ # Configure pre-commit - pip install pre-commit==3.4.0 --no-cache-dir && \ + pip install --no-cache-dir pre-commit lxml PyYAML --no-cache-dir && \ echo "commit-msg post-rewrite pre-commit pre-merge-commit pre-rebase prepare-commit-msg" | xargs -n 1 cp /opt/git/global-hooks/+pre-commit-only.sh && \ echo "pre-push post-checkout post-commit post-merge" | xargs -n 1 cp /opt/git/global-hooks/+pre-commit-and-lfs.sh && \ git config --global core.hooksPath /opt/git/global-hooks && \ diff --git a/capella/Dockerfile b/capella/Dockerfile index bbec0840..6ed528e1 100644 --- a/capella/Dockerfile +++ b/capella/Dockerfile @@ -61,7 +61,7 @@ FROM base_new as build_online # https://github.com/moby/moby/issues/26533#issuecomment-246966836 ONBUILD ARG CAPELLA_VERSION="5.2.0" ONBUILD COPY ./download_archive.py /opt/.download_archive.py -ONBUILD RUN pip install --no-cache-dir requests==2.31.0 lxml==4.9.3 && \ +ONBUILD RUN pip install --no-cache-dir requests && \ python .download_archive.py ${CAPELLA_VERSION}; FROM base_new as build_offline @@ -121,7 +121,7 @@ ARG MEMORY_LIMIT=5500m RUN echo '-Dorg.eclipse.equinox.p2.transport.ecf.retry=15' >> /opt/capella/capella.ini && \ echo '-Dorg.eclipse.ecf.provider.filetransfer.retrieve.readTimeout=10000' >> /opt/capella/capella.ini && \ sed -i "s/-Xmx[^ ]*/-Xmx$MEMORY_LIMIT/g" /opt/capella/capella.ini -RUN pip install --no-cache-dir lxml==4.9.3 PyYAML==6.0.1 && python install_dropins.py +RUN python install_dropins.py COPY ./versions/${CAPELLA_VERSION}/patches /opt/patches RUN PATCH_DIR=/opt/patches /opt/patch.sh diff --git a/pure-variants/setup_workspace_purevariants.py b/pure-variants/setup_workspace_purevariants.py index a897ee08..4c83c71c 100644 --- a/pure-variants/setup_workspace_purevariants.py +++ b/pure-variants/setup_workspace_purevariants.py @@ -3,11 +3,16 @@ from __future__ import annotations +import json import logging import os import pathlib import re import shutil +import typing as t + +from lxml import etree +from lxml.builder import E logging.basicConfig(level=logging.DEBUG) LOGGER = logging.getLogger("pure::variants preparation") @@ -18,6 +23,11 @@ ) +class ResolvedServer(t.TypedDict): + name: str + url: str + + def replace_config(path: pathlib.Path, key: str, value: str) -> None: """Replace the existing config or add the config.""" path.parent.mkdir(exist_ok=True, parents=True) @@ -68,13 +78,63 @@ def copy_license_file_to_right_location() -> None: ) -if __name__ == "__main__": - LOGGER.info("Prepare Workspace...") - +def set_pure_variants_license_server_url() -> None: replace_config( ECLIPSE_SETTINGS_BASE_PATH / "com.ps.consul.eclipse.ui.float.prefs", "licenseServerLocation", os.environ["PURE_VARIANTS_LICENSE_SERVER"], ) + +def decode_bytes_to_eclipse_format(xml: bytes) -> str: + return xml.decode("utf-8").replace("=", r"\=").replace(":", r"\:") + + +def set_pure_variants_server_url() -> None: + known_servers = os.environ["PURE_VARIANTS_KNOWN_SERVERS"] + if not known_servers: + LOGGER.info( + "PURE_VARIANTS_KNOWN_SERVERS environment variable not set." + "Will not inject KNOWN_SERVERS into the workspace." + ) + resolved_servers: list[ResolvedServer] = json.loads(known_servers) + + category_servers = E.servers( + *[ + E.server( + name=server["name"], + description="", + category="com.ps.consul.pvserver.model", + url=server["url"], + ) + for server in resolved_servers + ] + ) + + replace_config( + ECLIPSE_SETTINGS_BASE_PATH / "com.ps.consul.eclipse.ui.prefs", + "CATEGORY_SERVERS", + r'' + + decode_bytes_to_eclipse_format(etree.tostring(category_servers)), + ) + + known_cores = E.CORELIST( + *[ + E.CORE(NAME=server["name"], URL=server["url"]) + for server in resolved_servers + ] + ) + replace_config( + ECLIPSE_SETTINGS_BASE_PATH / "com.ps.consul.eclipse.ui.prefs", + "KNOWN_CORES", + r'' + + decode_bytes_to_eclipse_format(etree.tostring(known_cores)), + ) + + +if __name__ == "__main__": + LOGGER.info("Prepare Workspace...") + + set_pure_variants_license_server_url() copy_license_file_to_right_location() + set_pure_variants_server_url() diff --git a/t4c/Dockerfile b/t4c/Dockerfile index 1c43159f..5ed300c5 100644 --- a/t4c/Dockerfile +++ b/t4c/Dockerfile @@ -60,7 +60,7 @@ COPY t4c_cli /opt/t4c_cli/t4c_cli COPY pyproject.toml /opt/t4c_cli/pyproject.toml WORKDIR /opt/t4c_cli -RUN python -m venv .venv && source .venv/bin/activate && pip install --no-cache-dir . +RUN pip install --no-cache-dir . WORKDIR /opt ENV BASE_TYPE=t4c