small www

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-06 23:20:37 +02:00
1 parent 3d6c49df65
commit fda15b194b
7 files changed
+336 -72

No files matched your search

+89 -12
View File
@@ -8,11 +8,17 @@ ENV_FILE="$ROOT/.env"
GPG_DIR="$ROOT/gpg"
DATA_DIR="$ROOT/data"
SERVICE="rust-package-builder"
HTTP_SERVICE="repository-http"
DEFAULT_HTTP_PORT=18765
log() {
printf '[start] %s\n' "$*"
}
warn() {
printf '[start] WARN: %s\n' "$*" >&2
}
die() {
printf '[start] ERROR: %s\n' "$*" >&2
exit 1
@@ -33,6 +39,21 @@ ENV
chmod 0600 "$ENV_FILE" 2>/dev/null || true
}
update_env_var() {
local key=$1
local value=$2
local tmp="$ENV_FILE.tmp.$$"
awk -v key="$key" -v value="$value" '
BEGIN { found=0 }
index($0, key "=") == 1 { print key "=" value; found=1; next }
{ print }
END { if (!found) print key "=" value }
' "$ENV_FILE" > "$tmp"
mv "$tmp" "$ENV_FILE"
chmod 0600 "$ENV_FILE" 2>/dev/null || true
}
load_env_file() {
# .env is intentionally limited to simple KEY=value entries used by Compose.
# shellcheck disable=SC1090
@@ -41,7 +62,55 @@ load_env_file() {
set +a
}
normalize_http_settings() {
local url=${REPOSITORY_URL%/}
local rest hostpart explicit_port=""
HTTP_PORT=${HTTP_PORT:-}
case "$url" in
http://*)
rest=${url#http://}
[[ "$rest" != */* ]] || die "REPOSITORY_URL dla wbudowanego HTTP nie moze zawierac sciezki: $REPOSITORY_URL"
hostpart=$rest
if [[ "$hostpart" =~ ^\[[^]]+\]:([0-9]+)$ ]]; then
explicit_port=${BASH_REMATCH[1]}
elif [[ "$hostpart" =~ ^[^:]+:([0-9]+)$ ]]; then
explicit_port=${BASH_REMATCH[1]}
fi
if [[ -n "$explicit_port" ]]; then
HTTP_PORT=$explicit_port
else
HTTP_PORT=${HTTP_PORT:-$DEFAULT_HTTP_PORT}
url="${url}:${HTTP_PORT}"
REPOSITORY_URL=$url
export REPOSITORY_URL
update_env_var REPOSITORY_URL "$REPOSITORY_URL"
log "REPOSITORY_URL bez portu - ustawiono $REPOSITORY_URL"
fi
;;
https://*)
# HTTPS is supported as a public URL only when an external TLS proxy points
# to the local micro HTTP service. The embedded service itself is HTTP only.
HTTP_PORT=${HTTP_PORT:-$DEFAULT_HTTP_PORT}
warn "REPOSITORY_URL uzywa HTTPS. Wbudowany serwer nasluchuje po zwyklym HTTP na porcie $HTTP_PORT; HTTPS wymaga zewnetrznego reverse proxy/TLS."
;;
*)
die "REPOSITORY_URL musi zaczynac sie od http:// albo https://"
;;
esac
[[ "$HTTP_PORT" =~ ^[0-9]+$ ]] || die "HTTP_PORT musi byc liczba"
(( HTTP_PORT >= 1024 && HTTP_PORT <= 65535 )) || die "HTTP_PORT musi byc z zakresu 1024-65535"
export HTTP_PORT
update_env_var HTTP_PORT "$HTTP_PORT"
}
require_cmd docker
require_cmd awk
if ! docker info >/dev/null 2>&1; then
die "Docker daemon nie jest dostepny dla aktualnego uzytkownika"
fi
@@ -66,10 +135,8 @@ case "$SOURCE_REPO" in
http://*|https://*|ssh://*|git@*|file://*) ;;
*) die "SOURCE_REPO ma nieobslugiwany format: $SOURCE_REPO" ;;
esac
case "$REPOSITORY_URL" in
http://*|https://*) ;;
*) die "REPOSITORY_URL musi zaczynac sie od http:// albo https://" ;;
esac
normalize_http_settings
mkdir -p "$DATA_DIR/repository" "$DATA_DIR/state" "$DATA_DIR/cargo" "$DATA_DIR/work" "$GPG_DIR"
chmod 0700 "$GPG_DIR" 2>/dev/null || true
@@ -80,8 +147,11 @@ log "budowanie obrazu buildera"
if [[ ! -s "$GPG_DIR/private-key.asc" ]]; then
log "brak klucza GPG - generowanie stalego klucza podpisujacego"
IMAGE_REF=$("${COMPOSE[@]}" --env-file "$ENV_FILE" config | awk '$1 == "image:" {print $2; exit}')
[[ -n "$IMAGE_REF" ]] || die "nie mozna ustalic nazwy zbudowanego obrazu"
IMAGE_REF=$("${COMPOSE[@]}" --env-file "$ENV_FILE" config | awk '''
$1 == "rust-package-builder:" { in_builder=1; next }
in_builder && $1 == "image:" { print $2; exit }
''')
[[ -n "$IMAGE_REF" ]] || die "nie mozna ustalic nazwy zbudowanego obrazu buildera"
docker image inspect "$IMAGE_REF" >/dev/null 2>&1 || die "zbudowany obraz nie istnieje: $IMAGE_REF"
uid=$(id -u)
@@ -127,8 +197,8 @@ else
log "uzywanie istniejacego klucza GPG"
fi
log "uruchamianie buildera przez Docker Compose"
"${COMPOSE[@]}" --env-file "$ENV_FILE" up -d "$SERVICE"
log "uruchamianie buildera i mikro HTTP przez Docker Compose"
"${COMPOSE[@]}" --env-file "$ENV_FILE" up -d "$SERVICE" "$HTTP_SERVICE"
fingerprint=""
if [[ -r "$GPG_DIR/fingerprint" ]]; then
@@ -137,13 +207,20 @@ fi
log "gotowe"
printf '\n'
printf 'SOURCE_REPO: %s\n' "$SOURCE_REPO"
printf 'REPOSITORY_URL: %s\n' "$REPOSITORY_URL"
[[ -n "$fingerprint" ]] && printf 'GPG fingerprint: %s\n' "$fingerprint"
printf 'SOURCE_REPO: %s\n' "$SOURCE_REPO"
printf 'REPOSITORY_URL: %s\n' "$REPOSITORY_URL"
printf 'HTTP port: %s\n' "$HTTP_PORT"
[[ -n "$fingerprint" ]] && printf 'GPG fingerprint: %s\n' "$fingerprint"
printf 'Publiczny katalog: %s\n' "$DATA_DIR/repository"
printf '\n'
printf 'Podglad logow:\n '
printf 'Repo/strona: %s/\n' "${REPOSITORY_URL%/}"
printf 'Healthcheck: http://127.0.0.1:%s/healthz\n' "$HTTP_PORT"
printf '\n'
printf 'Podglad logow buildera:\n '
printf '%q ' "${COMPOSE[@]}"
printf 'logs -f %q\n' "$SERVICE"
printf 'Podglad logow HTTP:\n '
printf '%q ' "${COMPOSE[@]}"
printf 'logs -f %q\n' "$HTTP_SERVICE"
printf '\n'
printf 'Builder natychmiast sprawdzi branch master (lub SOURCE_BRANCH, jezeli ustawiono go opcjonalnie) i po udanym buildzie opublikuje repozytorium.\n'