Skip to content

Commit 4aa347f

Browse files
committed
Add dockerfiles for some of supported RDBMSs
1 parent fef4e1a commit 4aa347f

19 files changed

+2308
-0
lines changed

Containers/ReadMe.md

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
# Containers
2+
3+
Containers here are ment to be used for running tests. When built correctly after run they will have required database structure.
4+
Dockerfiles and initialization scripts are grouped into folders and hereafter all examples of build commands assume that they are executed in context of one of the folders.
5+
6+
Across all instances of different RDBMSs we use 'dotest' user with 'dotest' password as cridentials for connection. In some cases user can be changed on container run, but not in all cases. We recommend using default settings, thought test connection password is weak it is fine for test environment and easy to remember.
7+
8+
## MS SQL Server
9+
10+
Dockerfiles are placed in 'mssql' folder.
11+
12+
### Build image
13+
14+
Assuming commands are executed in context of 'mssql' folder, images can be built as following
15+
16+
```console
17+
docker buildx build -f do-mssql-2017 -t do-mssql:2017 .
18+
```
19+
```console
20+
docker buildx build -f do-mssql-2019 -t do-mssql:2019 .
21+
```
22+
23+
Don't forget about the dot at the end.
24+
25+
More information about ```buildx build``` [in docker documentation](https://docs.docker.com/reference/cli/docker/buildx/build/).
26+
27+
### Run container
28+
29+
If images are built like in the examples above then containers can be run like so
30+
31+
```console
32+
docker run --name DO_SQL2017 -h DO_SQL2017 -e ACCEPT_EULA=Y -e MSSQL_PID="Developer" -e MSSQL_SA_PASSWORD="<your sa password>" -e TZ=<timezone of host> -e MSSQL_INIT_WAIT=60 -p 1417:1433 -d do-mssql:2017
33+
```
34+
```console
35+
docker run --name DO_SQL2019 -h DO_SQL2019 -e ACCEPT_EULA=Y -e MSSQL_PID="Developer" -e MSSQL_SA_PASSWORD="<your sa password>" -e TZ=<timezone of host> -e MSSQL_INIT_WAIT=60 -p 1419:1433 -d do-mssql:2019
36+
```
37+
38+
Here,
39+
40+
``` --name``` - name of the container, we use names like in the examples but you can choose any other name.
41+
42+
``` -h``` or ```--hostname``` - it will be required in connection strings, if you are familiar with MS SQL Server installation process then you probably know about named instances. The hosthame here will be name of instance.
43+
44+
``` -e ACCEPT_EULA=Y ``` - accepting EULA, more on [official docker page](https://hub.docker.com/r/microsoft/mssql-server)
45+
46+
``` -e MSSQL_PID="Developer"``` - the edition the container will run with. We develop so we use "Developer" edition (available options listed on [official docker page](https://hub.docker.com/r/microsoft/mssql-server) )
47+
48+
``` -e MSSQL_SA_PASSWORD="<your sa password>" ``` - password for 'sa' user. It should meet MS SQL Server password policies. (more on [official docker page](https://hub.docker.com/r/microsoft/mssql-server) )
49+
50+
``` -e TZ=<timezone of host>``` - Some of tests still assume that test runner and storage insance are in the same timezone. If you run and test locally on your machine, set it to host timezone, otherwise false falling tests appear.
51+
52+
``` -e MSSQL_INIT_WAIT=60 ``` - NOTE, this is not a standard variable. MS SQL Server takes some time to start and begin recieving connections, to not get false connection errors we need to wait for some time. This parameter defines how long we need to wait before first attempt to connect. Depending on how performant host machine is the value might require increase or let be decreased. Default wait time is 60 (seconds).
53+
54+
``` -p 1417:1433``` - host-to-container port mappings. If serveral containers are run on the same host they are required to have different host ports. We use following pattern - first two digits of default port (1433) and last two digits of MS SQL Server version e.g. 17 for 2017, 19 for 2019, so on.
55+
56+
57+
### Connect to instance in docker
58+
59+
To access an instance run in docker use "```<pc name or ip>\hostname, <host port>```" as ```DataSource```, similar to connections to named instances.
60+
61+
Say, Docker's host has name is "WILLY" and containers run with commands above, then connection strings may look like:
62+
63+
```
64+
Data Source=WILLY\DO_SQL2017,1417;Initial Catalog=DO-Tests;User Id=dotest;Password=dotest;MultipleActiveResultSets=True;
65+
```
66+
```
67+
Data Source=WILLY\DO_SQL2019,1419;Initial Catalog=DO-Tests;User Id=dotest;Password=dotest;MultipleActiveResultSets=True;
68+
```
69+
70+
71+
72+
## PostgreSQL
73+
74+
Dockerfiles are placed in 'postgres' folder.
75+
76+
### Build image
77+
78+
Assuming commands are executed in context of 'postgres folder, images can be built with following commands
79+
80+
```console
81+
docker buildx build -f do-postgre-9_0 -t do-postgres:9.0 .
82+
```
83+
```console
84+
docker buildx build -f do-postgre-9_1 -t do-postgres:9.1 .
85+
```
86+
```console
87+
docker buildx build -f do-postgre-9_2 -t do-postgres:9.2 .
88+
```
89+
```console
90+
docker buildx build -f do-postgre-9_6 -t do-postgres:9.6 .
91+
```
92+
```console
93+
docker buildx build -f do-postgre-10 -t do-postgres:10.0 .
94+
```
95+
```console
96+
docker buildx build -f do-postgre-11 -t do-postgres:11.0 .
97+
```
98+
99+
100+
NOTE Images older than 9.6 are unable to update tzdata so some tests can fail due to specific way of working with offset on ```TIMESTAMP WITH TIMEZONE```.
101+
102+
103+
### Run container
104+
105+
Assuming the images are built like in examples above containers can be run like so
106+
107+
```console
108+
docker run --name postgre-9.0 -e POSTGRES_PASSWORD=<your password> -e POSTGRES_HOST_AUTH_METHOD=md5 -e TZ=<timezone of host> -p 5490:5432 -d do-postgres:9.0
109+
```
110+
```console
111+
docker run --name postgre-9.1 -e POSTGRES_PASSWORD=<your password> -e POSTGRES_HOST_AUTH_METHOD=md5 -e TZ=<timezone of host> -p 5491:5432 -d do-postgres:9.1
112+
```
113+
```console
114+
docker run --name postgre-9.2 -e POSTGRES_PASSWORD=<your password> -e POSTGRES_HOST_AUTH_METHOD=md5 -e TZ=<timezone of host> -p 5492:5432 -d do-postgres:9.2
115+
```
116+
```console
117+
docker run --name postgre-9.6 -e POSTGRES_PASSWORD=<your password> -e POSTGRES_HOST_AUTH_METHOD=md5 -e TZ=<timezone of host> -p 5496:5432 -d do-postgres:9.6
118+
```
119+
```console
120+
docker run --name postgre-10 -e POSTGRES_PASSWORD=<your password> -e POSTGRES_HOST_AUTH_METHOD=md5 -e TZ=<timezone of host> -p 54100:5432 -d do-postgres:10.0
121+
```
122+
```console
123+
docker run --name postgre-11 -e POSTGRES_PASSWORD=<your password> -e POSTGRES_HOST_AUTH_METHOD=md5 -e TZ=<timezone of host> -p 54110:5432 -d do-postgres:11.0
124+
```
125+
126+
Here,
127+
128+
``` --name postgre-17``` - name of the container
129+
130+
```-e POSTGRES_PASSWORD=<your password>``` - superuser password, required by base image.
131+
132+
```-e POSTGRES_HOST_AUTH_METHOD=md5``` - option that controlls 'auth-method'. For test purposes 'md5' is ok.
133+
134+
```-e TZ=<timezone of host>``` - Some of tests still assume that test runner and storage insance are in the same timezone. If you run and test locally on your machine, set it to host timezone, otherwise false falling tests appear.
135+
136+
```-p 54110:5432``` - host-to-container port mappings. If serveral containers are run on the same host they require to have different ports. We use following pattern - first two digits of standard port (5432) and PostgreSQL version after that e.g. 110 for 11.0, 96 for 9.6.
137+
138+
139+
During first run of container database structure and users will be created. By default it creates 'dotest' user, 'dotest' database with several schemas within.
140+
We intentionally don't use superuser as owner of database and user for connections, if you change superuser name by using ```POSTGRES_USER``` variable, don't name it 'dotest', otherwise conflict will occur.
141+
142+
143+
More information about standard options [on official image page on docker hub](https://hub.docker.com/_/postgres)
144+
145+
146+
### Connect to instance in docker
147+
148+
To access an instance run in docker use host name and the port you have mapped container to. If we have docker on the same "WILLY" host then connection strings may look like:
149+
150+
```
151+
HOST=WILLY;PORT=5490;DATABASE=dotest;USER ID=dotest;PASSWORD=dotest;
152+
```
153+
```
154+
HOST=WILLY;PORT=5496;DATABASE=dotest;USER ID=dotest;PASSWORD=dotest;
155+
```
156+
```
157+
HOST=WILLY;PORT=54110;DATABASE=dotest;USER ID=dotest;PASSWORD=dotest;
158+
```
159+
160+
for containers postgre-9.0, postgre-9.6, postgre-11 respectively, you get the idea.
161+
162+
163+
# MySQL
164+
165+
Dockerfiles are located in 'mysql' folder.
166+
167+
### Build image
168+
169+
Assuming commands are executed in context of 'mysql' folder, images can be built with following commands
170+
171+
172+
```console
173+
docker buildx build -f do-mysq-5_5 -t do-mysql:5.5 .
174+
```
175+
```console
176+
docker buildx build -f do-mysq-5_6 -t do-mysql:5.6 .
177+
```
178+
179+
180+
### Run container
181+
182+
183+
```console
184+
docker run --name mysql-5.5 -p 3355:3306 -e MYSQL_ROOT_PASSWORD=<your password> -e MYSQL_DATABASE=dotest -e MYSQL_USER=dotest -e MYSQL_PASSWORD=dotest -d do-mysql:5.5
185+
```
186+
```console
187+
docker run --name mysql-5.6 -p 3356:3306 -e MYSQL_ROOT_PASSWORD=<your password> -e MYSQL_DATABASE=dotest -e MYSQL_USER=dotest -e MYSQL_PASSWORD=dotest -d do-mysql:5.6
188+
```
189+
190+
Here,
191+
192+
``` --name mysql-5.6``` - name of container, can be changed, affects nothing
193+
194+
``` -p 3356:3306``` - host-to-container port mapping. We use following pattern - two first digits from default port (3306) folowed by version of MySQL e.g. 56 for MySQL 5.6.
195+
196+
``` -e MYSQL_ROOT_PASSWORD=<your password>``` - root password, required by base image.
197+
198+
``` -e MYSQL_DATABASE=dotest``` - database name to be created, can be changed (don't forget to change connection string) or omitted (initialization script will create 'dotest' database).
199+
200+
``` -e MYSQL_USER=dotest```- user name to be created for connections, can be changed (don't forget to change connection string) or omitted (initialization script will create 'dotest' user with 'dotest' password).
201+
202+
``` -e MYSQL_PASSWORD=dotest``` - password, required if MYSQL_USER is defined.
203+
204+
More information about standard options [on official image page on docker hub](https://hub.docker.com/_/mysql)
205+
206+
207+
208+
### Connect to instance in docker
209+
210+
To access an instance run in docker use host name and port you have mapped container to. If we have docker on the same "WILLY" host then connection strings may look like:
211+
212+
```
213+
Server=WILLY;Port=3355;Database=dotest;Uid=dotest;Pwd=dotest;Default Command Timeout=120;
214+
```
215+
```
216+
Server=WILLY;Port=3356;Database=dotest;Uid=dotest;Pwd=dotest;Default Command Timeout=120;
217+
```
218+
219+
220+
221+
# Firebird
222+
223+
Dockerfiles are located in 'firebird' folder.
224+
225+
### Build image
226+
227+
Assuming commands are executed in context of 'firebird' folder, image can be built with following commands
228+
229+
230+
```console
231+
docker buildx build -f do-firebird-3_0 -t do-firebird:3.0 .
232+
```
233+
234+
235+
### Run container
236+
237+
Assuming the image is built like in the example above container can be run like so
238+
239+
240+
```console
241+
docker run --name firebird-3 -p 3053:3050 -e FIREBIRD_ROOT_PASSWORD=<your password> -e FIREBIRD_USER=dotest -e FIREBIRD_PASSWORD=dotest -e FIREBIRD_DATABASE=DOTEST.fdb -e FIREBIRD_DATABASE_PAGE_SIZE=8192 -d do-firebird:3.0
242+
```
243+
244+
Here,
245+
246+
```--name firebird-3``` - name of contaner, you can choose different name, it doesn't really matter.
247+
248+
```-e FIREBIRD_ROOT_PASSWORD=<your password>``` - root user password.
249+
250+
```-e FIREBIRD_USER=dotest``` - user for connections, can be changed.
251+
252+
```-e FIREBIRD_PASSWORD=dotest``` - user password. Required when user defined.
253+
254+
```-e FIREBIRD_DATABASE=DOTEST.fdb``` - database file name to create.
255+
256+
``` -e FIREBIRD_DATABASE_PAGE_SIZE=8192``` - page size for database.
257+
258+
```-p 3053:3050``` - host-to-container port mapping. We use following pattern - first three digits of standard port (3050) and major version of Firebird, e.g. 3, 4 ,5.
259+
260+
Pair ```FIREBIRD_USER``` / ```FIREBIRD_PASSWORD``` can be omitted, in this case initialization script will handle it and create 'dotest' user with 'dotest' password.
261+
262+
More information about standard options [on official image page on docker hub](https://hub.docker.com/r/firebirdsql/firebird)
263+
264+
265+
### Connect to instance in docker
266+
267+
To access an instance run in docker use host name and port you have mapped container to. If we have docker on the same "WILLY" host then connection string may look like:
268+
269+
```
270+
User=dotest;Password=dotest;Database=dotest;DataSource=WILLY;Port=3053;Dialect=3;Charset=UTF8;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0
271+
```
272+
273+
If you changed user/password for connections then don't forget to update it in connection string.
274+
275+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM firebirdsql/firebird:3.0.10
2+
3+
COPY init-firebird-instance.sh /docker-entrypoint-initdb.d/
4+
5+
RUN chmod +x /docker-entrypoint-initdb.d/init-firebird-instance.sh
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
set -u
4+
5+
echo "Register aliases with default settings for databasees"
6+
7+
/opt/firebird/bin/registerDatabase.sh "DOTEST.fdb" "$FIREBIRD_DATABASE"
8+
echo "Alias DOTEST.fdb => $FIREBIRD_DATABASE registered"
9+
10+
/opt/firebird/bin/registerDatabase.sh "dotest" "$FIREBIRD_DATABASE"
11+
echo "Alias dotest => $FIREBIRD_DATABASE registered"

Containers/mssql/configure-db.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
# Wait 60 seconds (or amount of time requested on run) for SQL Server to start up and start accepting connections.
4+
# Next, wait for same periond to let databases to reach working state by ensuring that
5+
# calling SQLCMD does not return an error code, which will ensure that sqlcmd is accessible
6+
# and that system and user databases return "0" which means all databases are in an "online" state
7+
# https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-databases-transact-sql?view=sql-server-2017
8+
9+
if [ -f /var/opt/mssql/data/DO-Tests.mdf ]; then
10+
echo "INFO: Databases already initialized. Skip database initialization."
11+
exit 0
12+
else
13+
echo "INFO: Databases don't exist. Trying to initialize"
14+
fi
15+
16+
INIT_WAIT=60
17+
[ -n "$MSSQL_INIT_WAIT" ] && INIT_WAIT=$MSSQL_INIT_WAIT
18+
19+
echo "INFO: Initial wait for $INIT_WAIT secs to let SQL Server start and accept connections."
20+
sleep $INIT_WAIT;
21+
22+
DBSTATUS=1
23+
ERRCODE=1
24+
i=0
25+
26+
#Different versions of Sql Server images have sqlcmd in different places
27+
if [ -d "/opt/mssql-tools18/" ]; then
28+
echo "INFO: Trying to login and check databases' states. If the databases are not ready wait for the same time..."
29+
while [[ $i -lt $INIT_WAIT ]] && [[ $ERRCODE -ne 0 ]]; do
30+
((i=i+1))
31+
DBSTATUS=$(/opt/mssql-tools18/bin/sqlcmd -h -1 -t 1 -U sa -P $MSSQL_SA_PASSWORD -C -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases")
32+
ERRCODE=$?
33+
sleep 1
34+
done
35+
36+
if [ $ERRCODE -ne 0 ] OR [ $DBSTATUS -ne 0 ]; then
37+
echo "INFO: SQL Server took more than 120 seconds to start up or one or more databases are not in an ONLINE state"
38+
exit 1
39+
fi
40+
41+
# Run the setup script to create the DB and the schema in the DB
42+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P $MSSQL_SA_PASSWORD -C -d master -i setup.sql
43+
44+
else
45+
echo "INFO: Trying to login and check databases' states. If the databases are not ready wait for the same time..."
46+
while [[ $i -lt $INIT_WAIT ]] && [[ $ERRCODE -ne 0 ]]; do
47+
((i=i+1))
48+
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")
49+
ERRCODE=$?
50+
sleep 1
51+
done
52+
53+
if [ $ERRCODE -ne 0 ] OR [ $DBSTATUS -ne 0 ]; then
54+
echo "INFO: SQL Server took more than 120 seconds to start up or one or more databases are not in an ONLINE state"
55+
exit 1
56+
fi
57+
58+
# Run the setup script to create the DB and the schema in the DB
59+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $MSSQL_SA_PASSWORD -d master -i setup.sql
60+
fi

Containers/mssql/do-mssql-2017

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM mcr.microsoft.com/mssql/server:2017-CU31-ubuntu-18.04
2+
3+
# See https://github.com/microsoft/mssql-docker/blob/master/linux/preview/examples/mssql-agent-fts-ha-tools/Dockerfile
4+
# for details
5+
RUN export DEBIAN_FRONTEND=noninteractive && \
6+
apt-get update && \
7+
#Actualize time zone database
8+
apt-get install -y tzdata && \
9+
apt-get install -yq curl apt-transport-https && \
10+
apt-get install -y gnupg2 && \
11+
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
12+
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list | tee /etc/apt/sources.list.d/mssql-server.list && \
13+
apt-get update && \apt-get install -y mssql-server-fts && \
14+
apt-get clean && \
15+
rm -rf /var/lib/apt/lists
16+
17+
# Create a config directory
18+
RUN mkdir -p /usr/config
19+
WORKDIR /usr/config
20+
21+
# Bundle config source
22+
COPY configure-db.sh /usr/config/
23+
COPY entrypoint.sh /usr/config/
24+
COPY setup.sql /usr/config/
25+
26+
# Grant permissions for to our scripts to be executable
27+
RUN chmod +x /usr/config/entrypoint.sh
28+
RUN chmod +x /usr/config/configure-db.sh
29+
30+
ENTRYPOINT ["./entrypoint.sh"]

0 commit comments

Comments
 (0)