refactor: Update Dockerfile and TypeScript configurations for improved build process

This commit is contained in:
2025-04-25 00:10:40 +08:00
parent 72a59bbcdd
commit a324815788
4 changed files with 36 additions and 28 deletions

View File

@@ -3,24 +3,22 @@ FROM node:23-alpine AS builder
WORKDIR /app
# Install pnpm and necessary build tools (if native modules are used)
# Install pnpm and necessary build tools
RUN apk add --no-cache python3 make g++ pnpm
# Copy package manifests
# First copy all config files
COPY tsconfig.json tsconfig.deploy.json ./
COPY package.json pnpm-lock.yaml ./
# Install ALL dependencies (including devDependencies needed for build)
# Now copy source code
COPY src/ ./src/
COPY deploy-commands.ts ./
# Install dependencies AFTER copying config files
RUN pnpm install --frozen-lockfile
# Copy the rest of the source code
COPY . .
# Compile TypeScript
RUN pnpm run build
# Prune devDependencies after build (optional but good practice)
RUN pnpm prune --prod
# Build the TypeScript code directly
RUN npx tsc -p tsconfig.json && npx tsc -p tsconfig.deploy.json
# ---- Production Stage ----
FROM node:23-alpine
@@ -29,17 +27,18 @@ WORKDIR /app
ENV NODE_ENV=production
# Copy necessary files from the builder stage
COPY --from=builder /app/node_modules ./node_modules
# Copy application files
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./package.json
# Copy other runtime necessities (adjust if needed)
# COPY .env.example ./
# COPY application.yml ./
# COPY plugins ./plugins
COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
COPY application.yml ./application.yml
COPY plugins ./plugins
# Expose port if needed (though likely not for a Discord bot)
# EXPOSE 3000
# Install production dependencies only
# Temporarily disable the prepare script by setting npm_config_ignore_scripts
RUN apk add --no-cache pnpm && \
npm_config_ignore_scripts=true pnpm install --prod --frozen-lockfile && \
apk del pnpm
# Run the compiled JavaScript application
CMD ["node", "dist/index.js"]