Skip to content

Commit 88b67cc

Browse files
committed
PG* DB env preparation
1 parent d10cccb commit 88b67cc

File tree

9 files changed

+38
-17
lines changed

9 files changed

+38
-17
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# handle legacy DB_SSL configuration, as we couldn't conditionally template that in docker-compose.yml
2+
if [[ -v DB_SSL && "${DB_SSL}" = "true" ]]; then
3+
if [[ -v PGSSLMODE && -v PGREQUIRESSL ]]; then
4+
export PGSSLMODE="require"
5+
else
6+
echo "Fatal: legacy 'DB_SSL=true' specified, but PGSSLMODE or PGREQUIRESSL has already been set. To resolve ambiguity, remove 'DB_SSL=true' from your .env file." > /dev/stderr
7+
exit 100
8+
fi
9+
fi
10+
11+
# handle other legacy DB_* configuration, and fill in our defaults if nothing is specified
12+
# When these PG* variables are _defined_ (even if _empty_), they will be left as-is.
13+
[[ -v PGHOST ]] || export PGHOST=${DB_HOST:-postgres14}
14+
[[ -v PGUSER ]] || export PGUSER=${DB_USER:-odk}
15+
[[ -v PGPASSWORD ]] || export PGPASSWORD=${DB_PASSWORD:-odk}
16+
[[ -v PGDATABASE ]] || export PGDATABASE=${DB_NAME:-odk}
17+
[[ -v PGAPPNAME ]] || export PGAPPNAME=odkcentral

files/service/odk-cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
set -o pipefail
33
shopt -s inherit_errexit
44

5+
# shellcheck disable=SC1090
6+
source /usr/share/odk/env.d/*
7+
58
exec "$(command -v node)" /usr/odk/lib/bin/cli.js "$@"

files/service/scripts/process-backlog.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
set -o pipefail
33
shopt -s inherit_errexit
44

5+
# shellcheck disable=SC1090
6+
source /usr/share/odk/env.d/*
7+
58
cd /usr/odk
69
/usr/local/bin/node lib/bin/process-backlog.js >/proc/1/fd/1 2>/proc/1/fd/2

files/service/scripts/purge.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
set -o pipefail
33
shopt -s inherit_errexit
44

5+
# shellcheck disable=SC1090
6+
source /usr/share/odk/env.d/*
7+
58
cd /usr/odk
69
/usr/local/bin/node lib/bin/purge.js >/proc/1/fd/1 2>/proc/1/fd/2

files/service/scripts/reap-sessions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
set -o pipefail
33
shopt -s inherit_errexit
44

5+
# shellcheck disable=SC1090
6+
source /usr/share/odk/env.d/*
7+
58
cd /usr/odk
69
/usr/local/bin/node lib/bin/reap-sessions.js >/proc/1/fd/1 2>/proc/1/fd/2

files/service/scripts/run-analytics.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
set -o pipefail
33
shopt -s inherit_errexit
44

5+
# shellcheck disable=SC1090
6+
source /usr/share/odk/env.d/*
7+
58
cd /usr/odk
69
/usr/local/bin/node lib/bin/run-analytics.js >/proc/1/fd/1 2>/proc/1/fd/2

files/service/scripts/start-odk.sh

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,8 @@ SENTRY_TAGS="{ \"version.central\": \"$(cat sentry-versions/central)\", \"versio
1717
# shellcheck disable=SC2090
1818
export SENTRY_TAGS
1919

20-
# handle legacy DB_SSL configuration, as we couldn't conditionally template that in docker-compose.yml
21-
if [[ -v DB_SSL && "${DB_SSL}" = "true" ]]; then
22-
if [[ -v PGSSLMODE && -v PGREQUIRESSL ]]; then
23-
export PGSSLMODE="require"
24-
else
25-
echo "Fatal: legacy 'DB_SSL=true' specified, but PGSSLMODE or PGREQUIRESSL has already been set. To resolve ambiguity, remove 'DB_SSL=true' from your .env file." > /dev/stderr
26-
exit 100
27-
fi
28-
fi
29-
30-
# handle other legacy DB_* configuration, and fill in our defaults if nothing is specified
31-
# When these PG* variables are _defined_ (even if _empty_), they will be left as-is.
32-
[[ -v PGHOST ]] || export PGHOST=${DB_HOST:-postgres14}
33-
[[ -v PGUSER ]] || export PGUSER=${DB_USER:-odk}
34-
[[ -v PGPASSWORD ]] || export PGPASSWORD=${DB_PASSWORD:-odk}
35-
[[ -v PGDATABASE ]] || export PGDATABASE=${DB_NAME:-odk}
36-
[[ -v PGAPPNAME ]] || export PGAPPNAME=odkcentral
20+
# shellcheck disable=SC1090
21+
source /usr/share/odk/env.d/*
3722

3823
echo "waiting for PostgreSQL to become connectable to..."
3924
while ! (psql --no-password --quiet --command "" > /dev/null 2>&1 || (echo "sleeping 1 second waiting for a database connection"; false)); do sleep 1; done

files/service/scripts/upload-blobs.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
set -o pipefail
33
shopt -s inherit_errexit
44

5+
# shellcheck disable=SC1090
6+
source /usr/share/odk/env.d/*
7+
58
cd /usr/odk
69
/usr/local/bin/node lib/bin/s3.js upload-pending >/proc/1/fd/1 2>/proc/1/fd/2

service.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ COPY files/shared/envsub.awk /scripts/
6060
COPY files/service/scripts/ ./
6161

6262
COPY files/service/config.json.template /usr/share/odk/
63+
COPY files/service/env.d/ /usr/share/odk/env.d/
6364
COPY files/service/crontab /etc/cron.d/odk
6465
COPY files/service/odk-cmd /usr/bin/
6566

0 commit comments

Comments
 (0)