From c512ecea8066ad46864881ddd7c88a511efdc4d6 Mon Sep 17 00:00:00 2001 From: Christomatt Date: Sat, 31 Jan 2026 06:27:36 +0100 Subject: [PATCH] Fix Docker migrations - install pg driver and improve entrypoint --- docker/Dockerfile | 11 ++++++----- docker/docker-entrypoint.sh | 29 ++++------------------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 6af805c..7251883 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -65,13 +65,14 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # Copy drizzle migrations and config -COPY --from=builder --chown=nextjs:nodejs /app/src/db/migrations ./src/db/migrations +COPY --from=builder --chown=nextjs:nodejs /app/drizzle ./drizzle COPY --from=builder --chown=nextjs:nodejs /app/drizzle.config.ts ./ COPY --from=builder --chown=nextjs:nodejs /app/package.json ./ COPY --from=builder --chown=nextjs:nodejs /app/package-lock.json ./ -# Install drizzle-kit globally for migrations (needed at runtime) -RUN npm install -g drizzle-kit && npm cache clean --force +# Install drizzle-kit and pg (postgres driver) for migrations +# These are needed at runtime for the entrypoint to run migrations +RUN npm install -g drizzle-kit pg && npm cache clean --force # Copy entrypoint script COPY --from=builder --chown=nextjs:nodejs /app/docker/docker-entrypoint.sh ./ @@ -83,8 +84,8 @@ USER nextjs # Expose the application port EXPOSE 3000 -# Health check to ensure container is running properly -HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ +# Health check - longer start period to allow migrations to run +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=5 \ CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => r.statusCode === 200 ? process.exit(0) : process.exit(1))" # Set the entrypoint diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index e25de91..eb207f6 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -43,42 +43,21 @@ run_migrations() { echo "🔄 Running database migrations..." # Run drizzle-kit push to create/update database schema - drizzle-kit push --force || { - echo "⚠️ Migration completed or already up to date" + # This creates tables if they don't exist + npx drizzle-kit push --force 2>&1 || { + echo "⚠️ Migration push returned non-zero (may be already up to date or error)" + echo " Continuing anyway..." } echo "✅ Migration check complete" } -# Function to check/create initial admin user -check_admin_setup() { - echo "" - echo "👤 Checking admin setup..." - - # This is a placeholder - you can add logic here to ensure - # at least one admin user exists on first run - # For now, we rely on the application to handle this - - echo "✅ Admin check complete (handled by application)" -} - -# Install netcat for database connectivity check if not present -if ! command -v nc >/dev/null 2>&1; then - echo "📦 Installing netcat for database checks..." - # Note: In Alpine, nc is typically included in busybox - # If not, we'll proceed anyway and let the app handle connection - echo " (Skipping - using application-level retry logic)" -fi - # Wait for database to be ready wait_for_db # Run migrations run_migrations -# Check admin setup -check_admin_setup - # Display startup info echo "" echo "========================================"