Fix Docker migrations - install pg driver and improve entrypoint

This commit is contained in:
Christomatt
2026-01-31 06:27:36 +01:00
parent bf9f0a3335
commit c512ecea80
2 changed files with 10 additions and 30 deletions
+6 -5
View File
@@ -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 --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy drizzle migrations and config # 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/drizzle.config.ts ./
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./ COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
COPY --from=builder --chown=nextjs:nodejs /app/package-lock.json ./ COPY --from=builder --chown=nextjs:nodejs /app/package-lock.json ./
# Install drizzle-kit globally for migrations (needed at runtime) # Install drizzle-kit and pg (postgres driver) for migrations
RUN npm install -g drizzle-kit && npm cache clean --force # 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 entrypoint script
COPY --from=builder --chown=nextjs:nodejs /app/docker/docker-entrypoint.sh ./ COPY --from=builder --chown=nextjs:nodejs /app/docker/docker-entrypoint.sh ./
@@ -83,8 +84,8 @@ USER nextjs
# Expose the application port # Expose the application port
EXPOSE 3000 EXPOSE 3000
# Health check to ensure container is running properly # Health check - longer start period to allow migrations to run
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ 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))" CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => r.statusCode === 200 ? process.exit(0) : process.exit(1))"
# Set the entrypoint # Set the entrypoint
+4 -25
View File
@@ -43,42 +43,21 @@ run_migrations() {
echo "🔄 Running database migrations..." echo "🔄 Running database migrations..."
# Run drizzle-kit push to create/update database schema # Run drizzle-kit push to create/update database schema
drizzle-kit push --force || { # This creates tables if they don't exist
echo "⚠️ Migration completed or already up to date" 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" 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 database to be ready
wait_for_db wait_for_db
# Run migrations # Run migrations
run_migrations run_migrations
# Check admin setup
check_admin_setup
# Display startup info # Display startup info
echo "" echo ""
echo "========================================" echo "========================================"