mik-laj commented on a change in pull request #4846: [AIRFLOW-4030] adding 
start to singularity for airflow
URL: https://github.com/apache/airflow/pull/4846#discussion_r263609499
 
 

 ##########
 File path: airflow/operators/singularity_operator.py
 ##########
 @@ -0,0 +1,179 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import json
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.utils.decorators import apply_defaults
+from airflow.utils.file import TemporaryDirectory
+from spython.main import Client
+import shutil
+import ast
+import os
+
+
+class SingularityOperator(BaseOperator):
+    """
+    Execute a command inside a Singularity container
+
+    Singularity has more seamless connection to the host than Docker, so
+    no special binds are needed to ensure binding content in the user $HOME
+    and temporary directories. If the user needs custom binds, this can
+    be done with --volumes
+
+    :param image: Singularity image or URI from which to create the container.
+    :type image: str
+    :param auto_remove: Delete the container when the process exits
+                        The default is False.
+    :type auto_remove: bool
+    :param command: Command to be run in the container. (templated)
+    :type command: str or list
+    :param start_command: start command to pass to the container instance
+    :type start_command: string or list
+    :param environment: Environment variables to set in the container. 
(templated)
+    :type environment: dict
+    :param force_pull: Pull the image on every run. Default is False.
+    :type force_pull: bool
+    :param volumes: List of volumes to mount into the container, e.g.
+        ``['/host/path:/container/path', '/host/path2:/container/path2']``.
+    :param options: other flags (list) to provide to the instance start
+    :type options: list
+    :param working_dir: Working directory to
+        set on the container (equivalent to the -w switch the docker client)
+    :type working_dir: str
+    """
+    template_fields = ('command', 'environment',)
+    template_ext = ('.sh', '.bash',)
+
+    @apply_defaults
+    def __init__(
+            self,
+            image,
+            api_version=None,
+            command=None,
+            start_command=None,
+            environment=None,
+            pull_folder=None,
+            force_pull=False,
+            volumes=None,
+            options = None,
+            working_dir=None,
+            auto_remove=False,
+            *args,
+            **kwargs):
+
+        super(SingularityOperator, self).__init__(*args, **kwargs)
+        self.api_version = api_version
+        self.auto_remove = auto_remove
+        self.command = command
+        self.start_command = start_command
+        self.environment = environment or {}
+        self.force_pull = force_pull
+        self.image = image
+        self.instance = None
+        self.options = options or []
+        self.volumes = volumes or []
+        self.working_dir = working_dir
+        self.cli = None
+        self.container = None
+
+    def execute(self, context):
+        self.log.info('Preparing Singularity container %s', self.image)
+        self.cli = Client
 
 Review comment:
   The operator should not call the external library directly. It is 
recommended to introduce an intermediate layer - hook.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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