Files
airflow_neo4j/scripts/init_airflow.sh

55 lines
1.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -e
echo "Initializing Airflow..."
# Инициализация БД (только если первый запуск)
airflow db migrate
# Создание пользователя-админа
if ! airflow users list | grep -q "${AIRFLOW_ADMIN_EMAIL}"; then
echo "Creating Airflow admin user..."
airflow users create \
--username "${AIRFLOW_ADMIN_USER}" \
--firstname "${AIRFLOW_ADMIN_FIRSTNAME}" \
--lastname "${AIRFLOW_ADMIN_LASTNAME}" \
--role Admin \
--email "${AIRFLOW_ADMIN_EMAIL}" \
--password "${AIRFLOW_ADMIN_PASSWORD}"
else
echo "✅ Admin user already exists."
fi
# Создание подключения к Neo4j
if ! airflow connections list | grep -q "${NEO4J_CONN_ID}"; then
echo "🔌 Creating Neo4j connection..."
airflow connections add "${NEO4J_CONN_ID}" \
--conn-type neo4j \
--conn-host "${NEO4J_URI}" \
--conn-login "${NEO4J_USER}" \
--conn-password "${NEO4J_PASSWORD}" \
--conn-port "${NEO4J_PORT}"
else
echo "✅ Neo4j connection already exists."
fi
# Установка Airflow Variables из .env
echo "🧩 Setting Airflow Variables..."
# Helper для установки переменной, если её ещё нет
function set_variable() {
local key=$1
local value=$2
if ! airflow variables get "$key" &>/dev/null; then
airflow variables set "$key" "$value"
echo " $key = $value"
else
echo "$key already exists"
fi
}
set_variable "CONN_ID" "${NEO4J_CONN_ID}"
echo "🎉 Initialization complete! Starting webserver..."
exec airflow webserver