Skip to content

Commit

Permalink
feat: Inject known pure::variants servers
Browse files Browse the repository at this point in the history
Specify known servers via the PURE_VARIANTS_KNOWN_SERVERS environment variable.
  • Loading branch information
MoritzWeber0 committed May 6, 2024
1 parent ba767ef commit 4b51fe9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ override:
info:
- DL3006
- DL3008
- DL3013
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
4 changes: 2 additions & 2 deletions capella/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
66 changes: 63 additions & 3 deletions pure-variants/setup_workspace_purevariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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'<?xml version\="1.0" encoding\="UTF-8"?>'
+ 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'<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>'
+ 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()
2 changes: 1 addition & 1 deletion t4c/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b51fe9

Please sign in to comment.