From 0cb397fc46e13e1784012701ee13aa31dd08e8f7 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 3 Jun 2023 01:24:13 -0600 Subject: [PATCH] Working on dockerization --- .../cherry-shim/src/python/cherry_shim.py | 9 ++++--- projects/tentacles/BUILD | 5 +++- projects/tentacles/Dockerfile | 25 +++++++++++++++++++ projects/tentacles/mkdocker.sh | 15 +++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 projects/tentacles/Dockerfile create mode 100644 projects/tentacles/mkdocker.sh diff --git a/projects/cherry-shim/src/python/cherry_shim.py b/projects/cherry-shim/src/python/cherry_shim.py index 12ae8fe..aed480b 100644 --- a/projects/cherry-shim/src/python/cherry_shim.py +++ b/projects/cherry-shim/src/python/cherry_shim.py @@ -5,7 +5,6 @@ import cherrypy def shim(app): - cherrypy.tree.graft(app, "/") cherrypy.server.unsubscribe() server = cherrypy._cpserver.Server() @@ -13,15 +12,17 @@ def shim(app): cherrypy.config.update( { "environment": environment, - "server.socket_host": host, - "server.socket_port": port, - "server.thread_pool": pool_size, "engine.autoreload.on": False, "log.screen": True, } ) + cherrypy.tree.graft(app, "/") + server.socket_host = host + server.socket_port = port + server.thread_pool = pool_size server.subscribe() + cherrypy.engine.start() cherrypy.engine.block() diff --git a/projects/tentacles/BUILD b/projects/tentacles/BUILD index 4305c05..336cd7d 100644 --- a/projects/tentacles/BUILD +++ b/projects/tentacles/BUILD @@ -1,16 +1,19 @@ py_project( name = "tentacles", + shebang = "/usr/bin/env python3.11", + zip_safe = False, main = "src/python/tentacles/__main__.py", main_deps = [ "//projects/anosql", "//projects/anosql-migrations", "//projects/cherry-shim", + py_requirement("attrs"), py_requirement("click"), py_requirement("flask"), py_requirement("jinja2"), py_requirement("octorest"), ], - main_data = [ + lib_data = [ "//projects/tentacles/src/python/tentacles/static/css", ], ) diff --git a/projects/tentacles/Dockerfile b/projects/tentacles/Dockerfile new file mode 100644 index 0000000..872b1b1 --- /dev/null +++ b/projects/tentacles/Dockerfile @@ -0,0 +1,25 @@ +FROM library/python:3.11 + MAINTAINER Reid 'arrdem' McKenzie + +# RUN pip install --upgrade pip + +RUN useradd -d /app app +RUN mkdir -p /app /data +RUN chown -R app:app /app /data +USER app +WORKDIR /app +VOLUME /data +ENV DOCKER_RUNNING=true + +ENV PYTHONPATH="/app:${PYTHONPATH}" +ENV PYTHONUNBUFFERED=true +ENV PATH="/app/.local/bin:${PATH}" + +### App specific crap +# Deps vary least so do them first +# RUN pip3 install --user install aiohttp aiohttp_basicauth async_lru cachetools click pycryptodome pyyaml retry + +COPY --chown=app:app tentacles.zapp /app/app + +EXPOSE 8080 +CMD ["/app/app"] diff --git a/projects/tentacles/mkdocker.sh b/projects/tentacles/mkdocker.sh new file mode 100644 index 0000000..6dc98cd --- /dev/null +++ b/projects/tentacles/mkdocker.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -eoux -o pipefail + +cd "$(dirname "$(realpath "$0")")" +tmpdir=$(mktemp -d) + +bazel build //projects/tentacles:tentacles.zapp +zapp=$(realpath $(bazel run --run_under=echo //projects/tentacles:tentacles.zapp)) + +cp Dockerfile "$tmpdir/" +cp -r "$zapp" "$tmpdir/" + +cd "${tmpdir}" +docker build "$@" -f Dockerfile .