Skip to content

Commit

Permalink
mergewith dist_db
Browse files Browse the repository at this point in the history
  • Loading branch information
delcroip authored Feb 23, 2023
1 parent 828dd24 commit ec38870
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 7 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: publish
on:
tags:
jobs:
publish-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the docker Docker image
run: |
docker build . --tag ghcr.io/openimis/openimis-be:${GITHUB_REF##*/}
docker run ghcr.io/openimis/openimis-be:${GITHUB_REF##*/}
docker push ghcr.io/openimis/openimis-be:${GITHUB_REF##*/}
2 changes: 1 addition & 1 deletion .github/workflows/file-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Merge me!
run : bash concatenate_files.sh
run : bash script/concatenate_files.sh
- name: Publish artifact
uses: actions/upload-artifact@master
with:
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/mssql/server:2017-latest
ARG ACCEPT_EULA=Y
ENV ACCEPT_EULA=N
ARG SA_PASSWORD=IMISuserP@s
ENV SA_PASSWORD=IMISuserP@s
ENV DB_USER_PASSWORD=IMISuserP@s
ENV DB_NAME=IMIS
ENV DB_USER=IMISUser
RUN mkdir -p /app
COPY script/* /app/
WORKDIR /app

ENV SQL_SCRIPT_URL="https://github.com/openimis/database_ms_sqlserver/releases/latest/download/sql-files.zip"
ENV INIT_MODE='empty'
RUN apt-get update && apt-get install unzip -y && rm -rf /var/lib/apt/lists/*
RUN chmod a+x /app/*.sh
CMD /bin/bash ./entrypoint.sh
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,68 @@ For deployment please read the [installation manual](http://openimis.readthedocs
Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
-->

## openIMIS dockerized database



| :bomb: Disclaimer : NOT FOR PRODUCTION USE :bomb: |
| --- |
| This repository provides a dockerized openIMIS database. It provides a quick setup for development, testing or demoing. ***It is NOT INTENDED FOR PRODUCTION USE.*** |


### ENV

- INIT_MODE if set to demo will init the database to demo (works only if not yet init)
- SQL_SCRIPT_URL url to init scripts
- **ACCEPT_EULA** must be set to Y to accept MS SQL EULA
- SA_PASSWORD default: IMISuserP@s
- DB_USER_PASSWORD defautl: IMISuserP@s
- DB_NAMEdefautl: IMIS
- DB_USER defautl: IMISUser


### gettingstarted

Please look for the directions on the openIMIS Wiki: https://openimis.atlassian.net/wiki/spaces/OP/pages/963182705/MO1.1+Install+the+modular+openIMIS+using+Docker

Using the provided docker file, you can build a docker image running a SQL Server 2017, with a restored openIMIS backup database.
This is done by giving the following ARGs to the docker build command:
```
docker build \
--build-arg ACCEPT_EULA=Y \
--build-arg SA_PASSWORD=<your secret password> \
. \
-t openimis-db
```

optinnaly
```
--build-arg SQL_SCRIPT_URL=<url to the sql script to create the database> \
--build-arg DB_USER_PASSWORD=StrongPassword
--build-arg DB_USER=IMISUser
--build-arg DB_NAME=IMIS
```
***Notes***:
* by setting the ACCEPT_EULA=Y, you explicitely accept [Microsoft EULA](https://go.microsoft.com/fwlink/?linkid=857698) for the dockerized SQL Server 2017. Please ensure you read it and use the provided software according to the terms of that license.
* choose a strong password (at least 8 chars,...)... or SQL Server will complain


To start the image in a docker container: `docker run -p 1433:1433 openimis-db`
To restore the backup inside the container:
* To spot the ID of the container: `docker container ls` (spot the row with openimis-db IMAGE name)


***Note:***
the container will check if the database exist, if it doesnot it will take the latest demo release version and deploy it , SQL_SCRIPT_URL is per defautl set to "https://github.com/openimis/database_ms_sqlserver/releases/latest/download/sql-files.zip"
to have data retention when container are recreated volums need to be configured as microsoft docs suggest
* <host directory>/data:/var/opt/mssql/data : database files
* <host directory>/log:/var/opt/mssql/log : logs files
* <host directory>/secrets:/var/opt/mssql/secrets : secrets

The database is writen within the container. If you want to keep your data between container execution, stop/start the container via `docker stop <CONTAINER ID>` / `docker start <CONTAINER ID>` (using `docker run ... ` recreates a new container from the image... thus without any data)



## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/openimis/web_app_vb/tags).
Expand Down
6 changes: 0 additions & 6 deletions concatenate_files.ps1

This file was deleted.

File renamed without changes.
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
38 changes: 38 additions & 0 deletions script/run-initialization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash


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


# 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 'download full demo database'
wget $SQL_SCRIPT_URL -O /sql-files.zip
unzip /sql-files.zip -d /app
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"
if [ ${INIT_MODE} -eq "demo" ]; then
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i /app/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c
else
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i /app/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c
fi
echo ' give to the user the access to the database'
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "EXEC sp_changedbowner '$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 ec38870

Please sign in to comment.