diff --git a/tools/tests/component-templates/fenics-adapter.yaml b/tools/tests/component-templates/fenics-adapter.yaml index 09cc1983c..c14bf877c 100644 --- a/tools/tests/component-templates/fenics-adapter.yaml +++ b/tools/tests/component-templates/fenics-adapter.yaml @@ -1,5 +1,5 @@ image: precice/fenics-adapter:{{ params["FENICS_ADAPTER_REF"] }} -user: ${UID}:${UID} +user: ${UID}:${GID} depends_on: prepare: condition: service_completed_successfully diff --git a/tools/tests/component-templates/nutils-adapter.yaml b/tools/tests/component-templates/nutils-adapter.yaml index d34ba460b..1c3f98a23 100644 --- a/tools/tests/component-templates/nutils-adapter.yaml +++ b/tools/tests/component-templates/nutils-adapter.yaml @@ -1,5 +1,5 @@ image: "ghcr.io/precice/openfoam-adapter:{{ params["openfoam-adapter-ref"] }}" # TODO: Update -user: ${MY_UID}:${MY_GID} +user: ${UID}:${GID} depends_on: prepare: condition: service_completed_successfully diff --git a/tools/tests/component-templates/openfoam-adapter.yaml b/tools/tests/component-templates/openfoam-adapter.yaml index 930dd6a73..a1df486b8 100644 --- a/tools/tests/component-templates/openfoam-adapter.yaml +++ b/tools/tests/component-templates/openfoam-adapter.yaml @@ -3,8 +3,8 @@ build: args: {% for key, value in build_args.items() %} - {{key}}={{value}} - {% endfor %} -user: ${UID}:${UID} + {% endfor %} +user: ${UID}:${GID} depends_on: prepare: condition: service_completed_successfully diff --git a/tools/tests/docker-compose.template.yaml b/tools/tests/docker-compose.template.yaml index eea20af27..79ad341cd 100644 --- a/tools/tests/docker-compose.template.yaml +++ b/tools/tests/docker-compose.template.yaml @@ -2,7 +2,7 @@ version: "3.9" services: prepare: image: ubuntu:latest - user: ${MY_UID}:${MY_GID} + user: ${UID}:${GID} volumes: - /etc/passwd:/etc/passwd:ro #TODO: Maybe move those into a more general section ? - /etc/group:/etc/group:ro @@ -15,7 +15,7 @@ services: sed -i 's|m2n:sockets from|m2n:sockets network=\"eth0\" from|g' precice-config.xml && cat precice-config.xml" - + {% for service in services %} {{ service }}: {{ services[service] |indent(4) }} diff --git a/tools/tests/systemtests/Systemtest.py b/tools/tests/systemtests/Systemtest.py index 9d9270e91..86647abdc 100644 --- a/tools/tests/systemtests/Systemtest.py +++ b/tools/tests/systemtests/Systemtest.py @@ -72,9 +72,11 @@ class Systemtest: cmd_line_args: CmdLineArguments cases: Tuple[Case] params_to_use: Dict[str, str] = field(init=False) + env: Dict[str, str] = field(init=False) def __post_init__(self): self.__init_args_to_use() + self.env = {} def __init_args_to_use(self): """ @@ -173,6 +175,21 @@ def __copy_tools(self, run_directory: Path): def __cleanup(self): shutil.rmtree(self.run_directory) + def __get_uid_gid(self): + try: + uid = int(subprocess.check_output(["id", "-u"]).strip()) + gid = int(subprocess.check_output(["id", "-g"]).strip()) + return uid, gid + except Exception as e: + # Handle the exception if the 'id -u' or 'id -g' commands fail + # For example, you can return default values or raise an error. + print("Error getting group and user id: ", e) + + def __write_env_file(self): + with open(self.system_test_dir / ".env", "w") as env_file: + for key, value in self.env.items(): + env_file.write(f"{key}={value}\n") + def _run_field_compare(self): """ Writes the Docker Compose file to disk, executes docker-compose up, and handles the process output. @@ -284,6 +301,10 @@ def run(self, run_directory: Path): self.__copy_tools(run_directory) std_out: List[str] = [] std_err: List[str] = [] + uid, gid = self.__get_uid_gid() + self.env["UID"] = uid + self.env["GID"] = gid + self.__write_env_file() docker_compose_result = self._run_tutorial() std_out.extend(docker_compose_result.stdout_data) std_err.extend(docker_compose_result.stderr_data)