diff --git a/app/.dockerignore b/app/.dockerignore new file mode 100644 index 0000000..d34f8d4 --- /dev/null +++ b/app/.dockerignore @@ -0,0 +1,6 @@ +* +!requirements.txt +!playbook.py +!server.py +!run.sh +!static diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..f4b7830 --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,10 @@ +FROM algo +ARG BUILD_PACKAGES="gcc libffi-dev linux-headers make musl-dev openssl-dev" +COPY requirements.txt /app/requirements.txt +RUN apk --no-cache add ${BUILD_PACKAGES} && \ + source .env/bin/activate && \ + python3 -m pip --no-cache-dir install -r app/requirements.txt && \ + apk del ${BUILD_PACKAGES} +COPY . app +RUN chmod 0755 /algo/app/run.sh +CMD [ "/algo/app/run.sh" ] diff --git a/app/run.sh b/app/run.sh new file mode 100644 index 0000000..c9c736b --- /dev/null +++ b/app/run.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -e + +ALGO_DIR="/algo" +DATA_DIR="/data" + +if [ -z ${VIRTUAL_ENV+x} ] +then + ACTIVATE_SCRIPT="/algo/.env/bin/activate" + if [ -f "$ACTIVATE_SCRIPT" ] + then + # shellcheck source=/dev/null + source "$ACTIVATE_SCRIPT" + else + echo "$ACTIVATE_SCRIPT not found. Did you follow documentation to install dependencies?" + exit 1 + fi +fi + +tr -d '\r' < "${DATA_DIR}"/config.cfg > "${ALGO_DIR}"/config.cfg +test -d "${DATA_DIR}"/configs && rsync -qLktr --delete "${DATA_DIR}"/configs "${ALGO_DIR}"/ +python app/server.py +rsync -qLktr --delete "${ALGO_DIR}"/configs "${DATA_DIR}"/ +exit ${retcode} diff --git a/app/server.py b/app/server.py index 2c2c1a8..ad15339 100644 --- a/app/server.py +++ b/app/server.py @@ -3,6 +3,7 @@ import yaml from os.path import join, dirname from aiohttp import web import concurrent.futures +import sys from playbook import PlaybookCLI @@ -85,6 +86,12 @@ async def post_config(request): f.write(config) return web.json_response({'ok': True}) +@routes.post('/exit') +async def post_exit(_): + if task_future and task_future.done(): + sys.exit(0) + else: + sys.exit(1) app = web.Application() app.router.add_routes(routes) diff --git a/app/static/index.html b/app/static/index.html index 5e7c03c..4d0d3b3 100644 --- a/app/static/index.html +++ b/app/static/index.html @@ -61,7 +61,10 @@ 😢 Set up failed

- 🥳 Congratulations! Your Algo server is running. + 🥳 Congratulations, your Algo server is running! +

+

+ Config files are saved, bye!

@@ -99,7 +102,8 @@ - + @@ -126,7 +130,7 @@ 'provider-setup': window.httpVueLoader('/static/provider-setup.vue'), 'command-preview': window.httpVueLoader('/static/command-preview.vue'), 'status-running': window.httpVueLoader('/static/status-running.vue'), - 'status-done': window.httpVueLoader('/static/status-done.vue'), + 'status-done': window.httpVueLoader('/static/status-done.vue') }, created() { fetch("/playbook") @@ -154,6 +158,11 @@ fetch("/playbook", { method: "DELETE" }); + }, + exit() { + fetch("/exit", { + method: "POST" + }); } } }) diff --git a/app/static/status-done.vue b/app/static/status-done.vue index 3a51e5a..5391163 100644 --- a/app/static/status-done.vue +++ b/app/static/status-done.vue @@ -36,6 +36,12 @@ +
+

Finish setup and save configs

+

+ +

+