diff --git a/.env.example b/.env.example index 5a7acc6..b118e88 100644 --- a/.env.example +++ b/.env.example @@ -44,6 +44,9 @@ DEVICE_POSTGRES_PASSWORD= DEVICE_SECRET_KEY= TELEMETRY_SERVICE_URL="http://telemetry:8080" +# TimescaleDB Service +TIMESCALEDB_PASSWORD= + # EMQX Service EMQX_HOST="http://emqx:18083/api/v5" EMQX_USERNAME= @@ -58,9 +61,6 @@ MQTT_TOPICS="tenant/+/transformed/device/location" EMAIL_HOST_USER= EMAIL_HOST_PASSWORD= DEFAULT_FROM_EMAIL="no-reply@gmail.com" -EMAIL_BACKEND= -EMAIL_PORT= -EMAIL_USE_TLS= # MPA service MQTT_BROKER="emqx" diff --git a/entrypoint.sh b/entrypoint.sh index 740f7fe..cf5b286 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,13 @@ #!/usr/bin/env bash + +# Check if .env file exists +if [ ! -f .env ]; then + echo -e "\033[1;31mERROR: .env file not found!\033[0m" + echo -e "\033[0;33mYou can copy from .env.example if available:\033[0m" + echo -e " cp .env.example .env" + exit 1 +fi + set -a source .env set +a @@ -55,6 +64,30 @@ if [ "$PASSWORD_CHANGED" = true ]; then docker exec rabbitmq rabbitmqctl change_password "$RABBITMQ_DEFAULT_USER" "$RABBITMQ_DEFAULT_PASS" fi +sync_postgres_password() { + local container_name=$1 + local new_password=$2 + local db_user=${3:-postgres} + + if docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then + for i in {1..10}; do + if docker exec "$container_name" pg_isready -U "$db_user" &>/dev/null; then + break + fi + sleep 1 + done + + docker exec "$container_name" psql -U "$db_user" -c "ALTER USER ${db_user} WITH PASSWORD '${new_password}';" &>/dev/null || true + fi +} + +# Sync all PostgreSQL passwords from .env BEFORE stopping +sync_postgres_password "device_postgres" "$DEVICE_POSTGRES_PASSWORD" +sync_postgres_password "auth_postgres" "$AUTH_POSTGRES_PASSWORD" +sync_postgres_password "dashboard_postgres" "$DASHBOARD_POSTGRES_PASSWORD" +sync_postgres_password "bootstrap_postgres" "$BOOTSTRAP_POSTGRES_PASSWORD" +sync_postgres_password "timescaledb" "$TIMESCALEDB_PASSWORD" + echo "Deploying SpaceDF Core..." echo "Stopping existing services (if running)..." docker compose -f "${COMPOSE_FILE}" -p "${PROJECT_NAME}" stop || true diff --git a/generate-keys.sh b/generate-keys.sh index 824d6c2..fcba559 100755 --- a/generate-keys.sh +++ b/generate-keys.sh @@ -26,6 +26,7 @@ env_vars = { 'DASHBOARD_POSTGRES_PASSWORD': 'postgres', 'DEVICE_POSTGRES_PASSWORD': 'postgres', 'BOOTSTRAP_POSTGRES_PASSWORD': 'postgres', + 'TIMESCALEDB_PASSWORD': 'postgres', 'EMQX_USERNAME': 'user', 'EMQX_PASSWORD': 'password123', 'MQTT_BROKER_BRIDGE_PASSWORD': 'Default@1234',