4
4
from piper .base .docker import PythonImage
5
5
from piper .configurations import get_configuration
6
6
from 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
8
8
9
9
import inspect
10
- import os
11
10
import sys
12
11
import time
13
12
from abc import ABC , abstractmethod
14
- from distutils .command .config import config
15
13
from typing import Dict
14
+ from distutils .dir_util import copy_tree
16
15
17
16
import aiohttp
18
17
import docker
19
18
import requests
20
- from loguru import logger
21
19
from pydantic import BaseModel # , BytesObject, ListOfStringsObject
22
20
21
+ from piper .utils .logger_utils import logger
22
+
23
23
24
24
class BaseExecutor :
25
25
pass
@@ -88,7 +88,6 @@ async def __call__(self, *args, **kwargs):
88
88
89
89
def copy_piper (path : str ):
90
90
cfg = get_configuration ()
91
- from distutils .dir_util import copy_tree
92
91
copy_tree (cfg .piper_path , f"{ path } piper" )
93
92
94
93
@@ -107,7 +106,8 @@ def write_requirements(path, requirements):
107
106
def build_image (path : str , docker_image ):
108
107
client = docker .DockerClient (base_url = 'unix://var/run/docker.sock' )
109
108
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 :
111
111
output .write (image )
112
112
113
113
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):
146
146
if r .status_code == 200 :
147
147
break
148
148
except Exception as e :
149
+ logger .error (f"Exception while starting FastAPI app { e } " )
149
150
time .sleep (wait_on_iter )
150
151
151
152
if i == n_iters :
@@ -170,12 +171,15 @@ def __init__(self, port: int = 8080, **service_kwargs):
170
171
171
172
copy_piper (project_output_path )
172
173
copy_scripts (project_output_path , self .scripts ())
173
- # build_image(project_output_path, docker_image)
174
174
self .create_fast_api_files (project_output_path , ** service_kwargs )
175
175
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
+
176
180
# create and run docker container
177
181
# if container exits it will be recreated!
178
- du .create_image_and_container_by_dockerfile (
182
+ docker_utils .create_image_and_container_by_dockerfile (
179
183
docker_client ,
180
184
project_output_path ,
181
185
self .image_tag ,
@@ -206,14 +210,13 @@ def create_fast_api_files(self, path: str, **service_kwargs):
206
210
function_name = self .base_handler ,
207
211
request_model = "StringValue" ,
208
212
response_model = "StringValue" )
209
-
210
213
with open (f"{ path } /main.py" , "w" ) as output :
211
214
output .write (backend )
212
215
213
216
write_requirements (path , self .requirements )
214
217
215
218
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"
217
220
with open (f"{ path } /run.sh" , "w" ) as output :
218
221
output .write (gunicorn )
219
222
@@ -257,7 +260,7 @@ def __init__(self, port: int = 8080, **service_kwargs):
257
260
258
261
# create and run docker container
259
262
# if container exits it will be recreated!
260
- du .create_image_and_container_by_dockerfile (
263
+ docker_utils .create_image_and_container_by_dockerfile (
261
264
docker_client ,
262
265
project_output_path ,
263
266
self .image_tag ,
0 commit comments