# =============================================================================
# SQL Server 2017 Express - Low RAM Edition
# =============================================================================
# Imagen optimizada para ejecutar SQL Server con bajo consumo de memoria
#
# Autor: andresgarcia0313
# Repositorio: https://hub.docker.com/r/andresgarcia0313/mssql-express-lowram
# GitHub: https://github.com/andresgarcia0313
#
# USO RAPIDO:
#   docker run -d --name mssql --memory=384m \
#     -e MSSQL_SA_PASSWORD=TuPassword123! \
#     -p 1433:1433 andresgarcia0313/mssql-express-lowram
#
# VARIABLES DE ENTORNO:
#   MSSQL_SA_PASSWORD  (REQUERIDO) - Password del usuario SA
#   MSSQL_PID          (opcional)  - Edición: Express, Developer, Standard
#   MSSQL_MEMORY_LIMIT_MB (opcional) - Límite de memoria en MB (default: 340)
#
# RAM RECOMENDADA: 384MB - 512MB (mínimo viable para desarrollo)
# =============================================================================

FROM mcr.microsoft.com/mssql/server:2017-latest

LABEL maintainer="andresgarcia0313 <andresgarcia0313@gmail.com>"
LABEL org.opencontainers.image.title="SQL Server 2017 Express - Low RAM"
LABEL org.opencontainers.image.description="SQL Server 2017 Express optimizado para bajo consumo de RAM (384MB-512MB). Ideal para desarrollo local y CI/CD."
LABEL org.opencontainers.image.version="1.0"
LABEL org.opencontainers.image.vendor="andresgarcia0313"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.source="https://github.com/andresgarcia0313"

# Variables de entorno por defecto (MSSQL_SA_PASSWORD debe ser proporcionada)
ENV ACCEPT_EULA=Y \
    MSSQL_PID=Express \
    MSSQL_MEMORY_LIMIT_MB=340

# Copiar scripts de optimización
COPY --chmod=755 entrypoint.sh /opt/mssql/bin/entrypoint.sh
COPY --chmod=644 optimize.sql /opt/mssql/bin/optimize.sql

# Puerto SQL Server
EXPOSE 1433

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$MSSQL_SA_PASSWORD" -Q "SELECT 1" || exit 1

# Entrypoint personalizado que aplica optimizaciones al iniciar
ENTRYPOINT ["/opt/mssql/bin/entrypoint.sh"]
