Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit fabcd19

Browse files
feat: db container running
1 parent 6724bbf commit fabcd19

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

database/Dockerfile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
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"]

database/db-setup-entrypoint.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
#!/bin/bash
22
echo "🔧 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+
320
echo "📡 Connecting to SQL Server at db..."
421
until /opt/mssql-tools/bin/sqlcmd -S db -U SA -P "${DATABASE_PASSWORD}" -Q "SELECT 1;" > /dev/null 2>&1
522
do
623
echo "⏳ Waiting for SQL Server..."
724
sleep 5
825
done
926
echo "✅ 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+
1131
echo "✅ Database setup completed."

0 commit comments

Comments
 (0)