From 1cf1b00a9a5ea691007cc78491d4cf1e48b238b6 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Tue, 9 Dec 2025 13:59:23 +0100 Subject: [PATCH] fix: Simplify Dockerfile to single-stage with tsx runtime --- worker/Dockerfile | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/worker/Dockerfile b/worker/Dockerfile index 1ffe447..8bc1dab 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -1,33 +1,19 @@ -### Multi-stage build: compile TypeScript in a builder image, produce a smaller runtime image +### Single-stage build: Run worker with tsx TypeScript runtime ### IMPORTANT: Dokploy must set dockerContextPath="." (repo root) in database -### This allows the build to access package.json and other files from repo root ### Dockerfile path should be "worker/Dockerfile" -FROM node:20 AS builder +FROM node:20-alpine AS runtime WORKDIR /usr/src/app -# Copy package manifests and install all deps (including dev) for build +# Install production dependencies AND tsx for TypeScript runtime COPY package.json package-lock.json ./ -RUN npm ci --silent +RUN npm ci --production --silent && npm install tsx dotenv --silent -# Copy entire project and compile TypeScript -COPY . . -# Try to compile the project; if there is no TS config for worker, keep files as-is -RUN npx tsc -p tsconfig.json --outDir dist || echo "tsc exit code ignored" - -FROM node:20-alpine AS runner -WORKDIR /usr/src/app - -# Install only production dependencies -COPY package.json package-lock.json ./ -RUN npm ci --production --silent - -# Copy compiled output from builder (if present) and essential runtime files -COPY --from=builder /usr/src/app/dist ./dist -COPY --from=builder /usr/src/app/worker ./worker -COPY --from=builder /usr/src/app/lib ./lib +# Copy worker code and shared lib +COPY worker ./worker +COPY lib ./lib ENV NODE_ENV=production -# If compiled JS exists, run compiled entrypoint; otherwise fallback to tsx runtime -CMD ["sh", "-c", "if [ -f ./dist/worker/index.js ]; then node ./dist/worker/index.js; else npx tsx ./worker/index.ts; fi"] +# Run worker using tsx (TypeScript runtime) +CMD ["npx", "tsx", "./worker/index.ts"]