diff --git a/.gitignore b/.gitignore index d597a22..4144e01 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ pnpm-debug.log* # macOS-specific files .DS_Store -*storybook.log \ No newline at end of file +*storybook.log +data diff --git a/Dockerfile.dev-server b/Dockerfile.dev-server new file mode 100644 index 0000000..35a23d2 --- /dev/null +++ b/Dockerfile.dev-server @@ -0,0 +1,56 @@ +# 开发模式 Dockerfile - 完整开发环境 +FROM node:18-alpine + +# 安装必要的系统依赖 +RUN apk add --no-cache \ + curl \ + git \ + bash + +# 设置工作目录 +WORKDIR /app + +# 设置环境变量 +ENV NODE_ENV=production +ENV PORT=8080 +ENV HOST=0.0.0.0 +ENV PATH="/app/node_modules/.bin:${PATH}" + +# 复制package文件 +COPY package*.json ./ + +# 安装所有依赖(包括devDependencies),跳过 prepare 脚本 +RUN npm ci --ignore-scripts && \ + npm cache clean --force && \ + npm install husky --save-dev + +# 复制所有源代码 +COPY . . + +# 创建数据目录 +RUN mkdir -p /app/data + +# 暴露端口 +EXPOSE 8080 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD curl -f http://localhost:8080/ || exit 1 + +# 启动开发服务器(类似生产模式,稳定运行) +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "8080"] + +# 定义构建参数 +ARG VERSION=latest +ARG BUILD_DATE +ARG VCS_REF + +# 添加标签信息 +LABEL maintainer="walllee" \ + org.opencontainers.image.title="Moodist Development" \ + org.opencontainers.image.description="Ambient sounds for focus and calm - 开发环境(完整功能)" \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.revision="${VCS_REF}" \ + org.opencontainers.image.source="https://github.com/wheesys/moodist" \ + org.opencontainers.image.licenses="MIT" \ No newline at end of file diff --git a/Dockerfile.prod-like b/Dockerfile.prod-like new file mode 100644 index 0000000..27d2dee --- /dev/null +++ b/Dockerfile.prod-like @@ -0,0 +1,58 @@ +# 类生产模式 Dockerfile - 开发服务器但无热重载 +FROM node:18-alpine + +# 安装必要的系统依赖 +RUN apk add --no-cache \ + curl \ + git \ + bash + +# 设置工作目录 +WORKDIR /app + +# 设置环境变量 +ENV NODE_ENV=development +ENV PORT=8080 +ENV HOST=0.0.0.0 +ENV PATH="/app/node_modules/.bin:${PATH}" + +# 复制package文件 +COPY package*.json ./ + +# 安装所有依赖 +RUN npm ci && \ + npm cache clean --force + +# 在容器内构建应用 +COPY . . + +# 创建数据目录 +RUN mkdir -p /app/data + +# 构建应用 +RUN npm run build + +# 暴露端口 +EXPOSE 8080 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD curl -f http://localhost:8080/ || exit 1 + +# 启动应用(类似生产模式,无热重载) +CMD ["node", "./dist/server/entry.mjs"] + +# 定义构建参数 +ARG VERSION=latest +ARG BUILD_DATE +ARG VCS_REF + +# 添加标签信息 +LABEL maintainer="walllee" \ + org.opencontainers.image.title="Moodist Production-like" \ + org.opencontainers.image.description="Ambient sounds for focus and calm - 类生产模式(无热重载)" \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.revision="${VCS_REF}" \ + org.opencontainers.image.source="https://github.com/wheesys/moodist" \ + org.opencontainers.image.licenses="MIT" \ No newline at end of file diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 0000000..3c0ea66 --- /dev/null +++ b/Dockerfile.server @@ -0,0 +1,58 @@ +# 使用现有的本地构建成果 - Node.js 服务器版本 +FROM node:20-alpine + +# 安装必要的系统依赖 +RUN apk add --no-cache curl + +# 创建应用用户 +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 + +# 设置工作目录 +WORKDIR /app + +# 设置环境变量 +ENV NODE_ENV=production +ENV PORT=8080 + +# 复制package文件 +COPY package*.json ./ + +# 安装所有依赖(运行时需要adapter) +RUN npm ci --ignore-scripts && \ + npm cache clean --force + +# 复制本地构建的完整产物 +COPY --chown=nodejs:nodejs dist/ ./dist + +# 创建数据目录 +RUN mkdir -p /app/data && \ + chown -R nodejs:nodejs /app + +# 切换到非root用户 +USER nodejs + +# 暴露端口 +EXPOSE 8080 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ + CMD curl -f http://localhost:8080/ || exit 1 + +# 启动应用 +CMD ["node", "./dist/server/entry.mjs"] + +# 定义构建参数 +ARG VERSION=latest +ARG BUILD_DATE +ARG VCS_REF + +# 添加标签信息 +LABEL maintainer="walllee" \ + org.opencontainers.image.title="Moodist" \ + org.opencontainers.image.description="Ambient sounds for focus and calm - 多语言环境音应用 (Full Stack)" \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.revision="${VCS_REF}" \ + org.opencontainers.image.source="https://github.com/wheesys/moodist" \ + org.opencontainers.image.licenses="MIT" \ No newline at end of file diff --git a/astro.config.mjs b/astro.config.mjs index 2d8e50a..9e97f61 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -5,7 +5,10 @@ import node from '@astrojs/node'; import AstroPWA from '@vite-pwa/astro'; export default defineConfig({ - output: 'static', + output: 'server', + adapter: node({ + mode: 'standalone' + }), integrations: [ react(), AstroPWA({ diff --git a/docker-compose.yml b/docker-compose.yml index 062523a..3b4bc67 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,27 @@ -version: '3.9' services: moodist: - image: walllee/moodist:latest + image: walllee/moodist:3.0.0-prod-like + build: + context: . + dockerfile: Dockerfile.dev-server logging: options: max-size: 1g - restart: always + restart: unless-stopped ports: - '8080:8080' volumes: + # 挂载源代码用于热重载(保持用户权限) + - .:/app:cached + # 使用独立的 node_modules 避免权限冲突 + - node_modules_volume:/app/node_modules # 挂载 SQLite 数据库文件和 WAL 文件 - ./data:/app/data:rw environment: - - NODE_ENV=production + - NODE_ENV=development + - PORT=8080 + stdin_open: true + tty: true + +volumes: + node_modules_volume: