Merge pull request #1573 from kazkansouh/2.2-docker-user

Support for docker images that set the USER directive (+test coverage)
This commit is contained in:
Jeremy Grossmann authored and GitHub committed 2019-04-05 19:00:22 +08:00
commit 474e184646
3 files changed
+55 -5

No files matched your search

+7 -2
View File
@@ -319,7 +319,7 @@ class DockerVM(BaseNode):
"Volumes": {},
"Env": ["container=docker"], # Systemd compliant: https://github.com/GNS3/gns3-server/issues/573
"Cmd": [],
"Entrypoint": image_infos.get("Config", {"Entrypoint": []})["Entrypoint"]
"Entrypoint": image_infos.get("Config", {"Entrypoint": []}).get("Entrypoint")
}
if params["Entrypoint"] is None:
@@ -330,7 +330,7 @@ class DockerVM(BaseNode):
except ValueError as e:
raise DockerError("Invalid start command '{}': {}".format(self._start_command, e))
if len(params["Cmd"]) == 0:
params["Cmd"] = image_infos.get("Config", {"Cmd": []})["Cmd"]
params["Cmd"] = image_infos.get("Config", {"Cmd": []}).get("Cmd")
if params["Cmd"] is None:
params["Cmd"] = []
if len(params["Cmd"]) == 0 and len(params["Entrypoint"]) == 0:
@@ -342,6 +342,11 @@ class DockerVM(BaseNode):
# Give the information to the container the list of volume path mounted
params["Env"].append("GNS3_VOLUMES={}".format(":".join(self._volumes)))
# Pass user configured for image to init script
if image_infos.get("Config", {"User": ""}).get("User"):
params["User"] = "root"
params["Env"].append("GNS3_USER={}".format(image_infos.get("Config", {"User": ""})["User"]))
variables = self.project.variables
if not variables:
variables = []
+6 -3
View File
@@ -87,6 +87,9 @@ done
ifup -a -f
# continue normal docker startup
PATH="$OLD_PATH"
exec "$@"
GNS3_CMD="PATH=$OLD_PATH exec"
while test "$#" -gt 0 ; do
GNS3_CMD="${GNS3_CMD} \"${1//\"/\\\"}\""
shift
done
exec su ${GNS3_USER-root} -p -c "$GNS3_CMD"