From 20c2cc018cd4404893effe9b6ef7fff4b82b9a6d Mon Sep 17 00:00:00 2001 From: diaco Date: Mon, 5 Oct 2026 09:12:41 +0330 Subject: [PATCH] Add optional apt/PyPI mirrors and HTTP_PORT Co-authored-by: Cursor --- .env.example | 9 +++++++++ Dockerfile | 20 ++++++++++++++++++++ README.md | 15 +++++++++++---- docker-compose.yml | 9 +++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..53db3fb --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# Host port published by nginx (maps to container port 80) +HTTP_PORT=80 + +# Optional Debian apt mirror host (replaces deb.debian.org / security.debian.org) +# APT_MIRROR=mirrors.tuna.tsinghua.edu.cn + +# Optional PyPI index URL for pip during image build +# PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple +# PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn diff --git a/Dockerfile b/Dockerfile index 3611d60..02445f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,26 @@ FROM python:3.14-slim ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 +ARG APT_MIRROR= +ARG PIP_INDEX_URL= +ARG PIP_TRUSTED_HOST= + +# Optional Debian apt mirror (host only, e.g. mirror.example.com) +RUN if [ -n "$APT_MIRROR" ]; then \ + if [ -f /etc/apt/sources.list.d/debian.sources ]; then \ + sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}|g" \ + /etc/apt/sources.list.d/debian.sources; \ + fi; \ + if [ -f /etc/apt/sources.list ]; then \ + sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}|g" \ + /etc/apt/sources.list; \ + fi; \ + fi + +# Optional PyPI mirror (pip reads these env vars) +ENV PIP_INDEX_URL=${PIP_INDEX_URL} +ENV PIP_TRUSTED_HOST=${PIP_TRUSTED_HOST} + WORKDIR /app # Install dependencies diff --git a/README.md b/README.md index aec603d..ba547d5 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,20 @@ The application is fully containerized using Docker, meaning it can be deployed ```bash cd path/to/product-slip ``` -2. Start the application stack using Docker Compose: +2. (Optional) Copy `.env.example` to `.env` and adjust settings: + ```bash + cp .env.example .env + ``` + - `HTTP_PORT` — host port for the app (default `80`) + - `APT_MIRROR` — Debian apt mirror host used during image build + - `PIP_INDEX_URL` / `PIP_TRUSTED_HOST` — PyPI mirror used by pip during image build +3. Start the application stack using Docker Compose: ```bash docker compose up -d --build ``` -3. The server is now running! You can access the application from any device on the same local network: - - If you are on the same machine: Open your browser and go to `http://localhost` - - If you are on a different machine on the same network: Find the host computer's local IP address (e.g., `192.168.1.15`) and go to `http://192.168.1.15` +4. The server is now running! You can access the application from any device on the same local network: + - If you are on the same machine: Open your browser and go to `http://localhost` (or `http://localhost:$HTTP_PORT` if you changed the port) + - If you are on a different machine on the same network: Find the host computer's local IP address (e.g., `192.168.1.15`) and go to `http://192.168.1.15` (add `:$HTTP_PORT` if not using port 80) ### Stopping the Server To safely stop the application without losing data: diff --git a/docker-compose.yml b/docker-compose.yml index 2bb4d39..0f4c5ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,11 @@ services: app: - build: . + build: + context: . + args: + APT_MIRROR: ${APT_MIRROR:-} + PIP_INDEX_URL: ${PIP_INDEX_URL:-} + PIP_TRUSTED_HOST: ${PIP_TRUSTED_HOST:-} restart: unless-stopped volumes: - db_data:/app/data @@ -15,7 +20,7 @@ services: image: nginx:alpine restart: unless-stopped ports: - - "80:80" + - "${HTTP_PORT:-80}:80" volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro depends_on: