chore(worker): two-stage Dockerfile + README with Dokploy settings
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 2s

This commit is contained in:
Ahmed Darrazi 2025-12-09 12:47:00 +01:00
parent 2843281f2f
commit 14722adf0c
2 changed files with 52 additions and 15 deletions

View File

@ -1,24 +1,31 @@
FROM node:20 ### Multi-stage build: compile TypeScript in a builder image, produce a smaller runtime image
# Create app directory FROM node:20 AS builder
WORKDIR /usr/src/app WORKDIR /usr/src/app
# Install dependencies first (copy package files) # Copy package manifests and install all deps (including dev) for build
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
# Install full dependencies so `tsx` can run worker/index.ts
RUN npm ci --silent RUN npm ci --silent
# Copy only required directories to keep image smaller # Copy project files and compile TypeScript output to `dist/`
COPY worker ./worker COPY . .
COPY lib ./lib # Try to compile the project; if there is no TS config for worker, keep files as-is
COPY node_modules ./node_modules RUN npx tsc -p tsconfig.json --outDir dist || echo "tsc exit code ignored"
COPY .env* ./
COPY tsconfig.json ./ 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 --from=builder /usr/src/app/.env* ./ || true
ENV NODE_ENV=production ENV NODE_ENV=production
# Set working directory to repo root; worker is invoked by npm script # If compiled JS exists, run compiled entrypoint; otherwise fallback to tsx runtime
WORKDIR /usr/src/app CMD ["sh", "-c", "if [ -f ./dist/worker/index.js ]; then node ./dist/worker/index.js; else npx tsx ./worker/index.ts; fi"]
CMD ["npm", "run", "worker:start"]

View File

@ -6,6 +6,36 @@ Build context
- Build path: `worker/` (Dokploy should use this path so the worker Dockerfile is found) - Build path: `worker/` (Dokploy should use this path so the worker Dockerfile is found)
- Dockerfile: `worker/Dockerfile` - Dockerfile: `worker/Dockerfile`
Two-stage build (recommended)
-----------------------------
- This repository includes a two-stage Dockerfile that compiles TypeScript in a builder stage and produces a smaller runtime image.
- The builder stage runs `npx tsc -p tsconfig.json --outDir dist` and the runtime stage will run the compiled `dist/worker/index.js` if present. If compilation is not performed, the container falls back to running `npx tsx ./worker/index.ts`.
Recommended Dokploy settings
----------------------------
- Provider: `Gitea`
- Repository: `ahmido/tenantpilot` (or your repo)
- Branch: `development`
- Build path: `worker/`
- Watch paths: `worker/**`, `lib/**`, `package.json`, `package-lock.json`
Notes
-----
- The Dockerfile attempts to run compiled JS first; if no compiled output is present the runtime falls back to `tsx`.
- If Dokploy requires a separate webhook per app, use the worker webhook URL provided in this repo's docs/workflow.
Notes on environment
--------------------
- Ensure Dokploy provides `REDIS_URL` in the environment for the worker container.
- Provide Azure AD secrets in Dokploy environment vars: `AZURE_AD_TENANT_ID`, `AZURE_AD_CLIENT_ID`, `AZURE_AD_CLIENT_SECRET`.
Worker container and Dokploy settings
====================================
Build context
-------------
- Build path: `worker/` (Dokploy should use this path so the worker Dockerfile is found)
- Dockerfile: `worker/Dockerfile`
Recommended Dokploy settings Recommended Dokploy settings
---------------------------- ----------------------------
- Provider: `Gitea` - Provider: `Gitea`