first commit
This commit is contained in:
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# eBdesk SiCABE — Airflow Entrypoint Wrapper
|
||||
# =============================================================================
|
||||
# 1. Install sling CLI (binary, not available via pip)
|
||||
# 2. Delegate ke Airflow entrypoint asli untuk service start
|
||||
# =============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# ─── Percayai sertifikat TLS Trino (dev, self-signed) ───────────────────────
|
||||
# Sebagian klien MEMVERIFIKASI TLS dan tidak punya opsi mematikannya — contohnya
|
||||
# Great Expectations / trino client (`verify=True`) dan DQ native OpenMetadata.
|
||||
# Alih-alih `append` ke certifi (dgn guard marker) — yang MEMBUAT certifi tetap
|
||||
# memegang cert LAMA setelah cert Trino di-regenerasi — kita bangun ULANG bundle
|
||||
# CA (certifi + cert Trino) setiap start, lalu arahkan REQUESTS_CA_BUNDLE /
|
||||
# SSL_CERT_FILE ke sana. Verifikasi TLS TETAP aktif.
|
||||
CA_SRC="/etc/ssl/trino/trino.crt"
|
||||
SICABE_CA="/tmp/sicabe-ca.pem"
|
||||
if [[ -f "${CA_SRC}" ]]; then
|
||||
CERTIFI_BUNDLE="$(python -c 'import certifi;print(certifi.where())' 2>/dev/null || true)"
|
||||
if [[ -n "${CERTIFI_BUNDLE}" && -f "${CERTIFI_BUNDLE}" ]]; then
|
||||
if cat "${CERTIFI_BUNDLE}" "${CA_SRC}" > "${SICABE_CA}" 2>/dev/null; then
|
||||
export REQUESTS_CA_BUNDLE="${SICABE_CA}"
|
||||
export SSL_CERT_FILE="${SICABE_CA}"
|
||||
echo "[SiCABE] CA bundle (certifi + Trino) → ${SICABE_CA} (selalu dibangun ulang)."
|
||||
else
|
||||
echo "[SiCABE] WARNING: gagal membangun CA bundle — lanjut."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# ─── Install sling CLI jika belum ada (NON-BLOCKING, fail-fast) ─────────────
|
||||
# Install ke ~/.local/bin (writable oleh user airflow, sudah di PATH)
|
||||
if ! command -v sling &>/dev/null; then
|
||||
echo "[SiCABE] Installing sling CLI (timeout 15s)..."
|
||||
SLING_VER="1.5.23"
|
||||
mkdir -p "${HOME}/.local/bin"
|
||||
if curl -fL --max-time 15 --connect-timeout 5 \
|
||||
"https://github.com/slingdata-io/sling-cli/releases/download/v${SLING_VER}/sling_linux_amd64.tar.gz" \
|
||||
-o /tmp/sling.tar.gz 2>/dev/null && tar -xzf /tmp/sling.tar.gz -C /tmp/ 2>/dev/null && [[ -f /tmp/sling ]]; then
|
||||
chmod +x /tmp/sling
|
||||
mv /tmp/sling "${HOME}/.local/bin/sling"
|
||||
echo "[SiCABE] Sling CLI v${SLING_VER} installed: $(sling --version 2>&1)"
|
||||
else
|
||||
echo "[SiCABE] WARNING: sling CLI download gagal — lanjut tanpa sling (DAG akan warning)."
|
||||
fi
|
||||
rm -rf /tmp/sling.tar.gz /tmp/sling 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# ─── Copy dbt project ke home airflow (writable) ────────────────────────────
|
||||
# Mount /opt/airflow/dbt adalah read-only (host bind). dbt perlu menulis
|
||||
# target/, logs/, dbt_packages/. Copy ke ~/dbt yang writable oleh airflow.
|
||||
if [[ -d /opt/airflow/dbt/sicabe && ! -d "${HOME}/dbt/sicabe" ]]; then
|
||||
echo "[SiCABE] Copying dbt project ke ${HOME}/dbt..."
|
||||
mkdir -p "${HOME}/dbt"
|
||||
cp -r /opt/airflow/dbt/sicabe "${HOME}/dbt/sicabe"
|
||||
cp /opt/airflow/dbt/profiles.yml "${HOME}/dbt/profiles.yml"
|
||||
echo "[SiCABE] dbt project siap di ${HOME}/dbt/sicabe"
|
||||
fi
|
||||
|
||||
# ─── Copy Great Expectations ke home airflow (writable) ─────────────────────
|
||||
if [[ -d /opt/airflow/great_expectations && ! -d "${HOME}/great_expectations" ]]; then
|
||||
echo "[SiCABE] Copying Great Expectations ke ${HOME}/great_expectations..."
|
||||
cp -r /opt/airflow/great_expectations "${HOME}/great_expectations"
|
||||
echo "[SiCABE] Great Expectations siap di ${HOME}/great_expectations"
|
||||
fi
|
||||
|
||||
# ─── LINK sling env.yaml ke ~/.sling (SELALU ikut file yang di-mount) ───────
|
||||
# WAJIB symlink, bukan copy: bootstrap men-regenerasi /opt/airflow/sling/env.yaml
|
||||
# SETELAH container start (host-aware), sehingga salinan hasil `cp` menjadi STALE
|
||||
# (gejala: Sling "lookup postgres ... server misbehaving"). Symlink → perubahan
|
||||
# langsung terbaca tanpa restart. ~/.sling/ tetap writable untuk .sling.db.
|
||||
# NON-FATAL: jangan sampai crash-loop container (set -e).
|
||||
# Dibuat TANPA syarat berkas ada: bila env.yaml belum ada saat start (bootstrap jalan
|
||||
# SETELAH container), symlink "menggantung" lalu VALID begitu berkas muncul. Dulu ada
|
||||
# guard `[[ -f … ]]` → symlink tak dibuat → Sling "could not find connection POSTGRES_DB".
|
||||
mkdir -p "${HOME}/.sling"
|
||||
rm -f "${HOME}/.sling/env.yaml" 2>/dev/null || true
|
||||
ln -s /opt/airflow/sling/env.yaml "${HOME}/.sling/env.yaml" \
|
||||
&& echo "[SiCABE] Sling env.yaml -> symlink ${HOME}/.sling/env.yaml" \
|
||||
|| echo "[SiCABE] WARNING: gagal symlink sling env.yaml — lanjut."
|
||||
|
||||
# ─── dbt-trino http_scheme ──────────────────────────────────────────────────
|
||||
# Sejak image di-build dari paket resmi (tanpa patch), http_scheme sudah HTTPS
|
||||
# lewat config/airflow/dbt/profiles.yml — tidak ada patch yang perlu dibalik.
|
||||
|
||||
# ─── Delegasikan ke entrypoint asli Airflow ─────────────────────────────────
|
||||
# Airflow official entrypoint ada di /entrypoint
|
||||
if [[ -x /entrypoint ]]; then
|
||||
exec /entrypoint "$@"
|
||||
elif [[ -x /usr/bin/docker-entrypoint.sh ]]; then
|
||||
exec /usr/bin/docker-entrypoint.sh "$@"
|
||||
else
|
||||
echo "[SiCABE] WARNING: Airflow entrypoint tidak ditemukan, menjalankan langsung..."
|
||||
exec "$@"
|
||||
fi
|
||||
Reference in New Issue
Block a user