66 lines
1.5 KiB
Docker
66 lines
1.5 KiB
Docker
# Multi-stage build for Generic App Service single container
|
|
|
|
# Stage 1: Build frontend
|
|
FROM node:20-alpine as frontend-builder
|
|
|
|
WORKDIR /frontend
|
|
|
|
# Copy package files
|
|
COPY frontend/package*.json ./
|
|
|
|
# Install dependencies
|
|
RUN npm ci
|
|
|
|
# Copy frontend source
|
|
COPY frontend/ .
|
|
|
|
# Build frontend
|
|
RUN npm run build
|
|
|
|
# Stage 2: Build backend dependencies
|
|
FROM python:3.11-slim as backend-builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install only essential build dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy and install Python dependencies
|
|
COPY backend/requirements.txt .
|
|
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
|
|
# Stage 3: Final image
|
|
FROM python:3.11-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy Python packages from builder
|
|
COPY --from=backend-builder /root/.local /root/.local
|
|
|
|
# Make sure scripts in .local are usable
|
|
ENV PATH=/root/.local/bin:$PATH
|
|
|
|
# Create config directory
|
|
RUN mkdir -p /config
|
|
|
|
# Copy backend application
|
|
COPY backend/app ./app
|
|
COPY backend/alembic ./alembic
|
|
COPY backend/alembic.ini .
|
|
COPY .env .
|
|
|
|
# Copy built frontend from frontend-builder
|
|
COPY --from=frontend-builder /frontend/dist ./static
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
|
|
# Run database migrations and start the application
|
|
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000"]
|