72
scripts/test.sh
Executable file
72
scripts/test.sh
Executable file
@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "${SCRIPT_DIR}/lib.sh"
|
||||
|
||||
WITH_TLS=false
|
||||
ALLOW_PENDING_EXTERNAL=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--with-tls) WITH_TLS=true ;;
|
||||
--allow-pending-external) ALLOW_PENDING_EXTERNAL=true ;;
|
||||
*) die "Unknown argument: $arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
load_env
|
||||
require_cmd curl
|
||||
|
||||
log "Checking docker compose status"
|
||||
if [[ "${WITH_TLS}" == "true" ]]; then
|
||||
compose --profile tls ps
|
||||
else
|
||||
compose ps
|
||||
fi
|
||||
|
||||
log "Checking local HTTP health"
|
||||
curl -fsS "http://localhost:${GITEA_HTTP_PORT}/api/healthz" && printf '\n'
|
||||
|
||||
log "Checking local web root"
|
||||
curl -I -sS "http://localhost:${GITEA_HTTP_PORT}" | grep -E 'HTTP/[0-9.]+ 200|HTTP/[0-9.]+ 302'
|
||||
|
||||
if command -v getent >/dev/null 2>&1; then
|
||||
log "Checking DNS resolution for ${GITEA_DOMAIN}"
|
||||
getent hosts "${GITEA_DOMAIN}" || log "DNS resolution not yet set for ${GITEA_DOMAIN}"
|
||||
fi
|
||||
|
||||
if command -v nc >/dev/null 2>&1; then
|
||||
log "Checking SSH TCP port on localhost"
|
||||
nc -z localhost "${GITEA_SSH_PORT}"
|
||||
fi
|
||||
|
||||
if [[ "${WITH_TLS}" == "true" ]]; then
|
||||
log "Checking Caddy container status"
|
||||
compose --profile tls ps caddy | grep -E 'gitea-caddy|caddy'
|
||||
|
||||
if command -v nc >/dev/null 2>&1; then
|
||||
log "Checking reverse proxy listener ports"
|
||||
nc -z localhost 80
|
||||
nc -z localhost 443
|
||||
fi
|
||||
|
||||
if getent hosts "${GITEA_DOMAIN}" >/dev/null 2>&1; then
|
||||
log "Checking HTTPS response by domain"
|
||||
if [[ "${ALLOW_PENDING_EXTERNAL}" == "true" ]]; then
|
||||
if ! curl -k -I -sS "https://${GITEA_DOMAIN}" | grep -E 'HTTP/[0-9.]+ 200|HTTP/[0-9.]+ 302|HTTP/[0-9.]+ 308'; then
|
||||
log "HTTPS domain check did not pass yet (pending DNS/routing/certificate propagation)"
|
||||
fi
|
||||
else
|
||||
curl -I -sS "https://${GITEA_DOMAIN}" | grep -E 'HTTP/[0-9.]+ 200|HTTP/[0-9.]+ 302|HTTP/[0-9.]+ 308'
|
||||
fi
|
||||
else
|
||||
if [[ "${ALLOW_PENDING_EXTERNAL}" == "true" ]]; then
|
||||
log "Skipping strict HTTPS domain check until DNS is configured"
|
||||
else
|
||||
die "DNS not configured for ${GITEA_DOMAIN}; rerun with --allow-pending-external if still propagating"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
log "All tests passed"
|
||||
Reference in New Issue
Block a user