Docker env, added save&exit step

This commit is contained in:
Ivan Gromov 2020-05-16 02:16:18 +05:00
parent 89c2330b80
commit dd2a05a96c
6 changed files with 66 additions and 3 deletions

6
app/.dockerignore Normal file
View file

@ -0,0 +1,6 @@
*
!requirements.txt
!playbook.py
!server.py
!run.sh
!static

10
app/Dockerfile Normal file
View file

@ -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" ]

25
app/run.sh Normal file
View file

@ -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}

View file

@ -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)

View file

@ -61,7 +61,10 @@
😢 Set up failed
</h1>
<h1 class="mb-5 text-center" v-if="step === 'status-done'">
🥳 Congratulations! Your Algo server is running.
🥳 Congratulations, your Algo server is running!
</h1>
<h1 class="mb-5 text-center" v-if="step === 'status-exit'">
Config files are saved, bye!
</h1>
</h1>
<transition name="fade">
@ -99,7 +102,8 @@
</section>
</transition>
<transition name="fade">
<status-done v-if="step == 'status-done'">
<status-done v-if="step == 'status-done'"
v-on:submit="exit(); step = 'status-exit'" >
</status-done>
</transition>
</div>
@ -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"
});
}
}
})

View file

@ -36,6 +36,12 @@
</div>
</div>
</section>
<section>
<h2 class="text-center">Finish setup and save configs</h2>
<p class="text-center">
<button v-on:click="$emit('submit')" class="btn btn-primary btn-lg" type="button">Save &amp; Exit</button>
</p>
</section>
</div>
</template>