fix: set runner WORKDIR to .medusa/server for custom module resolution

This commit is contained in:
Nermin Karic
2026-11-23 01:11:52 +01:00
parent df9f8b3a7c
commit 3ed45c4362
2 changed files with 14 additions and 18 deletions

View File

@@ -26,19 +26,16 @@ COPY apps/backend ./apps/backend
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=2048"
# Build Medusa backend and admin dashboard
# Build Medusa backend and admin dashboard (compiled to .medusa/server)
RUN npm run build --workspace=@dtc/backend
# Copy compiled medusa-config.js and instrumentation.js to project root for production Node.js runtime
RUN cp apps/backend/.medusa/server/medusa-config.js apps/backend/medusa-config.js && \
if [ -f apps/backend/.medusa/server/instrumentation.js ]; then cp apps/backend/.medusa/server/instrumentation.js apps/backend/instrumentation.js; fi
# Prune devDependencies to keep image light and avoid OOM during copy
RUN npm prune --production --workspace=@dtc/backend
# 3. Production runner stage
# In Medusa v2, production runtime runs from the compiled .medusa/server directory
FROM node:22-alpine AS runner
WORKDIR /app/apps/backend
WORKDIR /app/apps/backend/.medusa/server
RUN apk add --no-cache libc6-compat curl
@@ -49,17 +46,18 @@ ENV PORT=9000
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 medusa
# Copy pruned dependencies from builder (sequential dependency prevents BuildKit parallel I/O spike)
# Copy dependencies and compiled server artifacts
COPY --from=builder --chown=medusa:nodejs /app/node_modules /app/node_modules
COPY --from=builder --chown=medusa:nodejs /app/package.json /app/package-lock.json /app/
COPY --from=builder --chown=medusa:nodejs /app/apps/backend /app/apps/backend
# Uploads directory
RUN mkdir -p /app/apps/backend/uploads && chown -R medusa:nodejs /app/apps/backend/uploads
RUN mkdir -p /app/apps/backend/.medusa/server/uploads /app/apps/backend/uploads && \
chown -R medusa:nodejs /app/apps/backend
USER medusa
EXPOSE 9000
# Run migrations and start Medusa production server
# Medusa v2 production entrypoint: run migrations then start server from compiled .medusa/server
CMD ["sh", "-c", "npx medusa db:migrate && npm run start"]