build: 使用dockerfile构建docker镜像 #58

Manually merged
remilia merged 4 commits from build/dockerfile into master 2025-11-05 14:07:56 +08:00
2 changed files with 99 additions and 0 deletions
Showing only changes of commit daa22f8ff9 - Show all commits

58
.dockerignore Normal file
View File

@ -0,0 +1,58 @@
# ------------------------
# Node / Package Manager
# ------------------------
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
.pnpm-store
# Nuxt build outputs
.output
.nuxt
dist
.cache
.unimport
.h3
.nitro
**/.nitro
# Dev tools / OS files
.DS_Store
Thumbs.db
# Logs
*.log
logs
!.gitkeep
# Local env files (runtime env should be provided by Docker/K8s)
.env
.env.*
!.env.example
# Git
.git
.gitignore
.gitattributes
# Editor / IDE
.vscode
.idea
*.swp
*.swo
# Tests
coverage
*.lcov
# Docker
Dockerfile*
docker-compose.yml
# CI / Local build artifacts
*.tgz
*.zip
*.tar
*.mdx

41
Dockerfile Normal file
View File

@ -0,0 +1,41 @@
-------- Base image --------
FROM node:22-alpine AS base
ENV NODE_ENV=production
WORKDIR /app
# -------- Dependencies layer -------
FROM base AS deps
WORKDIR /app
RUN corepack enable
# Copy package.json and lockfile
COPY package.json pnpm-lock.yaml .npmrc ./
# Install dependencies with cache
RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install
# -------- Build layer -------
FROM deps AS build
# Copy entire project
COPY . ./
ENV NITRO_PRESET=node-server
# Build the project
RUN pnpm run build
# ------- Runtime layer -------
FROM base AS runtime
WORKDIR /app
# COPY .output folder
COPY --from=build /app/.output ./
ENV PORT=3000
ENV NITRO_PRESET=node-server
ENV HOST=0.0.0.0
EXPOSE 3000
CMD ["node", "/app/server/index.mjs"]