Files
scriptshare-cursor/Dockerfile.api

59 lines
1.5 KiB
Docker
Raw Normal View History

# ScriptShare API Dockerfile
FROM node:18-alpine
# Install system dependencies for native modules and MySQL client
RUN apk add --no-cache python3 make g++ libc6-compat curl mysql-client
WORKDIR /app
# Copy package files first for better caching
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production=false
# Copy source code
COPY . .
# Copy database configuration files
COPY src/lib/db/ src/lib/db/
COPY drizzle.config.ts ./
# Build TypeScript with API-specific config
RUN npm run build:api
# Create startup script for database migration and server start
RUN cat > start.sh << 'EOF'
#!/bin/sh
echo "Starting ScriptShare API..."
# Wait for database to be ready
echo "Waiting for database connection..."
until mysqladmin ping -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" --silent; do
echo "Database is unavailable - sleeping"
sleep 2
done
echo "Database is ready!"
# Run database migrations if needed
echo "Running database migrations..."
npm run db:migrate || echo "Migrations completed or not needed"
# Start the API server
echo "Starting API server..."
exec npm run start:api
EOF
# Make startup script executable
RUN chmod +x start.sh
# Expose port
EXPOSE 3000
# Health check that includes database connectivity
HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=5 \
CMD curl -f http://localhost:3000/api/health || exit 1
# Start with our custom startup script
CMD ["./start.sh"]