Blame SOURCES/backport-init-and-init_path-to-create_host_config.patch

a44080
From b1ec2f7d35ac1ba825eef2167ac7a59964ff47fe Mon Sep 17 00:00:00 2001
a44080
From: Tomas Tomecek <ttomecek@redhat.com>
a44080
Date: Fri, 22 Mar 2019 11:17:28 +0100
a44080
Subject: [PATCH] backport init and init_path to create_host_config
a44080
a44080
Resolves #1687227
a44080
a44080
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
a44080
---
a44080
 docker/utils/utils.py        |  6 ++++++
a44080
 docs/hostconfig.md           |  2 ++
a44080
 tests/unit/container_test.py | 24 ++++++++++++++++++++++++
a44080
 3 files changed, 32 insertions(+)
a44080
a44080
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
a44080
index 2a183a0..9053889 100644
a44080
--- a/docker/utils/utils.py
a44080
+++ b/docker/utils/utils.py
a44080
@@ -610,6 +610,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
a44080
                        shm_size=None, sysctls=None, version=None, tmpfs=None,
a44080
                        oom_score_adj=None, dns_opt=None, cpu_shares=None,
a44080
                        cpuset_cpus=None, userns_mode=None, pids_limit=None,
a44080
+                       init=None, init_path=None,
a44080
                        cpu_rt_period=None, cpu_rt_runtime=None):
a44080
 
a44080
     host_config = {}
a44080
@@ -918,6 +919,11 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
a44080
             )
a44080
         host_config['CPURealtimeRuntime'] = cpu_rt_runtime
a44080
 
a44080
+    if init is not None:
a44080
+        host_config['Init'] = init
a44080
+    if init_path is not None:
a44080
+        host_config['InitPath'] = init_path
a44080
+
a44080
     return host_config
a44080
 
a44080
 
a44080
diff --git a/docs/hostconfig.md b/docs/hostconfig.md
a44080
index c39a02c..b452a91 100644
a44080
--- a/docs/hostconfig.md
a44080
+++ b/docs/hostconfig.md
a44080
@@ -132,6 +132,8 @@ for example:
a44080
 * pids_limit (int): Tune a container’s pids limit. Set -1 for unlimited.
a44080
 * cpu_rt_runtime (int): Limit the CPU real-time runtime in microseconds.
a44080
 * cpu_rt_period (int): Limit the CPU real-time period in microseconds.
a44080
+* init (bool): Run an init inside the container that forwards signals and reaps processes.
a44080
+* init_path (str): Path to the docker-init binary.
a44080
 
a44080
 **Returns** (dict) HostConfig dictionary
a44080
 
a44080
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py
a44080
index 8c7b2c1..137e634 100644
a44080
--- a/tests/unit/container_test.py
a44080
+++ b/tests/unit/container_test.py
a44080
@@ -360,6 +360,30 @@ class CreateContainerTest(DockerClientTest):
a44080
                                "NetworkMode": "default"
a44080
                              }}'''))
a44080
 
a44080
+    def test_create_container_with_init(self):
a44080
+        self.client.create_container(
a44080
+            'busybox', 'ls', host_config=self.client.create_host_config(
a44080
+                init=True, init_path="/path/to/docker-init"
a44080
+            )
a44080
+        )
a44080
+
a44080
+        args = fake_request.call_args
a44080
+        self.assertEqual(args[0][1],
a44080
+                         url_prefix + 'containers/create')
a44080
+        self.assertEqual(json.loads(args[1]['data']),
a44080
+                         json.loads('''
a44080
+                            {"Tty": false, "Image": "busybox",
a44080
+                             "Cmd": ["ls"], "AttachStdin": false,
a44080
+                             "AttachStderr": true,
a44080
+                             "AttachStdout": true, "OpenStdin": false,
a44080
+                             "StdinOnce": false,
a44080
+                             "NetworkDisabled": false,
a44080
+                             "HostConfig": {
a44080
+                               "Init": true,
a44080
+                               "InitPath": "/path/to/docker-init",
a44080
+                               "NetworkMode": "default"
a44080
+                             }}'''))
a44080
+
a44080
     @requires_api_version('1.18')
a44080
     def test_create_container_with_host_config_cpuset(self):
a44080
         self.client.create_container(
a44080
-- 
a44080
2.20.1
a44080