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
|
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
|
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 ./
|
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
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
# Copy the rest of the source code
|
# Build the TypeScript code directly
|
||||||
COPY . .
|
RUN npx tsc -p tsconfig.json && npx tsc -p tsconfig.deploy.json
|
||||||
|
|
||||||
# Compile TypeScript
|
|
||||||
RUN pnpm run build
|
|
||||||
|
|
||||||
# Prune devDependencies after build (optional but good practice)
|
|
||||||
RUN pnpm prune --prod
|
|
||||||
|
|
||||||
|
|
||||||
# ---- Production Stage ----
|
# ---- Production Stage ----
|
||||||
FROM node:23-alpine
|
FROM node:23-alpine
|
||||||
@ -29,17 +27,18 @@ WORKDIR /app
|
|||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
# Copy necessary files from the builder stage
|
# Copy application files
|
||||||
COPY --from=builder /app/node_modules ./node_modules
|
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY --from=builder /app/package.json ./package.json
|
COPY --from=builder /app/package.json ./package.json
|
||||||
# Copy other runtime necessities (adjust if needed)
|
COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||||
# COPY .env.example ./
|
COPY application.yml ./application.yml
|
||||||
# COPY application.yml ./
|
COPY plugins ./plugins
|
||||||
# COPY plugins ./plugins
|
|
||||||
|
|
||||||
# Expose port if needed (though likely not for a Discord bot)
|
# Install production dependencies only
|
||||||
# EXPOSE 3000
|
# 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
|
# Run the compiled JavaScript application
|
||||||
CMD ["node", "dist/index.js"]
|
CMD ["node", "dist/index.js"]
|
||||||
|
|||||||
@ -5,12 +5,14 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"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",
|
"start": "node dist/index.js",
|
||||||
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
|
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"format": "prettier --write src/**/*.ts deploy-commands.ts",
|
"format": "prettier --write src/**/*.ts deploy-commands.ts",
|
||||||
"prepare": "npm run build"
|
"prepare": "npm run build:all"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"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": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"module": "commonjs",
|
"module": "CommonJS",
|
||||||
|
"moduleResolution": "Node",
|
||||||
"lib": ["ES2020"],
|
"lib": ["ES2020"],
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"rootDir": ".",
|
"rootDir": "src",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
@ -12,11 +13,10 @@
|
|||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"moduleResolution": "node"
|
"sourceMap": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*",
|
"src/**/*"
|
||||||
"deploy-commands.ts"
|
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user