Initial commit: Ebook Translation System with Docker setup
This commit is contained in:
64
ebook_backend&admin_panel/Dockerfile
Normal file
64
ebook_backend&admin_panel/Dockerfile
Normal file
@@ -0,0 +1,64 @@
|
||||
# Multi-stage build pre optimalizáciu veľkosti obrazu
|
||||
FROM python:3.11-slim as builder
|
||||
|
||||
# Nastavenie working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Inštalácia build dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
postgresql-client \
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Kopírovanie requirements
|
||||
COPY requirements.txt .
|
||||
|
||||
# Inštalácia Python dependencies
|
||||
RUN pip install --no-cache-dir --user -r requirements.txt
|
||||
|
||||
# Production stage
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Nastavenie environment variables
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PATH=/root/.local/bin:$PATH
|
||||
|
||||
# Inštalácia runtime dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
postgresql-client \
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Vytvorenie non-root user pre bezpečnosť
|
||||
RUN useradd -m -u 1000 appuser
|
||||
|
||||
# Nastavenie working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Kopírovanie Python dependencies z builder stage
|
||||
COPY --from=builder /root/.local /root/.local
|
||||
|
||||
# Kopírovanie aplikačných súborov
|
||||
COPY --chown=appuser:appuser . .
|
||||
|
||||
# Vytvorenie potrebných adresárov
|
||||
RUN mkdir -p /app/admin-backend/logs \
|
||||
/app/admin-backend/translationfile \
|
||||
&& chown -R appuser:appuser /app
|
||||
|
||||
# Prepnutie na non-root user
|
||||
USER appuser
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Healthcheck
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
|
||||
|
||||
# Spustenie aplikácie
|
||||
WORKDIR /app/admin-backend
|
||||
CMD ["python", "init_db.py"] && \
|
||||
["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
|
||||
Reference in New Issue
Block a user