2021-08-01 14:27:44 -07:00
|
|
|
#!/usr/bin/env bash
|
2025-04-03 10:39:47 +05:30
|
|
|
# Copyright 2025 Collate
|
|
|
|
|
# Licensed under the Collate Community License, Version 1.0 (the "License");
|
2021-12-01 12:46:28 +05:30
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
2025-04-03 10:39:47 +05:30
|
|
|
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
|
2021-12-01 12:46:28 +05:30
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
2021-08-02 15:08:30 +05:30
|
|
|
|
2022-08-30 23:55:46 +02:00
|
|
|
DB_HOST=${DB_HOST:-mysql}
|
|
|
|
|
DB_PORT=${DB_PORT:-3306}
|
2022-03-16 22:54:14 -07:00
|
|
|
|
2022-08-30 23:55:46 +02:00
|
|
|
AIRFLOW_DB=${AIRFLOW_DB:-airflow_db}
|
|
|
|
|
DB_USER=${DB_USER:-airflow_user}
|
2025-11-21 16:58:28 +05:30
|
|
|
DB_SCHEME=${DB_SCHEME:-mysql+mysqldb}
|
2022-08-30 23:55:46 +02:00
|
|
|
DB_PASSWORD=${DB_PASSWORD:-airflow_pass}
|
2023-12-06 19:56:19 +05:30
|
|
|
DB_PROPERTIES=${DB_PROPERTIES:-""}
|
2022-03-16 22:54:14 -07:00
|
|
|
|
|
|
|
|
AIRFLOW_ADMIN_USER=${AIRFLOW_ADMIN_USER:-admin}
|
|
|
|
|
AIRFLOW_ADMIN_PASSWORD=${AIRFLOW_ADMIN_PASSWORD:-admin}
|
|
|
|
|
|
2023-12-04 18:09:42 +05:30
|
|
|
DB_USER_VAR=`echo "${DB_USER}" | python3 -c "import urllib.parse; encoded_user = urllib.parse.quote(input()); print(encoded_user)"`
|
|
|
|
|
DB_PASSWORD_VAR=`echo "${DB_PASSWORD}" | python3 -c "import urllib.parse; encoded_user = urllib.parse.quote(input()); print(encoded_user)"`
|
|
|
|
|
|
|
|
|
|
DB_CONN=`echo -n "${DB_SCHEME}://${DB_USER_VAR}:${DB_PASSWORD_VAR}@${DB_HOST}:${DB_PORT}/${AIRFLOW_DB}${DB_PROPERTIES}"`
|
2022-03-16 22:54:14 -07:00
|
|
|
|
2025-11-21 16:58:28 +05:30
|
|
|
# Airflow 3.x configuration
|
|
|
|
|
export AIRFLOW__API__AUTH_BACKENDS=${AIRFLOW__API__AUTH_BACKENDS:-"airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session"}
|
|
|
|
|
export AIRFLOW__API__BASE_URL=${AIRFLOW__API__BASE_URL:-"http://localhost:8080"}
|
2024-04-25 14:18:41 +02:00
|
|
|
|
2025-11-21 16:58:28 +05:30
|
|
|
# Enable CSRF for API endpoints (required for production security)
|
|
|
|
|
export AIRFLOW__API__ENABLE_CSRF=${AIRFLOW__API__ENABLE_CSRF:-"True"}
|
|
|
|
|
|
|
|
|
|
# Configure SimpleAuthManager
|
|
|
|
|
echo "Configuring SimpleAuthManager (default in Airflow 3.x)"
|
|
|
|
|
export AIRFLOW__CORE__SIMPLE_AUTH_MANAGER_USERS="${AIRFLOW_ADMIN_USER}:admin"
|
|
|
|
|
|
|
|
|
|
AIRFLOW_HOME=${AIRFLOW_HOME:-/opt/airflow}
|
|
|
|
|
export AIRFLOW__CORE__SIMPLE_AUTH_MANAGER_PASSWORDS_FILE="${AIRFLOW_HOME}/simple_auth_manager_passwords.json"
|
|
|
|
|
|
|
|
|
|
# Airflow 3.x uses [database] section for SQL Alchemy connection
|
2024-04-25 14:18:41 +02:00
|
|
|
export AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=${AIRFLOW__DATABASE__SQL_ALCHEMY_CONN:-$DB_CONN}
|
2022-03-16 22:54:14 -07:00
|
|
|
|
2024-06-05 21:18:37 +02:00
|
|
|
airflow db migrate
|
2022-03-16 22:54:14 -07:00
|
|
|
|
2025-11-21 16:58:28 +05:30
|
|
|
# Create users for SimpleAuthManager
|
|
|
|
|
echo "SimpleAuthManager configured - user: ${AIRFLOW_ADMIN_USER}:admin"
|
|
|
|
|
|
|
|
|
|
AIRFLOW_HOME=${AIRFLOW_HOME:-/opt/airflow}
|
|
|
|
|
PASSWORD_FILE="${AIRFLOW_HOME}/simple_auth_manager_passwords.json"
|
|
|
|
|
|
|
|
|
|
echo "Setting password for ${AIRFLOW_ADMIN_USER} in ${PASSWORD_FILE}..."
|
|
|
|
|
mkdir -p "${AIRFLOW_HOME}"
|
|
|
|
|
|
|
|
|
|
python3 -c "
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
password_file = Path('${PASSWORD_FILE}')
|
|
|
|
|
passwords = {}
|
|
|
|
|
|
|
|
|
|
if password_file.exists():
|
|
|
|
|
try:
|
|
|
|
|
with open(password_file, 'r') as f:
|
|
|
|
|
passwords = json.load(f)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
passwords['${AIRFLOW_ADMIN_USER}'] = '${AIRFLOW_ADMIN_PASSWORD}'
|
|
|
|
|
|
|
|
|
|
with open(password_file, 'w') as f:
|
|
|
|
|
json.dump(passwords, f, indent=2)
|
|
|
|
|
|
|
|
|
|
print(f'Password set for ${AIRFLOW_ADMIN_USER}')
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
echo "SimpleAuthManager user created with custom password"
|
2022-03-16 22:54:14 -07:00
|
|
|
|
2022-09-20 23:37:39 +02:00
|
|
|
rm -f /opt/airflow/airflow-webserver-monitor.pid
|
2025-11-21 16:58:28 +05:30
|
|
|
|
|
|
|
|
# Start Airflow 3.x components
|
|
|
|
|
echo "Starting Airflow 3.x components..."
|
|
|
|
|
nohup airflow api-server --port 8080 > /opt/airflow/logs/api-server.log 2>&1 &
|
|
|
|
|
nohup airflow dag-processor > /opt/airflow/logs/dag-processor.log 2>&1 &
|
2022-03-09 03:21:07 +05:30
|
|
|
airflow scheduler
|