From 98a3405ca2914c8ae3f7e96654f6d6646c133506 Mon Sep 17 00:00:00 2001 From: Sir Tangale <89900079+sirTangale@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:48:37 +0900 Subject: [PATCH 1/4] Update import-data.sh path has changed in recent images --- import-data.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import-data.sh b/import-data.sh index 8f74505..4fd2543 100644 --- a/import-data.sh +++ b/import-data.sh @@ -2,7 +2,7 @@ #do this in a loop because the timing for when the SQL instance is ready is indeterminate for i in {1..50}; do - /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Yukon900 -d master -i setup.sql + /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P Yukon900 -d master -i setup.sql if [ $? -eq 0 ] then echo "setup.sql completed" From 3cc09060eedd9f66acd001a48a7c091dd41de946 Mon Sep 17 00:00:00 2001 From: Sir Tangale <89900079+sirTangale@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:17:59 +0900 Subject: [PATCH 2/4] Update import-data.sh --- import-data.sh | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/import-data.sh b/import-data.sh index 4fd2543..48f8d24 100644 --- a/import-data.sh +++ b/import-data.sh @@ -1,17 +1,43 @@ #run the setup script to create the DB and the schema in the DB #do this in a loop because the timing for when the SQL instance is ready is indeterminate -for i in {1..50}; -do - /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P Yukon900 -d master -i setup.sql - if [ $? -eq 0 ] - then - echo "setup.sql completed" +#!/bin/bash + +LOG_FILE="/tmp/mssql-log.txt" + +# Function to log messages +log_message() { + local message="$1" + echo "$(date +"%Y-%m-%d %T"): $message" >> "$LOG_FILE" +} + +# Wait for SQL Server to be started +for i in {1..100}; do + /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P Yukon900 -d master -Q "SELECT 1" -C + if [ $? -eq 0 ]; then + log_message "SQL Server is up and running" break else - echo "not ready yet..." - sleep 1 + log_message "Waiting for SQL Server to be ready... Attempt $i" + sleep 5 fi done +# Check if SQL Server is up and running +/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P Yukon900 -d master -Q "SELECT 1" -C +if [ $? -ne 0 ]; then + log_message "SQL Server is not accessible after waiting. Exiting." + exit 1 +fi + +# Run the init script +/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P Yukon900 -d master -i setup.sql -C +if [ $? -eq 0 ]; then + log_message "init.sql setup completed successfully" +else + log_message "init.sql setup failed" +fi + #import the data from the csv file -/opt/mssql-tools/bin/bcp DemoData.dbo.Products in "/usr/src/app/Products.csv" -c -t',' -S localhost -U sa -P Yukon900 +/opt/mssql-tools18/bin/bcp DemoData.dbo.Products in "/usr/src/app/Products.csv" -c -t',' -S localhost -U sa -P Yukon900 + + From 21f4031c424044fc83b33713d4f014e2eac25479 Mon Sep 17 00:00:00 2001 From: Sir Tangale <89900079+sirTangale@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:19:33 +0900 Subject: [PATCH 3/4] Update entrypoint.sh --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 52ba6f0..5d19a5b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,2 +1,2 @@ -#start SQL Server, start the script to create the DB and import the data, start the app -/opt/mssql/bin/sqlservr & /usr/src/app/import-data.sh & npm start +# run mport-data.sh in background and sqlservr in foreground, and start the app +/usr/src/app/import-data.sh & /opt/mssql/bin/sqlservr & npm start From 0a1741a435fd601fafdbb7f648badb354798cb9d Mon Sep 17 00:00:00 2001 From: Sir Tangale <89900079+sirTangale@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:20:31 +0900 Subject: [PATCH 4/4] Update Dockerfile --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9aa68c0..fe5b4c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -FROM mcr.microsoft.com/mssql/server - +FROM mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04 # Switch to root user for access to apt-get install USER root