Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c19fc58a25 | ||
|
|
bd5dc8fbc4 | ||
|
|
f4a81b4b9b | ||
|
|
477389d353 | ||
|
|
90a44e8b6e | ||
|
|
36d2233567 | ||
|
|
2fc979a845 | ||
|
|
7218004f2f | ||
|
|
75fd57391d | ||
|
|
a82e0a8f10 | ||
|
|
d1864c7030 | ||
|
|
43e4b9788a | ||
|
|
84b409356b |
+13
-4
@@ -24,10 +24,12 @@ RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requir
|
|||||||
# pull official base image
|
# pull official base image
|
||||||
FROM dvcorg/cml:0-dvc2-base1-gpu
|
FROM dvcorg/cml:0-dvc2-base1-gpu
|
||||||
|
|
||||||
# create app home
|
# create home directory and app user
|
||||||
ENV APP_HOME = /home/app
|
RUN mkdir -p /home/app && \
|
||||||
RUN mkdir -p $APP_HOME
|
addgroup --system app && \
|
||||||
WORKDIR $APP_HOME
|
adduser --system --group app
|
||||||
|
|
||||||
|
# add folder to store repo in
|
||||||
RUN mkdir -p /home/app/repo
|
RUN mkdir -p /home/app/repo
|
||||||
|
|
||||||
# install packages from builder
|
# install packages from builder
|
||||||
@@ -36,7 +38,14 @@ COPY --from=builder /usr/src/app/requirements.txt requirements.txt
|
|||||||
RUN pip install --no-cache /wheels/*
|
RUN pip install --no-cache /wheels/*
|
||||||
|
|
||||||
# copy in files
|
# copy in files
|
||||||
|
WORKDIR /home/app
|
||||||
COPY ./code .
|
COPY ./code .
|
||||||
|
|
||||||
|
# change ownership to app user
|
||||||
|
RUN chown -R app:app /home/app
|
||||||
|
|
||||||
|
# change to the app user
|
||||||
|
USER app
|
||||||
|
|
||||||
# start execution
|
# start execution
|
||||||
ENTRYPOINT [ "python", "main.py" ]
|
ENTRYPOINT [ "python", "main.py" ]
|
||||||
+32
-9
@@ -39,18 +39,18 @@ async def test(request: Request):
|
|||||||
@app.post('/event')
|
@app.post('/event')
|
||||||
def handle_event(request: GiteaRequest):
|
def handle_event(request: GiteaRequest):
|
||||||
""" Handle event from webhook. """
|
""" Handle event from webhook. """
|
||||||
# stop early if asked
|
# extract information
|
||||||
commit_msg = request.head_commit['message']
|
commit_msg = request.head_commit['message']
|
||||||
|
repo_url = request.repository['clone_url']
|
||||||
|
branch_name = request.ref.split('/')[-1]
|
||||||
|
# stop early if asked
|
||||||
if commit_msg.lower().startswith('[skip ci]'):
|
if commit_msg.lower().startswith('[skip ci]'):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=200,
|
status_code=200,
|
||||||
detail='skipping ci'
|
detail='skipping ci'
|
||||||
)
|
)
|
||||||
# clone repository
|
# clone repository
|
||||||
repo_url = request.repository['clone_url']
|
|
||||||
logging.info('cloning repository: {repo_url}')
|
|
||||||
local_repo_dir = clone_repository(repo_url)
|
local_repo_dir = clone_repository(repo_url)
|
||||||
logging.info(f'local_repo_dir: {local_repo_dir}')
|
|
||||||
# locate runner script
|
# locate runner script
|
||||||
runner_script_path = local_repo_dir / 'runner_script.yml'
|
runner_script_path = local_repo_dir / 'runner_script.yml'
|
||||||
if not runner_script_path.exists():
|
if not runner_script_path.exists():
|
||||||
@@ -58,17 +58,40 @@ def handle_event(request: GiteaRequest):
|
|||||||
status_code=200,
|
status_code=200,
|
||||||
detail="no runner_script.yml in repository root"
|
detail="no runner_script.yml in repository root"
|
||||||
)
|
)
|
||||||
# load runner commands
|
# load runner script
|
||||||
runner_script = load_runner_script(path=runner_script_path)
|
runner_script = load_runner_script(path=runner_script_path)
|
||||||
for pipeline_name, pipeline_step in runner_script.pipelines.items():
|
# determine pipeline to run
|
||||||
print(pipeline_name)
|
if branch_name not in runner_script.pipelines.keys():
|
||||||
print(pipeline_step)
|
# get default pipeline
|
||||||
|
if 'default' not in runner_script.pipelines.keys():
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=404,
|
||||||
|
detail='no pipelines defined in runner_script.yml'
|
||||||
|
)
|
||||||
|
pipeline = runner_script.pipelines['default']
|
||||||
|
else:
|
||||||
|
# get custom pipeline
|
||||||
|
pipeline = runner_script.pipelines[branch_name]
|
||||||
|
logging.info(f'running pipeline {pipeline.name}')
|
||||||
|
# TODO: create virtualenv?
|
||||||
|
# install requirements
|
||||||
|
assert pipeline.requirements is not None
|
||||||
|
requirements_path = local_repo_dir / pipeline.requirements
|
||||||
|
os.system(f'pip install -r {requirements_path}')
|
||||||
|
for cmd in pipeline.script:
|
||||||
|
try:
|
||||||
|
os.system(cmd)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=503,
|
||||||
|
detail=f'failed running {cmd}: {e}'
|
||||||
|
)
|
||||||
# send response
|
# send response
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=202,
|
status_code=202,
|
||||||
detail='received task'
|
detail='received task'
|
||||||
)
|
)
|
||||||
|
# consider to include link to page that show progress
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
load_dotenv('dev.env')
|
load_dotenv('dev.env')
|
||||||
|
|||||||
@@ -28,5 +28,6 @@ def load_runner_script(path: Path) -> RunnerScript:
|
|||||||
with open(path, 'r') as fh:
|
with open(path, 'r') as fh:
|
||||||
script = yaml.safe_load(fh)
|
script = yaml.safe_load(fh)
|
||||||
runner_script = RunnerScript.parse_obj(script)
|
runner_script = RunnerScript.parse_obj(script)
|
||||||
|
logging.debug('finished')
|
||||||
return runner_script
|
return runner_script
|
||||||
|
|
||||||
+8
-1
@@ -10,4 +10,11 @@ services:
|
|||||||
- LOGGER_LEVEL=debug
|
- LOGGER_LEVEL=debug
|
||||||
- LISTEN_IP=0.0.0.0
|
- LISTEN_IP=0.0.0.0
|
||||||
- LISTEN_PORT=8000
|
- LISTEN_PORT=8000
|
||||||
- REPO_DIR=/home/app/repo/
|
- REPO_DIR=/home/app/repo/
|
||||||
|
# deploy:
|
||||||
|
# resources:
|
||||||
|
# reservations:
|
||||||
|
# devices:
|
||||||
|
# - driver: nvidia
|
||||||
|
# device_ids: ['0']
|
||||||
|
# capabilities: [gpu]
|
||||||
+1
-2
@@ -4,8 +4,7 @@ definitions:
|
|||||||
name: test
|
name: test
|
||||||
requirements: req-prod.txt
|
requirements: req-prod.txt
|
||||||
script:
|
script:
|
||||||
- command arg1 arg2
|
- nvidia-smi
|
||||||
- command2 arg1 arg2
|
|
||||||
|
|
||||||
pipelines:
|
pipelines:
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user