71 lines
2.2 KiB
Bash
Executable File
71 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
IMAGE="${IMAGE:-localhost/wiki-print:latest}"
|
|
MANIFEST="$ROOT_DIR/podman/wiki-print.pod.yaml"
|
|
SECRET_NAME="wiki-print-config"
|
|
|
|
if [ -z "${WIKI_URL:-}" ]; then
|
|
echo "WIKI_URL is not set." >&2
|
|
echo "Export the Wiki.js URL before starting the pod, for example:" >&2
|
|
echo " export WIKI_URL='https://wiki.example.com'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${WIKI_API_KEY:-}" ]; then
|
|
echo "WIKI_API_KEY is not set." >&2
|
|
echo "Export the Wiki.js API key before starting the pod, for example:" >&2
|
|
echo " export WIKI_API_KEY='your-wiki-js-api-key'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! podman info >/dev/null 2>&1; then
|
|
echo "Podman is not ready. Starting the Podman machine…"
|
|
podman machine start
|
|
fi
|
|
|
|
if ! podman image exists "$IMAGE"; then
|
|
"$ROOT_DIR/scripts/build.sh"
|
|
fi
|
|
|
|
# Recreate the pod before replacing the secret: a running container still
|
|
# references the old secret, and Podman refuses to remove a secret in use.
|
|
if podman pod exists wiki-print >/dev/null 2>&1; then
|
|
podman play kube --down "$MANIFEST" >/dev/null 2>&1 || podman pod rm -f wiki-print >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
if podman secret exists "$SECRET_NAME" >/dev/null 2>&1; then
|
|
podman secret rm "$SECRET_NAME" >/dev/null
|
|
fi
|
|
# Remove the secret used by older versions of these scripts.
|
|
if podman secret exists wiki-print-api-key >/dev/null 2>&1; then
|
|
podman secret rm wiki-print-api-key >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
# podman play kube expects the secret content to be a JSON map of raw values
|
|
# (base64-encoded) or a Kubernetes Secret object.
|
|
printf '{"WIKI_URL":"%s","WIKI_API_KEY":"%s"}' \
|
|
"$(printf %s "$WIKI_URL" | base64 | tr -d '\n')" \
|
|
"$(printf %s "$WIKI_API_KEY" | base64 | tr -d '\n')" \
|
|
| podman secret create "$SECRET_NAME" - >/dev/null
|
|
|
|
echo "Creating pod wiki-print…"
|
|
podman play kube --replace "$MANIFEST"
|
|
|
|
echo -n "Waiting for the web UI"
|
|
for _ in $(seq 1 60); do
|
|
if curl -fsS http://127.0.0.1:8080/healthz >/dev/null 2>&1; then
|
|
echo
|
|
echo "wiki-print is ready at http://localhost:8080"
|
|
exit 0
|
|
fi
|
|
echo -n "."
|
|
sleep 1
|
|
done
|
|
|
|
echo
|
|
echo "The pod was created, but the health check did not become ready in time."
|
|
echo "Inspect it with: ./scripts/logs.sh"
|
|
exit 1
|