feat: bootstrap icin wscraper otomatik clone ve guncelleme akisini ekle

This commit is contained in:
2026-03-13 08:14:10 +03:00
parent e29b68c5d7
commit fca46a009c
3 changed files with 272 additions and 21 deletions

View File

@@ -2,6 +2,7 @@
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
WSCRAPER_DIR="$ROOT_DIR/bin/wscraper"
RUNTIME_DIR="$ROOT_DIR/.runtime/wscraper-service"
VENV_DIR="$RUNTIME_DIR/.venv"
PID_FILE="$RUNTIME_DIR/wscraper-service.pid"
@@ -10,12 +11,14 @@ MARKER_FILE="$RUNTIME_DIR/.setup-complete"
MODE=""
SKIP_INSTALL="false"
RESTART_WSCRAPER="false"
SKIP_FETCH="false"
UPDATE_WSCRAPER="false"
usage() {
cat <<'EOF'
Usage:
./scripts/bootstrap.sh --dev-mode [--skip-wscraper-install] [--restart-wscraper]
./scripts/bootstrap.sh --prod-mode [--skip-wscraper-install] [--restart-wscraper]
./scripts/bootstrap.sh --dev-mode [--skip-wscraper-fetch] [--update-wscraper] [--skip-wscraper-install] [--restart-wscraper]
./scripts/bootstrap.sh --prod-mode [--skip-wscraper-fetch] [--update-wscraper] [--skip-wscraper-install] [--restart-wscraper]
EOF
}
@@ -30,6 +33,12 @@ while [[ $# -gt 0 ]]; do
--skip-wscraper-install)
SKIP_INSTALL="true"
;;
--skip-wscraper-fetch)
SKIP_FETCH="true"
;;
--update-wscraper)
UPDATE_WSCRAPER="true"
;;
--restart-wscraper|--restart)
RESTART_WSCRAPER="true"
;;
@@ -65,6 +74,8 @@ WSCRAPER_SERVICE_HOST="${WSCRAPER_SERVICE_HOST:-0.0.0.0}"
WSCRAPER_SERVICE_PORT="${WSCRAPER_SERVICE_PORT:-8787}"
WSCRAPER_SERVICE_TOKEN="${WSCRAPER_SERVICE_TOKEN:-}"
WSCRAPER_SERVICE_PYTHON_BIN="${WSCRAPER_SERVICE_PYTHON_BIN:-}"
WSCRAPER_GIT_URL="${WSCRAPER_GIT_URL:-https://github.com/wisecolt/Bookmark-Tracker.git}"
WSCRAPER_GIT_REF="${WSCRAPER_GIT_REF:-main}"
detect_python_bin() {
if [[ -n "$WSCRAPER_SERVICE_PYTHON_BIN" ]] && command -v "$WSCRAPER_SERVICE_PYTHON_BIN" >/dev/null 2>&1; then
@@ -89,6 +100,55 @@ detect_python_bin() {
PYTHON_BIN="$(detect_python_bin)"
ensure_wscraper_repo() {
if [[ "$SKIP_FETCH" == "true" ]]; then
echo "wscraper repo kontrolu atlandi."
return
fi
if [[ ! -d "$WSCRAPER_DIR" ]]; then
echo "wscraper repo klonlaniyor..."
git clone --branch "$WSCRAPER_GIT_REF" "$WSCRAPER_GIT_URL" "$WSCRAPER_DIR"
return
fi
if [[ ! -d "$WSCRAPER_DIR/.git" ]]; then
echo "bin/wscraper dizini var ama git reposu degil. Lutfen duzeltin veya dizini temizleyin." >&2
exit 1
fi
if [[ "$UPDATE_WSCRAPER" != "true" ]]; then
echo "wscraper repo mevcut, yeniden klonlanmayacak."
return
fi
local status_output
status_output="$(git -C "$WSCRAPER_DIR" status --porcelain)"
if [[ -n "$status_output" ]]; then
echo "wscraper repo kirli durumda; --update-wscraper uygulanmadi." >&2
echo "Lutfen bin/wscraper icindeki degisiklikleri commit edin veya temizleyin." >&2
exit 1
fi
echo "wscraper repo guncelleniyor..."
git -C "$WSCRAPER_DIR" pull --ff-only
}
validate_wscraper_repo() {
local expected_paths=(
"$WSCRAPER_DIR/pyproject.toml"
"$WSCRAPER_DIR/setup.py"
"$WSCRAPER_DIR/src/wscraper/cli.py"
)
local path
for path in "${expected_paths[@]}"; do
if [[ ! -e "$path" ]]; then
echo "wscraper repo eksik veya bozuk gorunuyor: $path bulunamadi." >&2
exit 1
fi
done
}
service_running() {
if [[ ! -f "$PID_FILE" ]]; then
return 1
@@ -160,7 +220,7 @@ start_wscraper_service() {
WSCRAPER_SERVICE_HOST="$WSCRAPER_SERVICE_HOST" \
WSCRAPER_SERVICE_PORT="$WSCRAPER_SERVICE_PORT" \
WSCRAPER_SERVICE_TOKEN="$WSCRAPER_SERVICE_TOKEN" \
PYTHONPATH="$ROOT_DIR/bin/wscraper/src" \
PYTHONPATH="$WSCRAPER_DIR/src" \
"$VENV_DIR/bin/python3" \
"$ROOT_DIR/bin/wscraper-service/server.py" \
>>"$LOG_FILE" 2>&1 &
@@ -192,6 +252,8 @@ run_docker() {
docker compose -f "$ROOT_DIR/docker-compose.yml" up --build -d
}
ensure_wscraper_repo
validate_wscraper_repo
install_wscraper_service
start_wscraper_service
run_docker