Files
merica/setup.sh
T

105 lines
4.5 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
# ==============================================================================
# MERICA STANDALONE APPLIANCE — ONE-CLICK SETUP & INSTALLATION SCRIPT
# ==============================================================================
set -e
# Warna Terminal
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}"
echo "=============================================================================="
echo " __ ___ ______ ____ ____ ______ ___ "
echo " / |/ / / ____/ / __ \ / _/ / ____/ / |"
echo " / /|_/ / / __/ / /_/ / / / / / / /| |"
echo " / / / / / /___ / _, _/ _/ / / /___ / ___ |"
echo "/_/ /_/ /_____/ /_/ |_| /___/ \____/ /_/ |_|"
echo " Managed Engine for Robust Ingestion & Cloud Airflow — Standalone Release"
echo "=============================================================================="
echo -e "${NC}"
# 1. Periksa ketersediaan Docker & Docker Compose
echo -e "🔍 [1/5] Memeriksa prasyarat Docker host..."
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Error: Docker belum terinstal pada mesin ini. Silakan pasang Docker terlebih dahulu.${NC}"
exit 1
fi
COMPOSE_CMD=""
if docker compose version &> /dev/null; then
COMPOSE_CMD="docker compose"
elif command -v docker-compose &> /dev/null; then
COMPOSE_CMD="docker-compose"
else
echo -e "${RED}❌ Error: Docker Compose tidak ditemukan. Harap pasang docker compose plugin.${NC}"
exit 1
fi
echo -e "${GREEN}✅ Docker dan Docker Compose terdeteksi.${NC}"
# 2. Periksa Berkas .env
echo -e "⚙️ [2/5] Menyiapkan berkas konfigurasi lingkungan (.env)..."
if [ ! -f .env ]; then
echo -e "${YELLOW}ℹ️ Berkas .env belum ditemukan. Membuat salinan dari .env.example...${NC}"
cp .env.example .env
echo -e "${GREEN}✅ Berkas .env berhasil dibuat dengan konfigurasi default.${NC}"
else
echo -e "${GREEN}✅ Berkas .env sudah ada.${NC}"
fi
# Load port dari .env jika ada
MERICA_PORT=$(grep -E "^MERICA_PORT=" .env | cut -d '=' -f2 | tr -d ' ' || echo "14000")
MERICA_PORT=${MERICA_PORT:-14000}
AIRFLOW_URL=$(grep -E "^AIRFLOW_WEB_URL=" .env | cut -d '=' -f2 | tr -d ' ' || echo "http://host.docker.internal:14080")
# 3. Verifikasi Starter Seed Pipelines (Anti-Blank Canvas)
echo -e "📁 [3/5] Memverifikasi template starter pipelines..."
if [ -d "./pipelines/configs" ] && [ "$(ls -A ./pipelines/configs 2>/dev/null)" ]; then
TOTAL_DAGS=$(ls -1 ./pipelines/configs/*.yaml 2>/dev/null | wc -l)
echo -e "${GREEN}✅ Ditemukan ${TOTAL_DAGS} template pipeline di ./pipelines/configs. Daftar DAG akan langsung muncul!${NC}"
else
echo -e "${YELLOW}⚠️ Peringatan: Folder ./pipelines/configs kosong. Membuat folder direktori default...${NC}"
mkdir -p ./pipelines/configs ./pipelines/metadata ./pipelines/dbt
fi
# 4. Menjalankan Kontainer Standalone Appliance
echo -e "🚀 [4/5] Menjalankan MERICA Standalone Appliance..."
$COMPOSE_CMD up -d
# 5. Menunggu Health-Check Endpoint Aktif
echo -e "⏳ [5/5] Menunggu kesiapan layanan MERICA pada port ${MERICA_PORT}..."
MAX_RETRIES=15
COUNTER=0
SUCCESS=0
while [ $COUNTER -lt $MAX_RETRIES ]; do
if curl -s -f "http://localhost:${MERICA_PORT}/api/v1/health" &> /dev/null; then
SUCCESS=1
break
fi
sleep 2
COUNTER=$((COUNTER + 1))
echo -n "."
done
echo ""
if [ $SUCCESS -eq 1 ]; then
echo -e "\n${GREEN}==============================================================================${NC}"
echo -e "${GREEN}🎉 MERICA STANDALONE APPLIANCE BERHASIL AKTIF & SEHAT!${NC}"
echo -e "${GREEN}==============================================================================${NC}"
echo -e "🌐 Antarmuka Web MERICA : ${BLUE}http://localhost:${MERICA_PORT}${NC}"
echo -e "🔗 Airflow Target : ${YELLOW}${AIRFLOW_URL}${NC}"
echo -e "🔑 Kredensial Default : Username: ${GREEN}admin${NC} | Password: ${GREEN}admin${NC}"
echo -e "📁 Direktori Pipeline : ./pipelines (Configs, Metadata, & dbt)"
echo -e "=============================================================================="
echo -e "💡 Tips: Buka browser Anda di ${BLUE}http://localhost:${MERICA_PORT}${NC} untuk mulai merancang DAG!"
echo -e " Untuk menghentikan: ${YELLOW}$COMPOSE_CMD down${NC}"
echo -e "==============================================================================\n"
else
echo -e "${YELLOW}⚠️ Kontainer sudah berjalan tetapi respons health-check belum terbaca.${NC}"
echo -e "Silakan periksa log kontainer dengan: ${BLUE}$COMPOSE_CMD logs -f merica${NC}"
fi