Skip to content

Commit 4d589f6

Browse files
committed
NH-3807 - Use custom Firebird 3 Docker image.
1 parent 3c841e4 commit 4d589f6

File tree

5 files changed

+285
-1
lines changed

5 files changed

+285
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
docker:
9696
- *ref-base-image
9797

98-
- image: jacobalberty/firebird:2.5.7-ss
98+
- image: ngbrown/nhibernate-build-firebird
9999
environment:
100100
- ISC_PASSWORD: Password12!
101101
FIREBIRD_USER: nhibernate
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM debian:jessie
2+
3+
ENV PREFIX=/usr/local/firebird
4+
ENV DEBIAN_FRONTEND noninteractive
5+
ENV FBURL=http://downloads.sourceforge.net/project/firebird/firebird/3.0.2-Release/Firebird-3.0.2.32703-0.tar.bz2
6+
ENV DBPATH=/databases
7+
8+
ADD build.sh ./build.sh
9+
10+
RUN chmod +x ./build.sh && \
11+
sync && \
12+
./build.sh && \
13+
rm -f ./build.sh
14+
15+
VOLUME ["/databases", "/var/firebird/run", "/var/firebird/etc", "/var/firebird/log", "/var/firebird/system", "/tmp/firebird"]
16+
17+
EXPOSE 3050/tcp
18+
19+
ADD docker-entrypoint.sh ${PREFIX}/docker-entrypoint.sh
20+
RUN chmod +x ${PREFIX}/docker-entrypoint.sh
21+
22+
ADD docker-entrypoint-async.sh ${PREFIX}/docker-entrypoint-async.sh
23+
RUN chmod +x ${PREFIX}/docker-entrypoint-async.sh
24+
25+
ENTRYPOINT ${PREFIX}/docker-entrypoint-async.sh ${PREFIX}/bin/fbguard
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# docker Firebird
2+
3+
## Default password for `sysdba`
4+
The default password for `sysdba` is randomly generated when you first launch the container,
5+
look in the docker log for your container or pull /var/firebird/etc/SYSDBA.password.
6+
Alternatively you may pass the environment variable ISC_PASSWORD to set the default password.
7+
8+
## Description
9+
This is a Firebird SQL Database container.
10+
11+
## Default Login information
12+
Username: SYSDBA
13+
Password is either set by `ISC_PASSWORD` or randomized
14+
15+
## Environment Variables:
16+
### `TZ`
17+
TimeZone. (i.e. America/Chicago)
18+
19+
### `ISC_PASSWORD`
20+
Default `sysdba` user password, if left blank a random 20 character password will be set instead.
21+
The password used will be placed in /var/firebird/etc/SYSDBA.password.
22+
If a random password is generated then it will be in the log for the container.
23+
24+
### `FIREBIRD_DATABASE`
25+
If this is set then a database will be created with this name under the `/databases` volume with the 'UTF8'
26+
default character set and if `FIREBIRD_USER` is also set then `FIREBIRD_USER` will be given ownership.
27+
28+
### `FIREBIRD_USER`
29+
This user will be created and given ownership of `FIREBIRD_DATABASE`.
30+
This variable is only used if `FIREBIRD_DATABASE` is also set.
31+
32+
### `FIREBIRD_PASSWORD`
33+
The password for `FIREBIRD_USER`, if left blank a random 20 character password will be set instead.
34+
If a random password is generated then it will be in the log for the container.
35+
36+
### `<VARIABLE>_FILE`
37+
If set to the path to a file then the named variable minus the _FILE portion will contain the contents of that file.
38+
This is useful for using docker secrets to manage your password.
39+
This applies to all variables except `TZ`
40+
41+
## Volumes:
42+
43+
### `/databases/`
44+
Default location to put database files
45+
46+
### `/var/firebird/run`
47+
guardian lock DIR
48+
49+
### `/var/firebird/etc`
50+
config files DIR
51+
message files DIR
52+
53+
### `/var/firebird/log`
54+
log files DIR
55+
56+
### `/var/firebird/system`
57+
security database DIR
58+
59+
### `/tmp/firebird`
60+
Database lock directory
61+
62+
## Exposes:
63+
### 3050/tcp
64+
65+
## Events
66+
Please note for events to work properly you must either configure RemoteAuxPort and forward it with -p using a direct mapping where both sides internal and external use the same port or use --net=host to allow the random port mapping to work.
67+
see: http://www.firebirdfaq.org/faq53/ for more information on event port mapping.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -e
3+
CPUC=$(awk '/^processor/{n+=1}END{print n}' /proc/cpuinfo)
4+
5+
apt-get update
6+
apt-get install -qy --no-install-recommends \
7+
libicu52 \
8+
libtommath0
9+
apt-get install -qy --no-install-recommends \
10+
bzip2 \
11+
ca-certificates \
12+
curl \
13+
g++ \
14+
gcc \
15+
libicu-dev \
16+
libncurses5-dev \
17+
libtommath-dev \
18+
make \
19+
zlib1g-dev
20+
mkdir -p /home/firebird
21+
cd /home/firebird
22+
curl -o firebird-source.tar.bz2 -L \
23+
"${FBURL}"
24+
tar --strip=1 -xf firebird-source.tar.bz2
25+
./configure \
26+
--prefix=${PREFIX}/ --with-fbbin=${PREFIX}/bin/ --with-fbsbin=${PREFIX}/bin/ --with-fblib=${PREFIX}/lib/ \
27+
--with-fbinclude=${PREFIX}/include/ --with-fbdoc=${PREFIX}/doc/ --with-fbudf=${PREFIX}/UDF/ \
28+
--with-fbsample=${PREFIX}/examples/ --with-fbsample-db=${PREFIX}/examples/empbuild/ --with-fbhelp=${PREFIX}/help/ \
29+
--with-fbintl=${PREFIX}/intl/ --with-fbmisc=${PREFIX}/misc/ --with-fbplugins=${PREFIX}/ \
30+
--with-fbconf=/var/firebird/etc/ --with-fbmsg=${PREFIX}/ \
31+
--with-fblog=/var/firebird/log/ --with-fbglock=/var/firebird/run/ \
32+
--with-fbsecure-db=/var/firebird/system
33+
make -j${CPUC}
34+
make silent_install
35+
cd /
36+
rm -rf /home/firebird
37+
find ${PREFIX} -name .debug -prune -exec rm -rf {} \;
38+
apt-get purge -qy --auto-remove \
39+
bzip2 \
40+
ca-certificates \
41+
curl \
42+
g++ \
43+
gcc \
44+
libicu-dev \
45+
libncurses5-dev \
46+
libtommath-dev \
47+
make \
48+
zlib1g-dev
49+
rm -rf /var/lib/apt/lists/*
50+
51+
# This allows us to initialize a random value for sysdba password
52+
mv /var/firebird/system/security3.fdb ${PREFIX}/security3.fdb
53+
54+
sed -i 's/^#DatabaseAccess/DatabaseAccess/g' /var/firebird/etc/firebird.conf
55+
sed -i "s~^\(DatabaseAccess\s*=\s*\).*$~\1Restrict ${DBPATH}~" /var/firebird/etc/firebird.conf
56+
57+
# Enable non-secured ADO.NET connector to connect.
58+
echo $'WireCrypt = Enabled
59+
AuthServer = Srp
60+
AuthClient = Srp
61+
UserManager = Srp
62+
'\
63+
>> /var/firebird/etc/firebird.conf
64+
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
set -e
3+
4+
build() {
5+
local var="$1"
6+
local stmt="$2"
7+
export $var+="$(printf "\n${stmt}")"
8+
}
9+
10+
run() {
11+
echo "${!1}" | ${PREFIX}/bin/isql
12+
}
13+
14+
createNewPassword() {
15+
# openssl generates random data.
16+
openssl </dev/null >/dev/null 2>/dev/null
17+
if [ $? -eq 0 ]
18+
then
19+
# We generate 40 random chars, strip any '/''s and get the first 20
20+
NewPasswd=`openssl rand -base64 40 | tr -d '/' | cut -c1-20`
21+
fi
22+
23+
# If openssl is missing...
24+
if [ -z "$NewPasswd" ]
25+
then
26+
NewPasswd=`dd if=/dev/urandom bs=10 count=1 2>/dev/null | od -x | head -n 1 | tr -d ' ' | cut -c8-27`
27+
fi
28+
29+
# On some systems even this routines may be missing. So if
30+
# the specific one isn't available then keep the original password.
31+
if [ -z "$NewPasswd" ]
32+
then
33+
NewPasswd="masterkey"
34+
fi
35+
36+
echo "$NewPasswd"
37+
}
38+
39+
# usage: file_env VAR [DEFAULT]
40+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
41+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
42+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
43+
file_env() {
44+
local var="$1"
45+
local fileVar="${var}_FILE"
46+
local def="${2:-}"
47+
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
48+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
49+
exit 1
50+
fi
51+
local val="$def"
52+
if [ "${!var:-}" ]; then
53+
val="${!var}"
54+
elif [ "${!fileVar:-}" ]; then
55+
val="$(< "${!fileVar}")"
56+
fi
57+
export "$var"="$val"
58+
unset "$fileVar"
59+
}
60+
61+
if [ ! -f "/var/firebird/system/security3.fdb" ]; then
62+
cp ${PREFIX}/security3.fdb /var/firebird/system/security3.fdb
63+
file_env 'ISC_PASSWORD'
64+
if [ -z ${ISC_PASSWORD} ]; then
65+
ISC_PASSWORD=$(createNewPassword)
66+
echo "setting 'SYSDBA' password to '${ISC_PASSWORD}'"
67+
fi
68+
69+
${PREFIX}/bin/isql -user sysdba employee <<EOL
70+
create or alter user SYSDBA password '${ISC_PASSWORD}';
71+
commit;
72+
quit;
73+
EOL
74+
75+
cat > /var/firebird/etc/SYSDBA.password <<EOL
76+
# Firebird generated password for user SYSDBA is:
77+
#
78+
ISC_USER=sysdba
79+
ISC_PASSWORD=${ISC_PASSWORD}
80+
#
81+
# Also set legacy variable though it can't be exported directly
82+
#
83+
ISC_PASSWD=${ISC_PASSWORD}
84+
#
85+
# generated at time $(date)
86+
#
87+
# Your password can be changed to a more suitable one using
88+
# SQL operator ALTER USER.
89+
#
90+
91+
EOL
92+
93+
fi
94+
95+
if [ -f "/var/firebird/etc/SYSDBA.password" ]; then
96+
source /var/firebird/etc/SYSDBA.password
97+
fi;
98+
99+
file_env 'FIREBIRD_USER'
100+
file_env 'FIREBIRD_PASSWORD'
101+
file_env 'FIREBIRD_DATABASE'
102+
103+
build isql "set sql dialect 3;"
104+
if [ ! -z "${FIREBIRD_DATABASE}" -a ! -f "${DBPATH}/${FIREBIRD_DATABASE}" ]; then
105+
if [ "${FIREBIRD_USER}" ]; then
106+
build isql "CONNECT employee USER '${ISC_USER}' PASSWORD '${ISC_PASSWORD}';"
107+
if [ -z "${FIREBIRD_PASSWORD}" ]; then
108+
FIREBIRD_PASSWORD=$(createNewPassword)
109+
echo "setting '${FIREBIRD_USER}' password to '${FIREBIRD_PASSWORD}'"
110+
fi
111+
build isql "CREATE USER ${FIREBIRD_USER} PASSWORD '${FIREBIRD_PASSWORD}';"
112+
build isql "COMMIT;"
113+
fi
114+
115+
stmt="CREATE DATABASE '${DBPATH}/${FIREBIRD_DATABASE}'"
116+
if [ "${FIREBIRD_USER}" ]; then
117+
stmt+=" USER '${FIREBIRD_USER}' PASSWORD '${FIREBIRD_PASSWORD}'"
118+
fi
119+
stmt+=" DEFAULT CHARACTER SET UTF8;";
120+
build isql "${stmt}";
121+
build isql "COMMIT;"
122+
if [ "${isql}" ]; then
123+
build isql "QUIT;"
124+
run isql
125+
fi
126+
fi
127+
128+
$@

0 commit comments

Comments
 (0)