Fokko closed pull request #3741: [AIRFLOW-1368] Add auto_remove for 
DockerOperator
URL: https://github.com/apache/incubator-airflow/pull/3741
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/operators/docker_operator.py 
b/airflow/operators/docker_operator.py
index 69dc1ebef7..72cd931793 100644
--- a/airflow/operators/docker_operator.py
+++ b/airflow/operators/docker_operator.py
@@ -66,6 +66,8 @@ class DockerOperator(BaseOperator):
     :type mem_limit: float or str
     :param network_mode: Network mode for the container.
     :type network_mode: str
+    :param auto_remove: Remove the container after execution. Default is false.
+    :type auto_remove: bool
     :param tls_ca_cert: Path to a PEM-encoded certificate authority
         to secure the docker connection.
     :type tls_ca_cert: str
@@ -127,10 +129,12 @@ def __init__(
             xcom_push=False,
             xcom_all=False,
             docker_conn_id=None,
+            auto_remove=False,
             *args,
             **kwargs):
 
         super(DockerOperator, self).__init__(*args, **kwargs)
+        self.auto_remove = auto_remove
         self.api_version = api_version
         self.command = command
         self.cpus = cpus
@@ -203,7 +207,8 @@ def execute(self, context):
                 host_config=self.cli.create_host_config(
                     binds=self.volumes,
                     network_mode=self.network_mode,
-                    shm_size=self.shm_size),
+                    shm_size=self.shm_size,
+                    auto_remove=self.auto_remove),
                 image=image,
                 mem_limit=self.mem_limit,
                 user=self.user,
diff --git a/tests/operators/docker_operator.py 
b/tests/operators/docker_operator.py
index 59d6d58416..0576842063 100644
--- a/tests/operators/docker_operator.py
+++ b/tests/operators/docker_operator.py
@@ -77,7 +77,8 @@ def test_execute(self, client_class_mock, mkdtemp_mock):
         
client_mock.create_host_config.assert_called_with(binds=['/host/path:/container/path',
                                                                  
'/mkdtemp:/tmp/airflow'],
                                                           
network_mode='bridge',
-                                                          shm_size=1000)
+                                                          shm_size=1000,
+                                                          auto_remove=False)
         client_mock.images.assert_called_with(name='ubuntu:latest')
         client_mock.logs.assert_called_with(container='some_id', stream=True)
         client_mock.pull.assert_called_with('ubuntu:latest', stream=True)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to