From 730d82868153c39fbc99808275751351614168b3 Mon Sep 17 00:00:00 2001 From: Junaid Ebrahim Date: Wed, 10 Mar 2021 15:04:07 +0200 Subject: [PATCH] Docker enhancement to grant the user the ability to modify the container create Why: Several use cases require the need to alter the docker container create 1. Running systemd containers require special binds plus a custom termination signal 2. Running systemd in sysbox containers require custom runtime as well as Privileged=false 3. Many other use cases exist and will only grow as Docker becomes even more commonplace This change addresses the need by: 1. Adding a custom textedit to the Docker container Advanced tab 2. Adding the custom fields to the GNS3 schemas and objects 3. Adding logic to the Docker create function to merge the custom parameters NB: This change is depenant on modifications to both gns3-gui and gns3-server --- gns3/modules/docker/docker_vm.py | 3 +- .../pages/docker_vm_configuration_page.py | 2 + .../pages/docker_vm_preferences_page.py | 3 ++ gns3/modules/docker/settings.py | 1 + .../docker/ui/docker_vm_configuration_page.ui | 53 +++++++++++++++---- .../ui/docker_vm_configuration_page_ui.py | 36 ++++++++++++- 6 files changed, 86 insertions(+), 12 deletions(-) diff --git a/gns3/modules/docker/docker_vm.py b/gns3/modules/docker/docker_vm.py index c3e59cc26..883f33b5b 100644 --- a/gns3/modules/docker/docker_vm.py +++ b/gns3/modules/docker/docker_vm.py @@ -52,7 +52,8 @@ def __init__(self, module, server, project): "console_http_port": DOCKER_CONTAINER_SETTINGS["console_http_port"], "console_http_path": DOCKER_CONTAINER_SETTINGS["console_http_path"], "extra_hosts": DOCKER_CONTAINER_SETTINGS["extra_hosts"], - "extra_volumes": DOCKER_CONTAINER_SETTINGS["extra_volumes"]} + "extra_volumes": DOCKER_CONTAINER_SETTINGS["extra_volumes"], + "extra_parameters": DOCKER_CONTAINER_SETTINGS["extra_parameters"]} self.settings().update(docker_vm_settings) diff --git a/gns3/modules/docker/pages/docker_vm_configuration_page.py b/gns3/modules/docker/pages/docker_vm_configuration_page.py index 76b29e619..43dc2f4b6 100644 --- a/gns3/modules/docker/pages/docker_vm_configuration_page.py +++ b/gns3/modules/docker/pages/docker_vm_configuration_page.py @@ -105,6 +105,7 @@ def loadSettings(self, settings, node=None, group=False): self.uiHttpConsolePathLineEdit.setText(settings["console_http_path"]) self.uiExtraHostsTextEdit.setPlainText(settings["extra_hosts"]) self.uiExtraVolumeTextEdit.setPlainText("\n".join(settings["extra_volumes"])) + self.uiExtraParametersTextEdit.setPlainText(settings["extra_parameters"]) if not group: self.uiNameLineEdit.setText(settings["name"]) @@ -178,6 +179,7 @@ def saveSettings(self, settings, node=None, group=False): settings["extra_hosts"] = self.uiExtraHostsTextEdit.toPlainText() # only tidy input here, validation is performed server side settings["extra_volumes"] = [ y for x in self.uiExtraVolumeTextEdit.toPlainText().split("\n") for y in [ x.strip() ] if y ] + settings["extra_parameters"] = self.uiExtraParametersTextEdit.toPlainText() if not group: adapters = self.uiAdapterSpinBox.value() diff --git a/gns3/modules/docker/pages/docker_vm_preferences_page.py b/gns3/modules/docker/pages/docker_vm_preferences_page.py index 16ae4dc34..35d2eb541 100644 --- a/gns3/modules/docker/pages/docker_vm_preferences_page.py +++ b/gns3/modules/docker/pages/docker_vm_preferences_page.py @@ -97,6 +97,9 @@ def _refreshInfo(self, docker_container): if docker_container["extra_volumes"]: QtWidgets.QTreeWidgetItem(section_item, ["Extra volumes:", "\n".join(docker_container["extra_volumes"])]) + + if docker_container["extra_parameters"]: + QtWidgets.QTreeWidgetItem(section_item, ["Extra parameters:", str(docker_container["extra_parameters"])]) self.uiDockerVMInfoTreeWidget.expandAll() self.uiDockerVMInfoTreeWidget.resizeColumnToContents(0) diff --git a/gns3/modules/docker/settings.py b/gns3/modules/docker/settings.py index 0ae3c8ac2..33edf2cb2 100644 --- a/gns3/modules/docker/settings.py +++ b/gns3/modules/docker/settings.py @@ -44,5 +44,6 @@ "console_http_path": "/", "extra_hosts": "", "extra_volumes": [], + "extra_parameters": "", "node_type": "docker" } diff --git a/gns3/modules/docker/ui/docker_vm_configuration_page.ui b/gns3/modules/docker/ui/docker_vm_configuration_page.ui index ad5c56168..ce4a467f1 100644 --- a/gns3/modules/docker/ui/docker_vm_configuration_page.ui +++ b/gns3/modules/docker/ui/docker_vm_configuration_page.ui @@ -17,7 +17,7 @@ - 0 + 1 @@ -324,18 +324,53 @@ directory per line. - - - - Qt::Vertical - - + + + - 20 + 10 388 - + + Modify parameters to +create the container +using the JSON format of +the Docker API, use only +if you have a specific +requirement e.g. systemd. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + e.g. systemd +{ + "StopSignal": "SIGRTMIN+3", + "HostConfig": { + "CapAdd": ["ALL"], + "Runtime": "runc", + "Privileged": true, + "Binds": [ + "/sys/fs/cgroup:/sys/fs/cgroup:ro", + "/sys/fs/fuse:/sys/fs/fuse" + ], + "Tmpfs": { + "/tmp": "", + "/run": "", + "/run/lock": "" + } + } +} + + diff --git a/gns3/modules/docker/ui/docker_vm_configuration_page_ui.py b/gns3/modules/docker/ui/docker_vm_configuration_page_ui.py index a741f6989..37535e72a 100644 --- a/gns3/modules/docker/ui/docker_vm_configuration_page_ui.py +++ b/gns3/modules/docker/ui/docker_vm_configuration_page_ui.py @@ -153,8 +153,16 @@ def setupUi(self, dockerVMConfigPageWidget): self.uiExtraVolumeTextEdit.setPlainText("") self.uiExtraVolumeTextEdit.setObjectName("uiExtraVolumeTextEdit") self.gridLayout_2.addWidget(self.uiExtraVolumeTextEdit, 1, 1, 1, 1) - spacerItem = QtWidgets.QSpacerItem(20, 388, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) - self.gridLayout_2.addItem(spacerItem, 2, 1, 1, 1) + + self.uiExtraParametersLabel = QtWidgets.QLabel(self.tab_2) + self.uiExtraParametersLabel.setObjectName("uiExtraParametersLabel") + self.uiExtraParametersLabel.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignLeading | QtCore.Qt.AlignTop) + self.gridLayout_2.addWidget(self.uiExtraParametersLabel, 2, 0, 1, 1) + + self.uiExtraParametersTextEdit = QtWidgets.QPlainTextEdit(self.tab_2) + self.uiExtraParametersTextEdit.setPlainText("") + self.uiExtraParametersTextEdit.setObjectName("uiExtraParametersTextEdit") + self.gridLayout_2.addWidget(self.uiExtraParametersTextEdit, 2, 1, 1, 1) self.uiTabWidget.addTab(self.tab_2, "") self.tab_3 = QtWidgets.QWidget() self.tab_3.setObjectName("tab_3") @@ -215,6 +223,30 @@ def retranslateUi(self, dockerVMConfigPageWidget): "VOLUMES config. One\n" "directory per line.")) self.uiExtraVolumeTextEdit.setPlaceholderText(_translate("dockerVMConfigPageWidget", "e.g. /etc/sysctl.d")) + self.uiExtraParametersLabel.setText(_translate("dockerVMConfigPageWidget", "Modify parameters to\n" +"create the container\n" +"using the JSON format of\n" +"the Docker API, use only\n" +"if you have a specific\n" +"requirement")) + self.uiExtraParametersTextEdit.setPlaceholderText(_translate("dockerVMConfigPageWidget", """e.g. systemd +{ + "StopSignal": "SIGRTMIN+3", + "HostConfig": { + "CapAdd": ["ALL"], + "Runtime": "runc", + "Privileged": true, + "Binds": [ + "/sys/fs/cgroup:/sys/fs/cgroup:ro", + "/sys/fs/fuse:/sys/fs/fuse" + ], + "Tmpfs": { + "/tmp": "", + "/run": "", + "/run/lock": "" + } + } +}""")) self.uiTabWidget.setTabText(self.uiTabWidget.indexOf(self.tab_2), _translate("dockerVMConfigPageWidget", "Advanced")) self.uiTabWidget.setTabText(self.uiTabWidget.indexOf(self.tab_3), _translate("dockerVMConfigPageWidget", "Usage"))