Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from openimis/develop
Browse files Browse the repository at this point in the history
release 2022-04
  • Loading branch information
delcroip authored May 11, 2022
2 parents a273f5b + 4ff9da3 commit a10d1cd
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 42 deletions.
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ ARG ACCEPT_EULA
ENV ACCEPT_EULA=$ACCEPT_EULA
ARG SA_PASSWORD
ENV SA_PASSWORD=$SA_PASSWORD
ARG SQL_SCRIPT_URL=https://github.com/openimis/database_ms_sqlserver/raw/master/Empty%20databases/openIMIS_ONLINE.sql
RUN wget $SQL_SCRIPT_URL -O /openIMIS_ONLINE.sql
COPY script/* /
ENV DB_USER_PASSWORD=$SA_PASSWORD
ENV DB_NAME=IMIS
ENV DB_USER=IMISUser
RUN mkdir -p /app
COPY script/* /app/
WORKDIR /app

ARG SQL_SCRIPT_URL="https://github.com/openimis/database_ms_sqlserver/releases/latest/download/sql-files.zip"
RUN wget $SQL_SCRIPT_URL -O /sql-files.zip
RUN apt-get update && apt-get install unzip -y && rm -rf /var/lib/apt/lists/* && unzip /sql-files.zip -d /app
RUN chmod a+x /app/*.sh
CMD /bin/bash ./entrypoint.sh
19 changes: 0 additions & 19 deletions Dockerfile_win

This file was deleted.

4 changes: 0 additions & 4 deletions script/create_database.bat

This file was deleted.

4 changes: 0 additions & 4 deletions script/create_database.sh

This file was deleted.

3 changes: 0 additions & 3 deletions script/create_user_db.bat

This file was deleted.

4 changes: 0 additions & 4 deletions script/demo_user.bat

This file was deleted.

5 changes: 0 additions & 5 deletions script/demo_user.sh

This file was deleted.

4 changes: 4 additions & 0 deletions script/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://www.softwaredeveloper.blog/initialize-mssql-in-docker-container

# Run Microsoft SQl Server and initialization script (at the same time)
/app/run-initialization.sh & /opt/mssql/bin/sqlservr
7 changes: 7 additions & 0 deletions script/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
data=$(/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "SELECT COUNT(*) FROM master.dbo.sysdatabases WHERE name = N'$DB_NAME'" | tr -dc '0-9'| cut -c1 )
if [ ${data} -eq "1" ]; then
exit 0
else
exit 1
fi
33 changes: 33 additions & 0 deletions script/run-initialization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash


# Wait to be sure that SQL Server came up
sleep 30s


# DATABSE initialisation

echo "Database initialisaton"
# if the table does not exsit it will create the table


# get "1" if the database exist : tr get only the integer, cut only the first integer (the second is the number of row affected)
data=$(/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "SELECT COUNT(*) FROM master.dbo.sysdatabases WHERE name = N'$DB_NAME'" | tr -dc '0-9'| cut -c1 )
if [ ${data} -eq "0" ]; then
echo 'create database user'
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE LOGIN $DB_USER WITH PASSWORD='${SA_PASSWORD}', CHECK_POLICY = OFF"

echo 'create database'
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP DATABASE IF EXISTS $DB_NAME"
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME"
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i /app/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c

echo ' give to the user the access to the database'
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE USER $DB_USER FOR LOGIN $DB_USER " -d $DB_NAME
else
echo "database already existing, nothing to do"
fi

# manual cleaning command
# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP DATABASE $DB_NAME"
# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP LOGIN $DB_USER"

0 comments on commit a10d1cd

Please sign in to comment.