Skip to content

Commit 7741719

Browse files
author
Tobias Sommer
committed
Add intial work on docker-entrypoint-always.d
1 parent 2035bd0 commit 7741719

File tree

7 files changed

+147
-18
lines changed

7 files changed

+147
-18
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

9.4/alpine/.docker-env.local

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
MASTER_DB_HOST=192.168.14.11
2+
MASTER_DB_PORT=5432
3+
MASTER_DB_REPLICATION_PASSWORD=WjH5Dn1W
4+
DB_NAME=msod
5+
6+
DB_USER=django_user
7+
DB_PASSWORD=123
8+
9+
ALFRESCO_HOST=http://10.1.10.37
10+
ALFRESCO_PORT=8180
11+
ALFRESCO_PASSWORD=admin
12+
ALFRESCO_USERNAME=admin
13+
14+
CENTRAL_TOOL_BASE_URL=http://web-central:8000
15+
CENTRAL_TOOL_API_SCHEMA_URL=/issdb/m2m/api/schema/
16+
CENTRAL_TOOL_API_AUTH_USER=admin
17+
CENTRAL_TOOL_API_AUTH_PASSWORD=admin
18+
19+
CENTRAL_TOOL_PM_EXCHANGE_ENDPOINT=/issdb/api/central-exchanged-planning-models/
20+
21+
# production only
22+
DOMAIN_NAME=auth.iss-db.spaceapplications.com
23+
AUTH_SSO_PUBLIC_KEY=a.cert
24+
AUTH_SSO_PRIVATE_KEY=a.key
25+
RAVEN_DSN=
26+
27+
# set to 1 to create empty database (without replication)
28+
CREATE_EMPTY_DB=
29+
30+
EXTRA_ALLOWED_HOSTS=localhost,*
31+
32+
ISS_DB=1
33+
34+
DEPLOYMENT_ENVIRONMENT=production
35+
36+
SILK=
37+
AGENCY_NAME=NASA
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3'
2+
services:
3+
4+
db:
5+
container_name: db
6+
image: postgres/always
7+
env_file: .docker-env.local
8+
# environment:
9+
# - POSTGRES_DB=msod
10+
volumes:
11+
- /var/iss-db/postgres/db/data:/var/lib/postgresql/data:rw
12+
- /var/iss-db/postgres/db/backup:/var/iss-db/backup:rw
13+
- /home/tso/Projects/postgres/9.4/alpine/docker-entrypoint.sh:/docker-entrypoint.sh
14+
- /home/tso/Projects/postgres/9.4/alpine/docker-entrypoint-always.d:/docker-entrypoint-always.d
15+
ports:
16+
- ${DB_LT_PORT:-127.0.0.1:8432}:5432
17+
restart: unless-stopped
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# Configure pg_hba.conf
3+
4+
# NASA might require narrowed down list of allowed ips
5+
allowed_ips="all"
6+
7+
# Echo multiline to file, overwrite existing pg_hba.conf
8+
{
9+
echo "# Local access to db enabled if system user is postgres"
10+
echo "local all postgres peer"
11+
echo
12+
echo "# External access to db requires password and is only enabled for $DB_USER"
13+
echo "host msod $DB_USER $allowed_ips md5"
14+
} > "$PGDATA/pg_hba.conf"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# TODO: Setup msodreporter settings here
4+
5+
# Create a non-superuser user without rights to 1) create databases 2) create users
6+
#/usr/bin/createuser "$DB_USER" -D -R
7+
8+
echo "Creating user $DB_USER if it doesn't exists"
9+
psql -tc "SELECT 1 FROM pg_user WHERE usename = '$DB_USER'" \
10+
| grep -q 1 && echo "User ${DB_USER} already exists" \
11+
|| psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';"
12+
13+
psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $DB_USER;"
14+
psql -c "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $DB_USER;"
15+
psql -c "GRANT ALL PRIVILEGES ON SCHEMA public TO $DB_USER;"
16+
17+
# TODO: Do the below?
18+
#REVOKE CREATE ON SCHEMA public FROM public;
19+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "${CREATE_EMPTY_DB}" == "1" ]; then
4+
echo "${PURPLE}Creating empty database${END}"
5+
# create DB if it doesn't already exist
6+
psql -tc "SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}'" \
7+
| grep -q 1 && echo "Database ${DB_NAME} already exists" \
8+
|| psql -c "CREATE DATABASE ${DB_NAME}"
9+
fi

9.4/alpine/docker-entrypoint.sh

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ file_env() {
2424
unset "$fileVar"
2525
}
2626

27+
# Extraction of script execution function
28+
# usage: do_script /path/file.sh
29+
do_script() {
30+
case "$1" in
31+
*.sh)
32+
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
33+
# https://github.com/docker-library/postgres/pull/452
34+
if [ -x "$1" ]; then
35+
echo "$0: running $1"
36+
"$1"
37+
else
38+
echo "$0: sourcing $1"
39+
. "$1"
40+
fi
41+
;;
42+
*.sql) echo "$0: running $1"; "${psql[@]}" -f "$1"; echo ;;
43+
*.sql.gz) echo "$0: running $1"; gunzip -c "$1" | "${psql[@]}"; echo ;;
44+
*) echo "$0: ignoring $1" ;;
45+
esac
46+
echo
47+
}
48+
49+
2750
if [ "${1:0:1}" = '-' ]; then
2851
set -- postgres "$@"
2952
fi
@@ -143,23 +166,7 @@ if [ "$1" = 'postgres' ]; then
143166

144167
echo
145168
for f in /docker-entrypoint-initdb.d/*; do
146-
case "$f" in
147-
*.sh)
148-
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
149-
# https://github.com/docker-library/postgres/pull/452
150-
if [ -x "$f" ]; then
151-
echo "$0: running $f"
152-
"$f"
153-
else
154-
echo "$0: sourcing $f"
155-
. "$f"
156-
fi
157-
;;
158-
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
159-
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
160-
*) echo "$0: ignoring $f" ;;
161-
esac
162-
echo
169+
do_script "$f"
163170
done
164171

165172
PGUSER="${PGUSER:-$POSTGRES_USER}" \
@@ -168,9 +175,29 @@ if [ "$1" = 'postgres' ]; then
168175
unset PGPASSWORD
169176

170177
echo
171-
echo 'PostgreSQL init process complete; ready for start up.'
178+
echo 'PostgreSQL initialisation process complete'
172179
echo
173180
fi
181+
182+
echo
183+
echo 'PostgreSQL doing default configuration'
184+
echo
185+
186+
# Start
187+
pg_ctl -D "$PGDATA" \
188+
-o "-c listen_addresses=''" \
189+
-w start
190+
191+
for f in /docker-entrypoint-always.d/*; do
192+
do_script "$f"
193+
done
194+
195+
# End
196+
pg_ctl -D "$PGDATA" -m fast -w stop
197+
198+
echo
199+
echo 'PostgreSQL default configuration process complete'
200+
echo
174201
fi
175202

176203
exec "$@"

0 commit comments

Comments
 (0)