refactor: Update Dockerfile and TypeScript configurations for improved build process
This commit is contained in:
parent
72a59bbcdd
commit
a324815788
39
Dockerfile
39
Dockerfile
@ -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"]
|
||||
|
||||
@ -5,12 +5,14 @@
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"build:deploy": "tsc -p tsconfig.deploy.json",
|
||||
"build:all": "npm run build && npm run build:deploy",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --write src/**/*.ts deploy-commands.ts",
|
||||
"prepare": "npm run build"
|
||||
"prepare": "npm run build:all"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
||||
7
tsconfig.deploy.json
Normal file
7
tsconfig.deploy.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["deploy-commands.ts"]
|
||||
}
|
||||
@ -1,10 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"lib": ["ES2020"],
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
@ -12,11 +13,10 @@
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"declaration": true,
|
||||
"moduleResolution": "node"
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"deploy-commands.ts"
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user