Skip to content

Commit

Permalink
🔨 fix docker compose db setup initializer pipeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
klondikemarlen committed Aug 8, 2023
1 parent e3c3e02 commit 2bd6780
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
10 changes: 4 additions & 6 deletions db/configure-db.sh → db/bin/configure-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ i=0

while [[ $DBSTATUS -ne 0 ]] && [[ $i -lt 60 ]] && [[ $ERRCODE -ne 0 ]]; do
i=$i+1
DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P $SA_PASSWORD -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases")
DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P "$MSSQL_SA_PASSWORD" -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases")
ERRCODE=$?
sleep 1
done

if [ $DBSTATUS -ne 0 ] OR [ $ERRCODE -ne 0 ]; then
if [[ $DBSTATUS -ne 0 ]] || [[ $ERRCODE -ne 0 ]]; then
echo "SQL Server took more than 60 seconds to start up or one or more databases are not in an ONLINE state"
exit 1
fi

echo "\$SQ_PASSWORD=$SA_PASSWORD"
echo "\$MSSQL_SQ_PASSWORD=$MSSQL_SQ_PASSWORD"
# Run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd \
-S localhost \
-U sa \
-P $SA_PASSWORD \
-P "$MSSQL_SA_PASSWORD" \
-d master \
-i setup.sql
-i ./initializers/setup.sql
22 changes: 12 additions & 10 deletions db/db.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ FROM mcr.microsoft.com/mssql/server:2019-latest

# current user:group => $whoami:$(id -gn) => mssql:root
USER root
RUN mkdir -p /usr/src/db && chown mssql:root /usr/src/db
USER mssql

RUN mkdir -p /usr/config

WORKDIR /usr/config

COPY . .
WORKDIR /usr/src/db

RUN chown -R mssql:root /usr/config
RUN chmod +x ./entrypoint.sh
RUN chmod +x ./configure-db.sh
# Data
# COPY ./db/data /var/opt/mssql/data
# COPY ./db/log /var/opt/mssql/log
# COPY ./db/backups /var/opt/mssql/data/backups

USER mssql
# Intialization
COPY --chown=mssql:root --chmod=+x ./db/entrypoint.sh ./
COPY --chown=mssql:root --chmod=+x ./db/bin ./bin
COPY --chown=mssql:root ./db/initializers ./initializers

ENTRYPOINT ["./entrypoint.sh"]
ENTRYPOINT ["/usr/src/db/entrypoint.sh"]
3 changes: 2 additions & 1 deletion db/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

# Start the script to create the DB and user
/usr/config/configure-db.sh &
cd /usr/src/db
./bin/configure-db.sh &

# Start SQL Server
/opt/mssql/bin/sqlservr
File renamed without changes.
2 changes: 2 additions & 0 deletions docker-compose.development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ services:
MSSQL_SA_PASSWORD: *password-definition
ACCEPT_EULA: "Y"
volumes:
- ./db/bin:/usr/src/db/bin
- ./db/initializers:/usr/src/db/initializers
- ./db/data:/var/opt/mssql/data
- ./db/log:/var/opt/mssql/log
- ./db/backups:/var/opt/mssql/data/backups
Expand Down

0 comments on commit 2bd6780

Please sign in to comment.