From 56bbbb5dfa315ef63879a6ad5a0460871ea62e7e Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Mon, 30 Oct 2023 20:01:23 +0300 Subject: [PATCH] Dockerized --- .dockerignore | 10 ++++++++++ .gitignore | 6 ++++++ Dockerfile | 27 +++++++++++++++++++++++++++ entrypoint.sh | 14 ++++++++++++++ generate_uswgi_config.py | 19 +++++-------------- requirements.txt | Bin 132 -> 164 bytes 6 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..00dec90 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +*sqlite3 +uwsgi.ini +start*.bash +__pycache__ +venv +.git +uwsgi.ini +start.bash +Dockerfile +squads_stat_cache.sqlite3 diff --git a/.gitignore b/.gitignore index eee9253..b23ee6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ *sqlite3 uwsgi.ini start*.bash +__pycache__ +venv +.git +uwsgi.ini +start.bash +squads_stat_cache.sqlite3 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..033254f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM python:3.11-slim as builder +WORKDIR /app + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +COPY requirements.txt . +RUN apt update && apt install -y gcc +RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt + +FROM python:3.11-slim + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +RUN useradd --no-create-home --system user +WORKDIR /app + +COPY --from=builder /app/wheels /wheels +COPY --from=builder /app/requirements.txt . + +RUN pip install --no-cache /wheels/* +USER user +COPY . . + +ENTRYPOINT ["/app/entrypoint.sh"] + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..aaf49ef --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -eu + +echo "Generating uwsgi config" +python3 generate_uswgi_config.py + +if [ "$IS_WEB" = "true" ]; then + echo "Running web" + exec uwsgi -c /tmp/uwsgi.ini +fi + +echo "Running collector" +exec python main.py $@ diff --git a/generate_uswgi_config.py b/generate_uswgi_config.py index e3a96ec..3f4f055 100644 --- a/generate_uswgi_config.py +++ b/generate_uswgi_config.py @@ -4,35 +4,26 @@ template = """ [uwsgi] master = 1 vacuum = true -socket = 127.0.0.1:8082 +socket = 0.0.0.0:8082 enable-threads = true die-on-term = true thunder-lock = true threads = {threads} processes = {processes} -virtualenv = {venv} wsgi-file = {wsgi_file} -chdir = {project_dir} -uid = {user} -gid = {group}"""[1:] +need-app = true +chdir = {project_dir}"""[1:] project_dir = os.path.dirname(os.path.abspath(__file__)) # current dir -venv_path = os.path.join(project_dir, 'venv') wsgi_file = os.path.join(project_dir, 'web.py') cpu_count = os.cpu_count() process_count = cpu_count -user = 'user2' -group = user - config = template.format(threads=cpu_count, processes=process_count, - venv=venv_path, wsgi_file=wsgi_file, - project_dir=project_dir, - user=user, - group=group) + project_dir=project_dir) -with open('uwsgi.ini', 'w') as file: +with open('/tmp/uwsgi.ini', 'w') as file: file.write(config) diff --git a/requirements.txt b/requirements.txt index 68abc2a349e53f559980a99cb3c48253e6b6c78a..0732f41cb03e402443ea4406141cc420b9bec112 100644 GIT binary patch delta 58 zcmZo+T*4^-|6c(^F+(LoGDAK?0Yf^25rZy65<@0K9z!BS5kuuf!D1m^1}=tDhH{{? Jbf5%?2LQb`4730M delta 25 gcmZ3&*up6I|6c(^F+(LoGDAK?0Yf^2(M0)T0BjHklK=n!