Files
timeoverflow/entrypoint.sh.tmpl
2026-02-27 16:21:51 +01:00

81 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# NOTE(d1): forked from the following upstream entrypoint script
# https://github.com/coopdevs/timeoverflow/blob/develop/entrypoint.sh
set -e
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
file_env "TIMEOVERFLOW_DB_PASSWORD"
export DATABASE_URL="postgres://timeoverflow:$TIMEOVERFLOW_DB_PASSWORD@db/timeoverflow"
file_env "TIMEOVERFLOW_SECRET_KEY_BASE"
export SECRET_KEY_BASE="${TIMEOVERFLOW_SECRET_KEY_BASE}"
{{ if eq (env "TIMEOVERFLOW_SMTP_ENABLED") "1" }}
file_env "TIMEOVERFLOW_SMTP_PASSWORD"
export SMTP_PASSWORD="${TIMEOVERFLOW_SMTP_PASSWORD}"
{{ end }}
# Run rails by default if sidekiq is specified
if [ -z "$RUN_RAILS" ] && [ -z "$RUN_SIDEKIQ" ]; then
RUN_RAILS=true
echo "⚠️ RUN_RAILS and RUN_SIDEKIQ are not set, defaulting to RUN_RAILS=true, RUN_SIDEKIQ=false"
fi
# ensure booleans
if [ "$RUN_RAILS" == "true" ] || [ "$RUN_RAILS" == "1" ]; then
RUN_RAILS=true
else
RUN_RAILS=false
fi
if [ "$RUN_SIDEKIQ" == "true" ] || [ "$RUN_SIDEKIQ" == "1" ]; then
RUN_SIDEKIQ=true
else
RUN_SIDEKIQ=false
fi
if [ "$RUN_RAILS" == "true" ]; then
echo "✅ Running Rails"
fi
if [ "$RUN_SIDEKIQ" == "true" ]; then
echo "✅ Running Sidekiq"
fi
export RUN_RAILS
export RUN_SIDEKIQ
# Check all the gems are installed or fails.
bundle check
if [ $? -ne 0 ]; then
echo "❌ Gems in Gemfile are not installed, aborting..."
exit 1
else
echo "✅ Gems in Gemfile are installed"
fi
echo "🚀 $@"
exec "$@"