Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Docker compose root user problem #354 #355

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/tests/component-templates/fenics-adapter.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/component-templates/nutils-adapter.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/component-templates/openfoam-adapter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/docker-compose.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }}
Expand Down
21 changes: 21 additions & 0 deletions tools/tests/systemtests/Systemtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Loading