44from piper .base .docker import PythonImage
55from piper .configurations import get_configuration
66from piper .envs import get_env , is_current_env , is_docker_env
7- from piper .utils import docker_utils as du
7+ from piper .utils import docker_utils
88
99import inspect
10- import os
1110import sys
1211import time
1312from abc import ABC , abstractmethod
14- from distutils .command .config import config
1513from typing import Dict
14+ from distutils .dir_util import copy_tree
1615
1716import aiohttp
1817import docker
1918import requests
20- from loguru import logger
2119from pydantic import BaseModel # , BytesObject, ListOfStringsObject
2220
21+ from piper .utils .logger_utils import logger
22+
2323
2424class BaseExecutor :
2525 pass
@@ -88,7 +88,6 @@ async def __call__(self, *args, **kwargs):
8888
8989def copy_piper (path : str ):
9090 cfg = get_configuration ()
91- from distutils .dir_util import copy_tree
9291 copy_tree (cfg .piper_path , f"{ path } piper" )
9392
9493
@@ -107,7 +106,8 @@ def write_requirements(path, requirements):
107106def build_image (path : str , docker_image ):
108107 client = docker .DockerClient (base_url = 'unix://var/run/docker.sock' )
109108 image = docker_image .render ()
110- with open (f"{ path } /Dockerfile" , "w" ) as output :
109+ print (f"{ path } Dockerfile" )
110+ with open (f"{ path } Dockerfile" , "w" ) as output :
111111 output .write (image )
112112
113113 image , logs = client .images .build (path = path ,
@@ -146,6 +146,7 @@ def wait_for_fast_api_app_start(host, external_port, wait_on_iter, n_iters):
146146 if r .status_code == 200 :
147147 break
148148 except Exception as e :
149+ logger .error (f"Exception while starting FastAPI app { e } " )
149150 time .sleep (wait_on_iter )
150151
151152 if i == n_iters :
@@ -170,12 +171,15 @@ def __init__(self, port: int = 8080, **service_kwargs):
170171
171172 copy_piper (project_output_path )
172173 copy_scripts (project_output_path , self .scripts ())
173- # build_image(project_output_path, docker_image)
174174 self .create_fast_api_files (project_output_path , ** service_kwargs )
175175
176+ docker_image = PythonImage (self .image_tag , "3.9" , cmd = f"./run.sh" , template_file = 'default-python.j2' ,
177+ run_rows = "" , post_install_lines = "" )
178+ build_image (project_output_path , docker_image )
179+
176180 # create and run docker container
177181 # if container exits it will be recreated!
178- du .create_image_and_container_by_dockerfile (
182+ docker_utils .create_image_and_container_by_dockerfile (
179183 docker_client ,
180184 project_output_path ,
181185 self .image_tag ,
@@ -206,14 +210,13 @@ def create_fast_api_files(self, path: str, **service_kwargs):
206210 function_name = self .base_handler ,
207211 request_model = "StringValue" ,
208212 response_model = "StringValue" )
209-
210213 with open (f"{ path } /main.py" , "w" ) as output :
211214 output .write (backend )
212215
213216 write_requirements (path , self .requirements )
214217
215218 gunicorn = "#!/bin/bash \n " \
216- f"gunicorn -b 0.0.0.0:8080 --workers { cfg .n_gunicorn_workers } main:app --worker-class uvicorn.workers.UvicornWorker --preload --timeout 120 --reload=True "
219+ f"gunicorn -b 0.0.0.0:8080 --workers { cfg .n_gunicorn_workers } main:app --worker-class uvicorn.workers.UvicornWorker --preload --timeout 120"
217220 with open (f"{ path } /run.sh" , "w" ) as output :
218221 output .write (gunicorn )
219222
@@ -257,7 +260,7 @@ def __init__(self, port: int = 8080, **service_kwargs):
257260
258261 # create and run docker container
259262 # if container exits it will be recreated!
260- du .create_image_and_container_by_dockerfile (
263+ docker_utils .create_image_and_container_by_dockerfile (
261264 docker_client ,
262265 project_output_path ,
263266 self .image_tag ,
0 commit comments