78 lines
2.7 KiB
Bash
Executable File
78 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
NS="${NS:-tafsirquran}"
|
|
API_IMAGE="${API_IMAGE:-tafsirquran-api:latest}"
|
|
WEB_IMAGE="${WEB_IMAGE:-tafsirquran-web:latest}"
|
|
MANIFEST="${MANIFEST:-$ROOT/k8s/manifest.yaml}"
|
|
PUBLIC_WEB="${PUBLIC_WEB:-https://quran.afrino.co}"
|
|
PUBLIC_API="${PUBLIC_API:-https://quranb.afrino.co}"
|
|
|
|
PROXY="${HTTPS_PROXY:-${HTTP_PROXY:-${https_proxy:-${http_proxy:-}}}}"
|
|
NO_PROXY_VAL="${NO_PROXY:-${no_proxy:-127.0.0.1,localhost,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}}"
|
|
BUILD_ARGS=()
|
|
if [ -n "${PROXY}" ]; then
|
|
echo "==> docker builds with proxy=${PROXY}"
|
|
BUILD_ARGS+=(
|
|
--build-arg "HTTP_PROXY=${PROXY}"
|
|
--build-arg "HTTPS_PROXY=${PROXY}"
|
|
--build-arg "http_proxy=${PROXY}"
|
|
--build-arg "https_proxy=${PROXY}"
|
|
--build-arg "NO_PROXY=${NO_PROXY_VAL}"
|
|
--build-arg "no_proxy=${NO_PROXY_VAL}"
|
|
)
|
|
fi
|
|
|
|
build_with_retry() {
|
|
local dockerfile="$1"
|
|
local tag="$2"
|
|
shift 2
|
|
local attempt=1
|
|
local max_attempts=3
|
|
until docker build "${BUILD_ARGS[@]}" "$@" -f "${dockerfile}" -t "${tag}" .; do
|
|
if [ "$attempt" -ge "$max_attempts" ]; then
|
|
echo "docker build ${tag} failed after ${max_attempts} attempts" >&2
|
|
exit 1
|
|
fi
|
|
echo "==> ${tag} build failed (attempt ${attempt}); retry in 15s"
|
|
attempt=$((attempt + 1))
|
|
sleep 15
|
|
done
|
|
}
|
|
|
|
echo "==> remove legacy postgres resources if present"
|
|
kubectl -n "${NS}" delete deploy tafsirquran-postgres --ignore-not-found
|
|
kubectl -n "${NS}" delete svc tafsirquran-postgres --ignore-not-found
|
|
kubectl -n "${NS}" delete pvc tafsirquran-pg-data --ignore-not-found
|
|
|
|
echo "==> build api + web (wasm/nginx)"
|
|
build_with_retry Dockerfile.api "${API_IMAGE}"
|
|
build_with_retry Dockerfile.web "${WEB_IMAGE}" --build-arg "API_BASE=${PUBLIC_API}/"
|
|
|
|
echo "==> import images into k3s"
|
|
docker save "${API_IMAGE}" | k3s ctr images import -
|
|
docker save "${WEB_IMAGE}" | k3s ctr images import -
|
|
|
|
echo "==> apply manifests"
|
|
kubectl apply -f "${MANIFEST}"
|
|
|
|
echo "==> restart api + web"
|
|
kubectl -n "${NS}" rollout restart deploy/tafsirquran-api deploy/tafsirquran-web
|
|
kubectl -n "${NS}" rollout status deploy/tafsirquran-api --timeout=360s
|
|
kubectl -n "${NS}" rollout status deploy/tafsirquran-web --timeout=240s
|
|
|
|
kubectl -n "${NS}" get pods,svc,pvc -o wide
|
|
|
|
echo "==> smoke"
|
|
curl -fsS --max-time 30 "http://127.0.0.1:30821/" | head -c 200; echo
|
|
curl -fsS --max-time 30 -o /dev/null -w "api/tafsirs:%{http_code}\n" "http://127.0.0.1:30821/api/tafsirs"
|
|
curl -fsS --max-time 30 -o /dev/null -w "web:%{http_code}\n" "http://127.0.0.1:30820/"
|
|
|
|
echo "web → ${PUBLIC_WEB}/"
|
|
echo "api → ${PUBLIC_API}/"
|
|
echo "audio PVC: tafsirquran-audio (import via k8s/audio-import-job.yaml)"
|
|
echo "deploy ok"
|