diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dc9d8c5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +src-tauri/target +dist +.git +*.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2193136 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# 第一阶段:构建前端 +FROM node:22-alpine AS builder +WORKDIR /app +RUN corepack enable +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile --ignore-scripts && \ + pnpm rebuild esbuild +COPY . . +RUN pnpm build + +# 第二阶段:Nginx 服务 +FROM nginx:alpine +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..4fc057c --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + + gzip on; + gzip_types text/css application/javascript application/json image/svg+xml; + gzip_vary on; + + # SPA fallback + location / { + try_files $uri /index.html; + } + + # 可选的 API 代理,取消注释并改 backend 地址即可 + # location /api/ { + # proxy_pass http://backend:8080; + # proxy_set_header Host $host; + # proxy_set_header X-Real-IP $remote_addr; + # } +} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml deleted file mode 100644 index 220bd0b..0000000 --- a/pnpm-workspace.yaml +++ /dev/null @@ -1,3 +0,0 @@ -allowBuilds: - esbuild: true - msw: true diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh new file mode 100755 index 0000000..dc665ba --- /dev/null +++ b/scripts/docker-build.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +cd "$(dirname "$0")/.." + +REGISTRY="${GITEA_REGISTRY:-git.msksbr.com}" +USERNAME="${GITEA_USERNAME:-msksbr}" +IMAGE="$REGISTRY/$USERNAME/bookmgr-client" +VERSION=$(node -e "console.log(require('./package.json').version)") + +echo ">>> 版本: $VERSION" +echo ">>> 镜像: $IMAGE" + +echo ">>> 构建镜像..." +docker build \ + --network=host \ + -t "$IMAGE:$VERSION" \ + -t "$IMAGE:latest" \ + . + +echo ">>> 推送镜像..." +docker push "$IMAGE:$VERSION" +docker push "$IMAGE:latest" + +echo "" +echo "完成!" +echo " 镜像: $IMAGE:$VERSION" +echo " 镜像: $IMAGE:latest" +echo "" +echo "部署:" +echo " docker run -d -p 80:80 $IMAGE:$VERSION"