Skip to content

Commit b54d4f5

Browse files
committed
feat(docker): install EQL in the target database if asked
1 parent 25adddc commit b54d4f5

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ services:
3939
- CS_DATABASE__HOST=postgres
4040
- CS_DATABASE__PORT=5432
4141
- CS_PROMETHEUS__ENABLED=${CS_PROMETHEUS__ENABLED:-true}
42+
- CS_DATABASE__INSTALL_EQL=true # install EQL into the PostgreSQL database we start above
4243
networks:
4344
- cipherstash
4445

docker-entrypoint.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
#!/usr/bin/env bash
22
set -eu
33

4+
DATABASE_URL="postgresql://${CS_DATABASE__USERNAME}:${CS_DATABASE__PASSWORD}@${CS_DATABASE__HOST}:${CS_DATABASE__PORT}/${CS_DATABASE__NAME}"
5+
6+
postgres_ready () {
7+
psql ${DATABASE_URL} -c "SELECT 1" > /dev/null 2>&1
8+
}
9+
10+
wait_for_postgres_or_exit() {
11+
host=${CS_DATABASE__HOST}
12+
port=${CS_DATABASE__PORT}
13+
max_retries=20
14+
interval=0.5
15+
attempt=1
16+
echo "Testing presence of PostgreSQL at ${host}:${port} with a maximum of ${max_retries} retries"
17+
18+
until postgres_ready
19+
do
20+
if [ $attempt -lt $max_retries ]; then
21+
echo "Waiting for ${host}:${port}"
22+
sleep $interval
23+
attempt=$(expr $attempt + 1)
24+
else
25+
echo "Unable to connect to ${host}:${port} after ${max_retries} attempts"
26+
exit 64
27+
fi
28+
done
29+
echo "Connected to ${host}:${port} after ${attempt} attempts"
30+
}
31+
432
: "${CS_DATABASE__AWS_BUNDLE_PATH:=./aws-rds-global-bundle.pem}"
533

634
# Optionally pull in the AWS RDS global certificate bundle. This is required
@@ -30,4 +58,31 @@ case "${CS_DATABASE__INSTALL_AWS_RDS_CERT_BUNDLE:-}" in
3058
;;
3159
esac
3260

61+
# Optionally install EQL in the target database
62+
case "${CS_DATABASE__INSTALL_EQL:-}" in
63+
"true") ;&
64+
"yes") ;&
65+
"1")
66+
>&2 echo "Installing EQL in target PostgreSQL database..."
67+
68+
if [ ! -f "/opt/cipherstash-eql.sql" ]; then
69+
>&2 echo "error: unable to find EQL installer at: /opt/cipherstash-eql.sql"
70+
exit 1
71+
fi
72+
73+
# Wait for postgres to become available
74+
wait_for_postgres_or_exit
75+
76+
# Attempt to install EQL
77+
psql --file=/opt/cipherstash-eql.sql --quiet $DATABASE_URL > /dev/null 2>&1
78+
if [ $? != 0 ]; then
79+
>&2 echo "error: unable to install EQL in target PostgreSQL database!"
80+
exit 2
81+
fi
82+
;;
83+
*)
84+
>&2 echo "Not installing EQL in target PostgreSQL database."
85+
;;
86+
esac
87+
3388
exec cipherstash-proxy "$@"

0 commit comments

Comments
 (0)