Install git in image and change start script to clone/pull target branch, reinstall dependencies, rebuild frontend, then launch backend and frontend services. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.3 KiB
Bash
44 lines
1.3 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}"
|
|
|
|
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"
|
|
python3 -m pip install --no-cache-dir -r "${WORKTREE_DIR}/backend/requirements.txt"
|
|
|
|
echo "[start] installing frontend dependencies and building"
|
|
cd "${WORKTREE_DIR}/frontend"
|
|
npm install
|
|
npm run build
|
|
|
|
echo "[start] launching backend:${BACKEND_PORT} and frontend:${FRONTEND_PORT}"
|
|
cd "${WORKTREE_DIR}/backend"
|
|
python3 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}"
|