diff --git a/README.md b/README.md index 9255ef1..0aeaf83 100644 --- a/README.md +++ b/README.md @@ -229,25 +229,26 @@ NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1 **更新部署:** +本地一键增量部署(推荐): + +```bash +python scripts/deploy_update.py +``` + +脚本会对比上次成功部署的 commit:仅前端改动只重建 `frontend`,仅后端改动只重建 `backend`,并启用 BuildKit npm/pip 缓存;健康检查改为短轮询。 + +服务器手动全量: + ```bash -# SSH 登录服务器后(当前开发分支为 dev1) cd /opt/nomadweb git fetch origin && git checkout -B dev1 origin/dev1 -export DOMAIN=nomadweb.nomadro.com +export DOMAIN=nomadweb.nomadro.com DOCKER_BUILDKIT=1 export NEXT_PUBLIC_API_URL=https://nomadweb.nomadro.com/api/v1 export NEXT_PUBLIC_SITE_URL=https://nomadweb.nomadro.com export CORS_ORIGINS=https://nomadweb.nomadro.com docker compose -f docker-compose.prod.yml up -d --build ``` -或使用 Docker Compose 生产配置: - -```bash -docker compose -f docker-compose.prod.yml up -d --build -cp deploy/caddy/nomadweb.caddy /etc/caddy/sites/nomadweb.caddy -systemctl reload caddy -``` - ### 本地 Docker Compose ```bash diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..ca96bbd --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,14 @@ +__pycache__ +*.py[cod] +*.egg-info +.venv +venv +.env* +!.env.example +.git +.gitignore +*.md +.pytest_cache +.mypy_cache +.ruff_cache +tests diff --git a/backend/Dockerfile b/backend/Dockerfile index 0aa3ffe..31ed1b0 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,7 +1,10 @@ +# syntax=docker/dockerfile:1 + FROM python:3.12-slim WORKDIR /app COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r requirements.txt COPY . . EXPOSE 8000 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 153693f..429acc2 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -29,6 +29,7 @@ services: frontend: build: context: ./frontend + dockerfile: Dockerfile args: NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-https://nomadweb.nomadro.com/api/v1} NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:-https://nomadweb.nomadro.com} diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..53c1d2d --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,15 @@ +node_modules +.next +.git +.gitignore +*.md +.env* +!.env.example +Dockerfile* +docker-compose* +coverage +.turbo +.vercel +npm-debug.log* +playwright-report +test-results diff --git a/frontend/Dockerfile b/frontend/Dockerfile index c47a9ed..09809f6 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,24 +1,28 @@ +# syntax=docker/dockerfile:1 + FROM node:20-alpine AS base +WORKDIR /app +ENV NEXT_TELEMETRY_DISABLED=1 FROM base AS deps -WORKDIR /app COPY package.json package-lock.json ./ -RUN npm ci --legacy-peer-deps || npm install --legacy-peer-deps +RUN --mount=type=cache,target=/root/.npm \ + npm ci --legacy-peer-deps --prefer-offline FROM base AS builder -WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . ARG NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1 ARG NEXT_PUBLIC_SITE_URL=http://localhost:3000 -ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL -ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL +ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL \ + NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL \ + NODE_ENV=production RUN npm run build FROM base AS runner -WORKDIR /app ENV NODE_ENV=production -RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs +RUN addgroup --system --gid 1001 nodejs \ + && adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static