updated execution of script
This commit is contained in:
+21
-2
@@ -4,6 +4,7 @@ from fastapi.responses import HTMLResponse
|
||||
from dotenv import load_dotenv
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from utils import clone_repository, execute_runner_script
|
||||
from setup_logging import setup_logging
|
||||
@@ -54,15 +55,33 @@ def handle_event(request: GiteaRequest):
|
||||
# clone repository
|
||||
local_repo_dir = clone_repository(repo_url)
|
||||
# locate runner script
|
||||
runner_script_path = local_repo_dir / '.gitea' / 'gpu_runner' / 'script.yml'
|
||||
runner_script_path = (
|
||||
local_repo_dir /
|
||||
'.gitea' /
|
||||
'gpu_runner' /
|
||||
'script.yml'
|
||||
)
|
||||
if not runner_script_path.exists():
|
||||
raise HTTPException(
|
||||
status_code=200,
|
||||
detail="no runner_script.yml in repository root"
|
||||
)
|
||||
venv_dir = local_repo_dir / 'venv'
|
||||
try:
|
||||
# create virtualenv
|
||||
os.system(f'virtualenv -p python3.10 {venv_dir}')
|
||||
logging.info('created venv')
|
||||
os.system(f'source {venv_dir}/bin/activate')
|
||||
logging.info('activated venv')
|
||||
# execute runner script
|
||||
logging.info('rexecuting runner script')
|
||||
execute_runner_script(path=runner_script_path)
|
||||
except:
|
||||
logging.error('failed running script')
|
||||
finally:
|
||||
os.system('deactivate')
|
||||
logging.info('deactivated venv')
|
||||
shutil.rmtree(venv_dir)
|
||||
logging.info('removed venv')
|
||||
# # TODO: create virtualenv?
|
||||
# # install requirements
|
||||
# assert pipeline.requirements is not None
|
||||
|
||||
Reference in New Issue
Block a user