示例#1
0
 def append(self):
     if notebook_helper.is_in_notebook():
         notebook_helper.export_notebook_to_tar_gz(
             self.notebook_file,
             TEMP_TAR_GZ_FILENAME,
             converted_filename=self.get_python_entrypoint())
     else:
         utils.generate_context_tarball(".", TEMP_TAR_GZ_FILENAME)
     transport = transport_pool.Http(httplib2.Http, size=_THREADS)
     src = docker_name.Tag(self.base_image)
     creds = docker_creds.DefaultKeychain.Resolve(src)
     with v2_2_image.FromRegistry(src, creds, transport) as src_image:
         with open(TEMP_TAR_GZ_FILENAME, 'rb') as f:
             new_img = append.Layer(src_image, f.read())
     if self.image_tag is None:
         self.image_tag = new_img.digest().split(":")[1]
     dst = docker_name.Tag(self.full_image_name())
     creds = docker_creds.DefaultKeychain.Resolve(dst)
     with docker_session.Push(dst,
                              creds,
                              transport,
                              threads=_THREADS,
                              mount=[src.as_repository()]) as session:
         logger.warn("Uploading {}".format(self.full_image_name()))
         session.upload(new_img)
     os.remove(TEMP_TAR_GZ_FILENAME)
     logger.warn("Pushed image {}".format(self.full_image_name()))
示例#2
0
 def get_python_entrypoint(self):
     entrypoint = sys.argv[0]
     if self.notebook_file is not None:
         entrypoint = os.path.basename(self.notebook_file)
     if notebook_helper.is_in_notebook() and entrypoint is None:
         entrypoint = notebook_helper.get_notebook_name()
     return entrypoint.replace('.ipynb', '.py')
示例#3
0
    def get_command(self):
        exec_file = ''
        if is_in_notebook():
            nb_name = get_notebook_name()
            exec_file = nb_name.replace('.ipynb', '.py')
        else:
            exec_file = self.get_exec_file_name()

        return "CMD python /app/{exec_file}".format(exec_file=exec_file)
示例#4
0
def get_mandatory_steps():
    steps = [
        "ENV FAIRING_RUNTIME 1", "RUN pip install fairing", "COPY ./ /app/",
        "RUN if [ -e /app/requirements.txt ]; then pip install --no-cache -r /app/requirements.txt; fi"
    ]

    if is_in_notebook():
        nb_name = get_notebook_name()
        steps += [
            "RUN pip install jupyter nbconvert",
            "RUN jupyter nbconvert --to script /app/{}".format(nb_name)
        ]
    return steps
示例#5
0
def get_command(exec_file=None):
    if exec_file is None and is_in_notebook():
        nb_name = get_notebook_name()
        exec_file = nb_name.replace('.ipynb', '.py')
    exec_file = get_exec_file_name()
    return "python /app/{exec_file}".format(exec_file=exec_file)