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 68abc2a..0732f41 100644 Binary files a/requirements.txt and b/requirements.txt differ