heartwood every commit a ring

Collapse web and scheduler into one container via Python supervisor

a72ebda0 by Isaac Bythewood · 24 days ago

modified Dockerfile
@@ -21,7 +21,8 @@ COPY . .ENV PATH="/app/.venv/bin:/app/node_modules/.bin:$PATH"RUN bun run build && \    uv run python manage.py collectstatic --noinput    uv run python manage.py collectstatic --noinput && \    chmod +x /app/entrypoint.pyRUN addgroup -S -g 1000 app && \    adduser -S -h /app -s /sbin/nologin -u 1000 -G app app && \
modified docker-compose.yml
@@ -9,18 +9,6 @@ services:      - /srv/data/status/:/data/    ports:      - "127.0.0.1:${PORT}:${PORT}"    command: >      gunicorn status.asgi:application --preload --workers 2 --max-requests 256      --timeout 30 --bind :${PORT} --worker-class uvicorn.workers.UvicornWorker      --error-logfile - --access-logfile -    restart: unless-stopped  worker:    container_name: status_worker    build: .    env_file: .env    volumes:      - /srv/data/status/:/data/    command: >      python3 manage.py scheduler    command: ./entrypoint.py    restart: unless-stopped    init: true
added entrypoint.py
@@ -0,0 +1,47 @@#!/usr/bin/env pythonimport osimport signalimport subprocessimport sysprocs = [    subprocess.Popen(["python", "manage.py", "scheduler"]),    subprocess.Popen(        [            "gunicorn",            "status.asgi:application",            "--workers",            "2",            "--max-requests",            "256",            "--timeout",            "30",            "--bind",            f":{os.environ['PORT']}",            "--worker-class",            "uvicorn.workers.UvicornWorker",            "--error-logfile",            "-",            "--access-logfile",            "-",        ]    ),]def shutdown(signum, frame):    for p in procs:        p.terminate()signal.signal(signal.SIGTERM, shutdown)signal.signal(signal.SIGINT, shutdown)pid, status = os.wait()for p in procs:    if p.pid != pid:        p.terminate()for p in procs:    p.wait()sys.exit(os.WEXITSTATUS(status) if os.WIFEXITED(status) else 1)