build(docker): add Docker build and deployment infrastructure
- Add multi-stage Dockerfile with pnpm install and Nginx serving - Add nginx.conf with gzip and SPA fallback - Add docker-build.sh script for building and pushing images - Add .dockerignore for build context optimization - Remove unused pnpm-workspace.yaml
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
src-tauri/target
|
||||
dist
|
||||
.git
|
||||
*.md
|
||||
+15
@@ -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
|
||||
+21
@@ -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;
|
||||
# }
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
allowBuilds:
|
||||
esbuild: true
|
||||
msw: true
|
||||
Executable
+31
@@ -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"
|
||||
Reference in New Issue
Block a user