Update Docker runtime to pull latest code on startup.

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>
This commit is contained in:
renjue
2026-05-09 16:19:18 +08:00
parent 82581d2949
commit 7e3f4d792f
3 changed files with 34 additions and 17 deletions

View File

@@ -1,14 +1,36 @@
#!/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}"
cd /app/backend
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 /app/frontend
cd "${WORKTREE_DIR}/frontend"
npm run preview -- --host 0.0.0.0 --port "${FRONTEND_PORT}" &
FRONTEND_PID=$!