Files
media_crawler/docker/start.sh
renjue 78a4932526 Improve Docker startup npm install speed and observability.
Use configurable npm mirror with npm ci --no-audit --no-fund and add startup logs plus README docs for NPM_REGISTRY.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-09 17:00:56 +08:00

52 lines
1.6 KiB
Bash

#!/usr/bin/env sh
set -eu
GIT_REPO_URL="${GIT_REPO_URL:-https://git.rc707blog.top/rose_cat707/media_crawler.git}"
GIT_BRANCH="${GIT_BRANCH:-main}"
WORKTREE_DIR="${WORKTREE_DIR:-/app/runtime}"
BACKEND_PORT="${FLASK_RUN_PORT:-14620}"
FRONTEND_PORT="${FRONTEND_PORT:-14621}"
NPM_REGISTRY="${NPM_REGISTRY:-https://registry.npmmirror.com}"
echo "[start] syncing source from ${GIT_REPO_URL} (${GIT_BRANCH})"
if [ ! -d "${WORKTREE_DIR}/.git" ]; then
rm -rf "${WORKTREE_DIR}"
git clone --branch "${GIT_BRANCH}" --single-branch "${GIT_REPO_URL}" "${WORKTREE_DIR}"
else
git -C "${WORKTREE_DIR}" fetch origin "${GIT_BRANCH}"
git -C "${WORKTREE_DIR}" checkout "${GIT_BRANCH}"
git -C "${WORKTREE_DIR}" reset --hard "origin/${GIT_BRANCH}"
fi
echo "[start] installing backend dependencies"
VENV_DIR="${WORKTREE_DIR}/.venv"
if [ ! -x "${VENV_DIR}/bin/python" ]; then
python3 -m venv "${VENV_DIR}"
fi
"${VENV_DIR}/bin/pip" install --no-cache-dir -r "${WORKTREE_DIR}/backend/requirements.txt"
echo "[start] installing frontend dependencies and building"
cd "${WORKTREE_DIR}/frontend"
echo "[start] npm registry: ${NPM_REGISTRY}"
npm config set registry "${NPM_REGISTRY}"
npm ci --no-audit --no-fund
echo "[start] building frontend assets"
npm run build
echo "[start] launching backend:${BACKEND_PORT} and frontend:${FRONTEND_PORT}"
cd "${WORKTREE_DIR}/backend"
"${VENV_DIR}/bin/python" app.py &
BACKEND_PID=$!
cd "${WORKTREE_DIR}/frontend"
npm run preview -- --host 0.0.0.0 --port "${FRONTEND_PORT}" &
FRONTEND_PID=$!
cleanup() {
kill "${BACKEND_PID}" "${FRONTEND_PID}" 2>/dev/null || true
}
trap cleanup INT TERM EXIT
wait "${BACKEND_PID}" "${FRONTEND_PID}"