# Dockerfile for DB init service

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

# Set SQL Server environment variables
ENV SA_PASSWORD=Ou812@12!@ \
    ACCEPT_EULA=Y

# Set working directory inside the container
WORKDIR /usr/src/app

# Copy the initialization script and SQL file into the image
COPY --chmod=0755 init.sh .
COPY init.sql .

# Make the script executable


# Start SQL Server, wait until it is ready, then run the init script
CMD /opt/mssql/bin/sqlservr & \
    /bin/bash -c "\
    until /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $$SA_PASSWORD -Q \"SELECT 1\" >/dev/null 2>&1; do \
    sleep 1; \
    done && \
    ./init.sh && \
    tail -f /dev/null \
    "
