diff --git a/Dockerfile b/Dockerfile index 3ec052e..ee6ba67 100644 --- a/Dockerfile +++ b/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"] diff --git a/package.json b/package.json index d1c9b54..1ea1d3e 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,18 @@ { -"name": "discord-music-bot", + "name": "discord-music-bot", "version": "1.0.0", "description": "", "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": "", diff --git a/tsconfig.deploy.json b/tsconfig.deploy.json new file mode 100644 index 0000000..9a8a925 --- /dev/null +++ b/tsconfig.deploy.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "." + }, + "include": ["deploy-commands.ts"] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index ddc5bb8..f31d1e5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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",