7f06856f45
build-and-deploy / deploy (push) Successful in 10m50s
Blazor UI + ASP.NET API + Postgres; push to main builds images and rolls out namespace tafsirquran.
81 lines
2.7 KiB
Bash
Executable File
81 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build images, import into k3s, apply manifests, roll out.
|
|
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:-http://185.252.31.44:30820}"
|
|
PUBLIC_API="${PUBLIC_API:-http://185.252.31.44:30821}"
|
|
|
|
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"
|
|
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 "==> build api + web"
|
|
build_with_retry Dockerfile.api "${API_IMAGE}"
|
|
build_with_retry Dockerfile.web "${WEB_IMAGE}"
|
|
|
|
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}"
|
|
|
|
# Keep public API URL for the Blazor host in sync with NodePort
|
|
kubectl -n "${NS}" create configmap tafsirquran-web-env \
|
|
--from-literal=ASPNETCORE_URLS='http://+:8080' \
|
|
--from-literal=ApiBaseAddress="${PUBLIC_API}/" \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
echo "==> wait postgres"
|
|
kubectl -n "${NS}" rollout status deploy/tafsirquran-postgres --timeout=180s
|
|
|
|
echo "==> restart api + web"
|
|
kubectl -n "${NS}" rollout restart deploy/tafsirquran-api deploy/tafsirquran-web
|
|
kubectl -n "${NS}" rollout status deploy/tafsirquran-api --timeout=300s
|
|
kubectl -n "${NS}" rollout status deploy/tafsirquran-web --timeout=240s
|
|
|
|
kubectl -n "${NS}" get pods,svc -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 "deploy ok"
|