You've already forked Promocode-API
mirror of
https://github.com/devitq/Promocode-API.git
synced 2026-05-22 23:17:10 +00:00
63 lines
1.5 KiB
Docker
63 lines
1.5 KiB
Docker
# Stage 1: Install dependencies
|
|
FROM docker.io/python:3.11-alpine3.20 AS builder
|
|
|
|
# Install uv
|
|
COPY --from=ghcr.io/astral-sh/uv:0.4.30 /uv /uvx /bin/
|
|
|
|
# Set the working directory
|
|
WORKDIR /app
|
|
|
|
# Setup env vars
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PYTHONOPTIMIZE=2 \
|
|
UV_COMPILE_BYTECODE=1 \
|
|
UV_PROJECT_ENVIRONMENT=/opt/venv
|
|
|
|
# Copy pyproject.toml file
|
|
COPY pyproject.toml .
|
|
|
|
# Install dependencies
|
|
RUN uv sync --no-dev --no-install-project --no-cache
|
|
|
|
|
|
# Stage 2: Serve the application
|
|
FROM docker.io/python:3.11-alpine3.20
|
|
|
|
# Set the working directory
|
|
WORKDIR /app
|
|
|
|
# Copy virtual environment from builder
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create app user and set permissions
|
|
RUN adduser -D -g '' app && chown -R app:app ./
|
|
|
|
# Run as non-root user
|
|
USER app
|
|
|
|
# Setup env vars
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PYTHONOPTIMIZE=2 \
|
|
PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Expose port
|
|
EXPOSE 8080
|
|
|
|
# Healthcheck
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8080/health/?format=json || exit 1
|
|
|
|
# Set env vars for app (sorry for that)
|
|
ENV DJANGO_DEBUG=False \
|
|
DJANGO_ALLOWED_HOSTS=* \
|
|
DJANGO_NOTIFIER_TELEGRAM_BOT_TOKEN=6196898691:AAHtiIgbLAHlELGqO4qmrKoqjWaEJohr9fY \
|
|
DJANGO_NOTIFIER_TELEGRAM_CHAT_ID=-1002304409222
|
|
|
|
# Start gunicorn
|
|
CMD python manage.py migrate && gunicorn config.wsgi -b ${SERVER_ADDRESS}
|