Skip to content

Commit dd2a05a

Browse files
committed
Docker env, added save&exit step
1 parent 89c2330 commit dd2a05a

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

app/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!requirements.txt
3+
!playbook.py
4+
!server.py
5+
!run.sh
6+
!static

app/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM algo
2+
ARG BUILD_PACKAGES="gcc libffi-dev linux-headers make musl-dev openssl-dev"
3+
COPY requirements.txt /app/requirements.txt
4+
RUN apk --no-cache add ${BUILD_PACKAGES} && \
5+
source .env/bin/activate && \
6+
python3 -m pip --no-cache-dir install -r app/requirements.txt && \
7+
apk del ${BUILD_PACKAGES}
8+
COPY . app
9+
RUN chmod 0755 /algo/app/run.sh
10+
CMD [ "/algo/app/run.sh" ]

app/run.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
ALGO_DIR="/algo"
6+
DATA_DIR="/data"
7+
8+
if [ -z ${VIRTUAL_ENV+x} ]
9+
then
10+
ACTIVATE_SCRIPT="/algo/.env/bin/activate"
11+
if [ -f "$ACTIVATE_SCRIPT" ]
12+
then
13+
# shellcheck source=/dev/null
14+
source "$ACTIVATE_SCRIPT"
15+
else
16+
echo "$ACTIVATE_SCRIPT not found. Did you follow documentation to install dependencies?"
17+
exit 1
18+
fi
19+
fi
20+
21+
tr -d '\r' < "${DATA_DIR}"/config.cfg > "${ALGO_DIR}"/config.cfg
22+
test -d "${DATA_DIR}"/configs && rsync -qLktr --delete "${DATA_DIR}"/configs "${ALGO_DIR}"/
23+
python app/server.py
24+
rsync -qLktr --delete "${ALGO_DIR}"/configs "${DATA_DIR}"/
25+
exit ${retcode}

app/server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from os.path import join, dirname
44
from aiohttp import web
55
import concurrent.futures
6+
import sys
67
from playbook import PlaybookCLI
78

89

@@ -85,6 +86,12 @@ async def post_config(request):
8586
f.write(config)
8687
return web.json_response({'ok': True})
8788

89+
@routes.post('/exit')
90+
async def post_exit(_):
91+
if task_future and task_future.done():
92+
sys.exit(0)
93+
else:
94+
sys.exit(1)
8895

8996
app = web.Application()
9097
app.router.add_routes(routes)

app/static/index.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ <h1 class="mb-5 text-center" v-if="step === 'status-error'">
6161
😢 Set up failed
6262
</h1>
6363
<h1 class="mb-5 text-center" v-if="step === 'status-done'">
64-
🥳 Congratulations! Your Algo server is running.
64+
🥳 Congratulations, your Algo server is running!
65+
</h1>
66+
<h1 class="mb-5 text-center" v-if="step === 'status-exit'">
67+
Config files are saved, bye!
6568
</h1>
6669
</h1>
6770
<transition name="fade">
@@ -99,7 +102,8 @@ <h1 class="mb-5 text-center" v-if="step === 'status-done'">
99102
</section>
100103
</transition>
101104
<transition name="fade">
102-
<status-done v-if="step == 'status-done'">
105+
<status-done v-if="step == 'status-done'"
106+
v-on:submit="exit(); step = 'status-exit'" >
103107
</status-done>
104108
</transition>
105109
</div>
@@ -126,7 +130,7 @@ <h1 class="mb-5 text-center" v-if="step === 'status-done'">
126130
'provider-setup': window.httpVueLoader('/static/provider-setup.vue'),
127131
'command-preview': window.httpVueLoader('/static/command-preview.vue'),
128132
'status-running': window.httpVueLoader('/static/status-running.vue'),
129-
'status-done': window.httpVueLoader('/static/status-done.vue'),
133+
'status-done': window.httpVueLoader('/static/status-done.vue')
130134
},
131135
created() {
132136
fetch("/playbook")
@@ -154,6 +158,11 @@ <h1 class="mb-5 text-center" v-if="step === 'status-done'">
154158
fetch("/playbook", {
155159
method: "DELETE"
156160
});
161+
},
162+
exit() {
163+
fetch("/exit", {
164+
method: "POST"
165+
});
157166
}
158167
}
159168
})

app/static/status-done.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
</div>
3737
</div>
3838
</section>
39+
<section>
40+
<h2 class="text-center">Finish setup and save configs</h2>
41+
<p class="text-center">
42+
<button v-on:click="$emit('submit')" class="btn btn-primary btn-lg" type="button">Save &amp; Exit</button>
43+
</p>
44+
</section>
3945
</div>
4046
</template>
4147

0 commit comments

Comments
 (0)