Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SQLite dbs #6

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions readme-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ param_usage_include_ports: true
param_ports:
- { external_port: "8080", internal_port: "8080", port_desc: "API port" }

param_usage_include_env: true
param_env_vars:
- { env_var: "HISHTORY_POSTGRES_DB", env_value: "postgresql://${HISHTORY_DB_USER}:${HISHTORY_DB_PASS}@hishtory-db:5432/hishtory?sslmode=disable", desc: "Postgres DB [Connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). Special characters must be [URL encoded](https://en.wikipedia.org/wiki/URL_encoding)."}
param_usage_include_env: false

opt_param_usage_include_env: false
opt_param_usage_include_env: true
opt_param_env_vars:
- { env_var: "HISHTORY_POSTGRES_DB", env_value: "postgresql://${HISHTORY_DB_USER}:${HISHTORY_DB_PASS}@hishtory-db:5432/hishtory?sslmode=disable", desc: "Postgres DB [Connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). Special characters must be [URL encoded](https://en.wikipedia.org/wiki/URL_encoding)."}
- { env_var: "HISHTORY_SQLITE_DB", env_value: "/config/hishtory.db", desc: "SQLite database path. Needs to be a mounted volume for persistence. Don't set at the same time as HISHTORY_POSTGRES_DB."}

app_setup_block_enabled: true
app_setup_block: |
Expand Down
17 changes: 9 additions & 8 deletions root/etc/s6-overlay/s6-rc.d/init-hishtory-config/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
if [[ -n ${HISHTORY_POSTGRES_DB} ]]; then
DBHOST=$(echo "${HISHTORY_POSTGRES_DB}" | awk -F '@' '{print $NF}' | awk -F ':' '{print $1}')
DBPORT=$(echo "${HISHTORY_POSTGRES_DB}" | awk -F '@' '{print $NF}' | awk -F ':' '{print $2}' | awk -F '/' '{print $1}')
echo "Waiting for DB ${DBHOST} to become available on port ${DBPORT}..."
while :; do
if nc -w 1 -z "$DBHOST" "$DBPORT" > /dev/null 2>&1; then
exit 0
fi
sleep 3
done
elif [[ -n ${HISHTORY_SQLITE_DB} ]]; then
echo "Using SQLite database, ensure you have mounted $(dirname "${HISHTORY_SQLITE_DB}") to your host"
else
echo "No database configured, sleeping..."
sleep infinity
fi

echo "Waiting for DB ${DBHOST} to become available on port ${DBPORT}..."
while :; do
if nc -w 1 -z "$DBHOST" "$DBPORT" > /dev/null 2>&1; then
exit 0
fi
sleep 3
done