From 6bedd8008861e720a6f411cd32adb26fbd2e3d6a Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Mon, 4 Nov 2024 20:04:48 +1100 Subject: [PATCH] Correct dockerfile --- Dockerfile | 34 ++++++++++++++++++++++++++++------ Dockerfile.local | 27 +++++++++++++++++++++++++++ docker-compose.yml | 12 +++++++++--- 3 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 Dockerfile.local diff --git a/Dockerfile b/Dockerfile index 419de40..ba74916 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,48 @@ +FROM ghcr.io/astral-sh/uv:bookworm-slim AS uv + FROM python:3.12-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 +ENV PYTHONPATH /app # Set work directory WORKDIR /app # Copy pyproject.toml COPY pyproject.toml uv.lock ./ + # Install system dependencies and uv RUN apt-get update && apt-get install -y \ build-essential \ curl \ - && rm -rf /var/lib/apt/lists/* \ - && curl -LsSf https://astral.sh/uv/install.sh | sh \ - && . $HOME/.cargo/env \ - && which uv + gcc \ + nodejs \ + npm \ + gettext \ + && rm -rf /var/lib/apt/lists/* +COPY --from=uv /usr/local/bin/uv /usr/local/bin/uv + +RUN which uv \ + && uv sync --no-dev -# Install Python dependencies -RUN . $HOME/.cargo/env && uv sync --no-dev # Copy project COPY . . + +# Install Tailwind CSS dependencies +RUN uv run manage.py tailwind install +# Build Tailwind CSS +RUN uv run manage.py tailwind build +# Collect static files +RUN uv run manage.py collectstatic --noinput +# Compile translation messages +RUN uv run manage.py compilemessages --locale=zh_Hans +# Create data directory for SQLite database +RUN mkdir -p /app/data && chmod 777 /app/data +# Expose port 8000 +EXPOSE 8000 +# Run the application +CMD ["uv", "run", "gunicorn", "--chdir", "/app", "url_manager.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..feb0506 --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,27 @@ +FROM ghcr.io/astral-sh/uv:bookworm-slim AS uv +FROM python:3.12-slim + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 +ENV UV_INSTALL_DIR /usr/local/bin +ENV PYTHONPATH /app + +# Set work directory +WORKDIR /app + +# Copy pyproject.toml +COPY pyproject.toml uv.lock ./ + +# Copy project +COPY . . + +# Install system dependencies and uv +RUN apt-get update && apt-get install -y \ + build-essential \ + curl \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=uv /usr/local/bin/uv /usr/local/bin/uv +# Install Python dependencies +RUN uv sync --no-dev diff --git a/docker-compose.yml b/docker-compose.yml index cae6120..f252e59 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,9 @@ version: '3.8' services: web: - build: . + build: + context: . + dockerfile: Dockerfile.local command: > sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" @@ -22,7 +24,9 @@ services: - app-network celery_worker: - build: . + build: + context: . + dockerfile: Dockerfile.local command: celery -A core worker --loglevel=info volumes: - .:/app @@ -38,7 +42,9 @@ services: - app-network celery_beat: - build: . + build: + context: . + dockerfile: Dockerfile.local command: celery -A core beat -s /app/data/celerybeat-schedule --loglevel=info volumes: - .:/app