This repository was archived by the owner on Jul 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +39
-7
lines changed
Expand file tree Collapse file tree 2 files changed +39
-7
lines changed Original file line number Diff line number Diff line change 1- FROM mcr.microsoft.com/mssql-tools
2- WORKDIR /scripts
3- COPY create_database_statement.sql .
4- COPY db-setup-entrypoint.sh .
5- RUN chmod +x ./db-setup-entrypoint.sh
6- ENTRYPOINT ["/scripts/db-setup-entrypoint.sh" ]
1+ # Use official Microsoft SQL Server image as base
2+ FROM mcr.microsoft.com/mssql/server:2022-latest
3+
4+ # Switch to root to change file permissions
5+ USER root
6+
7+ # Copy the setup script and SQL file to /database inside the container
8+ COPY db-setup-entrypoint.sh /database/db-setup-entrypoint.sh
9+ COPY create_database_statement.sql /database/create_database_statement.sql
10+
11+ # Make sure the entrypoint script is executable
12+ RUN chmod +x /database/db-setup-entrypoint.sh
13+
14+ # Switch back to the default non-root SQL Server user
15+ USER mssql
16+
17+ # Run the entrypoint script when the container starts
18+ ENTRYPOINT ["/database/db-setup-entrypoint.sh" ]
Original file line number Diff line number Diff line change 11#! /bin/bash
22echo " 🔧 Starting DB setup..."
3+
4+ # Verify that the script is executable
5+ if [ ! -x /database/db-setup-entrypoint.sh ]; then
6+ echo " ❌ Entry point script is not executable"
7+ exit 1
8+ fi
9+
10+ # Verify the content of the script is present and not empty
11+ echo " 📄 Content of the script:"
12+ cat /database/db-setup-entrypoint.sh
13+
14+ # Check if the SQL script exists
15+ if [ ! -f /database/create_database_statement.sql ]; then
16+ echo " ❌ SQL script not found!"
17+ exit 1
18+ fi
19+
320echo " 📡 Connecting to SQL Server at db..."
421until /opt/mssql-tools/bin/sqlcmd -S db -U SA -P " ${DATABASE_PASSWORD} " -Q " SELECT 1;" > /dev/null 2>&1
522do
623 echo " ⏳ Waiting for SQL Server..."
724 sleep 5
825done
926echo " ✅ SQL Server is ready."
10- /opt/mssql-tools/bin/sqlcmd -S db -U SA -P " ${DATABASE_PASSWORD} " -d master -i create_database_statement.sql
27+
28+ # Run the SQL setup script to create the database
29+ /opt/mssql-tools/bin/sqlcmd -S db -U SA -P " ${DATABASE_PASSWORD} " -d master -i /database/create_database_statement.sql
30+
1131echo " ✅ Database setup completed."
You can’t perform that action at this time.
0 commit comments