feat: update Dockerfile and .dockerignore for improved build process and dependency management

This commit is contained in:
yuanhau 2025-05-09 22:58:22 +08:00
parent 50846c91c2
commit 2e9845c268
2 changed files with 28 additions and 13 deletions

View file

@ -4,4 +4,9 @@ node_modules
.next .next
dist dist
.git .git
.env .env
.DS_Store
npm-debug.log
yarn-debug.log
yarn-error.log
.env.*

View file

@ -1,28 +1,38 @@
# Building process
FROM oven/bun:latest as builder FROM oven/bun:latest as builder
WORKDIR /app WORKDIR /app
# Copy dependency files
COPY package.json bun.lockb ./ # Copy package.json first
RUN bun install --frozen-lockfile COPY package.json ./
# Copy source files
# Copy lock files if they exist (support both bun and npm/yarn)
COPY bun.lockb* package-lock.json* yarn.lock* ./
# Install dependencies
RUN bun install --frozen-lockfile || bun install
# Copy remaining source files
COPY . . COPY . .
# Framework-specific build command
# Build the application
RUN bun run build RUN bun run build
# Production image # Production stage
FROM oven/bun:latest FROM oven/bun:latest
WORKDIR /app WORKDIR /app
# Copy built assets and dependencies # Copy built assets and dependencies
COPY --from=builder /app/.output /app/.output COPY --from=builder /app/.output /app/.output
COPY --from=builder /app/dist /app/dist COPY --from=builder /app/dist /app/dist
COPY --from=builder /app/build /app/build COPY --from=builder /app/build /app/build
COPY --from=builder /app/package.json /app/package.json COPY --from=builder /app/package.json ./
COPY --from=builder /app/bun.lockb /app/bun.lockb COPY --from=builder /app/bun.lockb* ./
# If you have customized your output directory, please add your custom one here, or just remove it. :) # If you have customized your output directory, please add your custom one here, or just remove it. :)
# Install production dependencies only
RUN bun install --production --frozen-lockfile # Install production dependencies
RUN bun install --production
EXPOSE 3000 EXPOSE 3000
# Map the prod command to start via editing your package.json like in the example.package.json
CMD ["bun", "run", "start"] CMD ["bun", "run", "start"]