Correct dockerfile

This commit is contained in:
2024-11-04 20:04:48 +11:00
parent f5bad96508
commit 6bedd80088
3 changed files with 64 additions and 9 deletions
+28 -6
View File
@@ -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"]
+27
View File
@@ -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
+9 -3
View File
@@ -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