added definition
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
import uvicorn
|
||||||
|
from setup_logging import setup_logging
|
||||||
|
from app import app
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# setup
|
||||||
|
setup_logging()
|
||||||
|
listen_ip = os.getenv('LISTEN_IP', default='0.0.0.0')
|
||||||
|
listen_port = int(os.getenv('LISTEN_PORT', default=8000))
|
||||||
|
logging.info(f'starting FastAPI server ({listen_ip}:{listen_port})')
|
||||||
|
uvicorn.run(
|
||||||
|
app=app,
|
||||||
|
host=listen_ip,
|
||||||
|
port=listen_port
|
||||||
|
)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List
|
||||||
|
import yaml
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class RunnerScript(BaseModel):
|
||||||
|
script: List[str]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
path = Path(__file__).parent.parent / 'runner_script.yml'
|
||||||
|
with open(path, 'r') as fh:
|
||||||
|
script = yaml.safe_load(fh)
|
||||||
|
runner_script = RunnerScript.parse_obj(script)
|
||||||
|
print(runner_script)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
from pydantic import AnyHttpUrl
|
||||||
|
from typing import List
|
||||||
|
from pathlib import Path
|
||||||
|
from git import Repo
|
||||||
|
import logging
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
from runner_script import RunnerScript
|
||||||
|
|
||||||
|
def clone_repository(repo_url: AnyHttpUrl) -> Path:
|
||||||
|
# extract repo name
|
||||||
|
repo_name = repo_url.split('/')[-1].replace('.git', '')
|
||||||
|
repo_dir = os.getenv('REPO_DIR', default=None)
|
||||||
|
assert repo_dir is not None
|
||||||
|
dst_dir = Path(repo_dir) / repo_name
|
||||||
|
# prepare repo download dir
|
||||||
|
if dst_dir.exists():
|
||||||
|
shutil.rmtree(dst_dir)
|
||||||
|
dst_dir.mkdir()
|
||||||
|
# git clone repo
|
||||||
|
Repo.clone_from(url=repo_url, to_path=dst_dir)
|
||||||
|
logging.debug('finished')
|
||||||
|
return dst_dir
|
||||||
|
|
||||||
|
def load_runner_script(path: Path) -> RunnerScript:
|
||||||
|
assert path.exists()
|
||||||
|
with open(path, 'r') as fh:
|
||||||
|
script = yaml.safe_load(fh)
|
||||||
|
runner_script = RunnerScript.parse_obj(script)
|
||||||
|
logging.debug('finished')
|
||||||
|
return runner_script
|
||||||
|
|
||||||
Reference in New Issue
Block a user