kanbot-backend / Dockerfile
Jeremy Jones
Self-contained Postgres + web server Dockerfile, entrypoint, and quoted schema
bd7e398
Raw History Blame Contribute Delete
2.18 kB
# KanBot backend — self-contained Docker Space.
# Installs Postgres server inside the container, stores data in /data (persistent
# volume), and runs the web board on port 7860.
#
# DB_HOST env var: if set and reachable, the web server connects to that
# external Postgres instead of the local one. Falls back to local automatically.
#
# The HF Docker Space runtime executes the container as UID 1000, so the
# Debian "postgres" user is remapped to UID 1000 here and the entrypoint runs
# initdb / pg_ctl / psql directly (no `su`, which requires root).
FROM python:3.11-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
DEBIAN_FRONTEND=noninteractive
# --------------------------------------------------------------------------- #
# Postgres server + client tooling
# --------------------------------------------------------------------------- #
RUN apt-get update && apt-get install -y --no-install-recommends \
postgresql \
postgresql-client \
netcat-openbsd \
ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& usermod -u 1000 postgres && groupmod -g 1000 postgres \
&& mkdir -p /var/lib/pgsql /run/postgresql \
&& chown -R postgres:postgres /var/lib/pgsql /run/postgresql /var/lib/postgresql
# --------------------------------------------------------------------------- #
# Python deps (same requirements as the local kanbot repo)
# --------------------------------------------------------------------------- #
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY --chown=postgres:postgres . /app
RUN chmod +x /app/entrypoint.sh
ENV DATABASE_URL="postgresql://kanbot:kanbot@localhost:5432/kanbot" \
KANBOT_WEB_HOST="0.0.0.0" \
KANBOT_WEB_PORT="7860" \
KANBOT_SCHEMA_SQL="/app/sql/001_schema_quoted.sql" \
PGDATA="/data/pgdata" \
HOME="/var/lib/postgresql"
USER postgres:postgres
EXPOSE 7860
HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=5 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/snapshot')" || exit 1
ENTRYPOINT ["/app/entrypoint.sh"]