From bcee4fa601c9c803f58425a23bc1cf165de0ddf4 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Sat, 14 Feb 2026 16:47:57 -0600 Subject: [PATCH] fix(api): auto-run migrations on container start and fix ESM warning - Add docker-entrypoint.sh that runs prisma migrate deploy before starting the app, ensuring all tables exist on deployment - Add "type": "module" to package.json to eliminate Node.js ESM reparsing warning for eslint.config.js Co-Authored-By: Claude Opus 4.6 --- apps/api/Dockerfile | 7 +++++-- apps/api/docker-entrypoint.sh | 8 ++++++++ apps/api/package.json | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100755 apps/api/docker-entrypoint.sh diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index 6a6ce5a..b97b06e 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -80,6 +80,9 @@ COPY --from=builder --chown=nestjs:nodejs /app/apps/api/package.json ./apps/api/ # Copy app's node_modules which contains symlinks to root node_modules COPY --from=builder --chown=nestjs:nodejs /app/apps/api/node_modules ./apps/api/node_modules +# Copy entrypoint script (runs migrations before starting app) +COPY --from=builder --chown=nestjs:nodejs /app/apps/api/docker-entrypoint.sh ./apps/api/ + # Set working directory to API app WORKDIR /app/apps/api @@ -96,5 +99,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ # Use dumb-init to handle signals properly ENTRYPOINT ["dumb-init", "--"] -# Start the application -CMD ["node", "dist/main.js"] +# Run migrations then start the application +CMD ["sh", "docker-entrypoint.sh"] diff --git a/apps/api/docker-entrypoint.sh b/apps/api/docker-entrypoint.sh new file mode 100755 index 0000000..80b7c35 --- /dev/null +++ b/apps/api/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +echo "Running database migrations..." +npx prisma migrate deploy --schema ./prisma/schema.prisma + +echo "Starting application..." +exec node dist/main.js diff --git a/apps/api/package.json b/apps/api/package.json index ce11f92..b90f4b2 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -2,6 +2,7 @@ "name": "@mosaic/api", "version": "0.0.1", "private": true, + "type": "module", "scripts": { "build": "nest build", "dev": "nest start --watch",