#!/usr/bin/env bash """:" # Python wrapper for execution exec python3 "$0" "$@" """ import sys import os import shutil DEFAULT_FILE = "/home/broto/sicabe-core/deploy/generated/host-control/docker-compose.yml" file_path = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_FILE print("==================================================================") print("🚀 MERICA -> Airflow 3 AIP-66 Git DAG Bundles Auto-Injector") print("==================================================================") print(f"Target compose: {file_path}") if not os.path.exists(file_path): print(f"❌ Error: File tidak ditemukan di {file_path}") print("Penggunaan: python3 scripts/inject_airflow_bundle.py [path_ke_docker-compose.yml]") sys.exit(1) # 1. Backup file backup_path = file_path + ".bak" shutil.copyfile(file_path, backup_path) print(f"đŸ›Ąī¸ [1/3] Backup file tersimpan di: {backup_path}") with open(file_path, "r", encoding="utf-8") as f: lines = f.readlines() # Check if already present full_content = "".join(lines) if "AIRFLOW__DAG_PROCESSOR__DAG_BUNDLE_CONFIG_LIST" in full_content: print("â„šī¸ Konfigurasi Git DAG Bundles sudah ada di dalam file. Lewati penyuntikan.") sys.exit(0) in_dag_processor = False in_env = False insert_idx = None indent = " " for i, line in enumerate(lines): if "airflow-dag-processor:" in line: in_dag_processor = True continue if in_dag_processor: # Berhenti jika berpindah ke service berikutnya (indentasi level service: 2 spasi) if line.startswith(" ") and not line.startswith(" ") and not line.strip().startswith("#"): break if line.strip().startswith("environment:"): in_env = True continue if in_env and "AIRFLOW__METRICS__STATSD_PREFIX:" in line: insert_idx = i + 1 break if insert_idx is not None: lines.insert(insert_idx, f'{indent}AIRFLOW__DAG_PROCESSOR__DAG_BUNDLE_STORAGE_PATH: /opt/airflow/dag_bundles\n') lines.insert(insert_idx + 1, f'{indent}AIRFLOW__DAG_PROCESSOR__DAG_BUNDLE_CONFIG_LIST: \'[{{"name":"merica-pipeline","classpath":"airflow.providers.git.bundles.git.GitDagBundle","kwargs":{{"repo_url":"https://repo.sicabe.com/merica-dlh/merica-pipelines.git","tracking_ref":"main","subdir":"dags","refresh_interval":30}}}}]\'\n') with open(file_path, "w", encoding="utf-8") as f: f.writelines(lines) print("🎉 [2/3] SUKSES: Variabel Git DAG Bundles berhasil disuntikkan ke airflow-dag-processor!") print("\n[3/3] Langkah Terakhir — Restart HANYA DAG Processor:") print(" 👉 docker restart sicabe-airflow-dag-processor") print(" 👉 docker logs --tail 30 -f sicabe-airflow-dag-processor\n") else: print("❌ Gagal: Blok 'airflow-dag-processor:' dengan 'environment:' tidak ditemukan.") sys.exit(1)