2025-08-13 00:51:44 +01:00
|
|
|
# Build stage
|
|
|
|
FROM node:18-alpine AS builder
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Install build dependencies for native modules (bcrypt, etc.)
|
|
|
|
RUN apk add --no-cache python3 make g++ libc6-compat
|
|
|
|
|
2025-08-13 00:51:44 +01:00
|
|
|
WORKDIR /app
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Copy package files first for better Docker layer caching
|
2025-08-13 00:51:44 +01:00
|
|
|
COPY package*.json ./
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Install dependencies with proper npm cache handling
|
|
|
|
RUN npm ci --only=production=false --silent
|
2025-08-13 00:51:44 +01:00
|
|
|
|
|
|
|
# Copy source code
|
|
|
|
COPY . .
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Set build-time environment variables
|
|
|
|
ARG VITE_APP_NAME="ScriptShare"
|
|
|
|
ARG VITE_APP_URL="https://scriptshare.example.com"
|
|
|
|
ARG VITE_ANALYTICS_ENABLED="false"
|
|
|
|
|
|
|
|
# Export as environment variables for Vite build
|
|
|
|
ENV VITE_APP_NAME=$VITE_APP_NAME
|
|
|
|
ENV VITE_APP_URL=$VITE_APP_URL
|
|
|
|
ENV VITE_ANALYTICS_ENABLED=$VITE_ANALYTICS_ENABLED
|
|
|
|
|
2025-08-15 22:35:15 +01:00
|
|
|
# Remove problematic server-side API files for frontend-only build
|
|
|
|
RUN rm -rf src/lib/api || true
|
|
|
|
RUN rm -rf src/lib/db || true
|
|
|
|
|
|
|
|
# Create mock API layer for frontend demo
|
|
|
|
RUN mkdir -p src/lib/api src/lib/db
|
2025-08-15 22:38:56 +01:00
|
|
|
|
|
|
|
# Create mock database files
|
|
|
|
RUN echo "export const db = {};" > src/lib/db/index.ts
|
|
|
|
RUN echo "export const users = {}; export const scripts = {}; export const ratings = {}; export const scriptVersions = {}; export const scriptAnalytics = {}; export const scriptCollections = {}; export const collectionScripts = {};" > src/lib/db/schema.ts
|
|
|
|
|
|
|
|
# Create mock API index
|
|
|
|
RUN echo "export const generateId = () => 'mock-id'; export class ApiError extends Error { constructor(message, status) { super(message); this.status = status; } }" > src/lib/api/index.ts
|
|
|
|
|
|
|
|
# Create mock auth API
|
|
|
|
RUN echo "export const authApi = { login: async () => ({ token: 'demo', user: { id: '1', username: 'demo' } }), register: async () => ({ token: 'demo', user: { id: '1', username: 'demo' } }), changePassword: async () => ({}), refreshToken: async () => ({ token: 'demo' }) };" > src/lib/api/auth.ts
|
|
|
|
|
|
|
|
# Create mock scripts API
|
|
|
|
RUN echo "export const scriptsApi = { getScripts: async () => ({ scripts: [], total: 0 }), getScript: async () => null, createScript: async () => ({}), updateScript: async () => ({}), deleteScript: async () => ({}), moderateScript: async () => ({}) };" > src/lib/api/scripts.ts
|
|
|
|
|
|
|
|
# Create mock ratings API
|
|
|
|
RUN echo "export const ratingsApi = { submitRating: async () => ({}), getUserRating: async () => null, getScriptRatingStats: async () => ({ averageRating: 0, totalRatings: 0, distribution: {} }) };" > src/lib/api/ratings.ts
|
|
|
|
|
|
|
|
# Create mock analytics API
|
|
|
|
RUN echo "export const analyticsApi = { trackEvent: async () => ({}), getAnalytics: async () => ({ views: [], downloads: [], topScripts: [], userGrowth: [] }) };" > src/lib/api/analytics.ts
|
|
|
|
|
|
|
|
# Create mock collections API
|
|
|
|
RUN echo "export const collectionsApi = { getCollections: async () => [], createCollection: async () => ({}), updateCollection: async () => ({}), deleteCollection: async () => ({}), addScriptToCollection: async () => ({}), removeScriptFromCollection: async () => ({}) };" > src/lib/api/collections.ts
|
|
|
|
|
|
|
|
# Create mock users API
|
|
|
|
RUN echo "export const usersApi = { getUser: async () => null, updateUser: async () => ({}), updateUserPermissions: async () => ({}), getAllUsers: async () => ([]), searchUsers: async () => ([]) };" > src/lib/api/users.ts
|
2025-08-15 22:35:15 +01:00
|
|
|
|
|
|
|
# Build the application (frontend only with mocks)
|
2025-08-13 00:51:44 +01:00
|
|
|
RUN npm run build
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Verify build output exists
|
|
|
|
RUN ls -la /app/dist
|
|
|
|
|
2025-08-13 00:51:44 +01:00
|
|
|
# Production stage
|
|
|
|
FROM nginx:alpine
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Install curl for health checks
|
|
|
|
RUN apk add --no-cache curl
|
|
|
|
|
2025-08-13 00:51:44 +01:00
|
|
|
# Copy built files from builder stage
|
|
|
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
|
|
|
|
|
|
# Copy nginx configuration
|
|
|
|
COPY nginx.conf /etc/nginx/nginx.conf
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Create nginx pid directory
|
|
|
|
RUN mkdir -p /var/run/nginx
|
|
|
|
|
|
|
|
# Set proper permissions
|
|
|
|
RUN chown -R nginx:nginx /usr/share/nginx/html
|
|
|
|
RUN chown -R nginx:nginx /var/cache/nginx
|
|
|
|
RUN chown -R nginx:nginx /var/log/nginx
|
|
|
|
RUN chown -R nginx:nginx /var/run/nginx
|
|
|
|
|
|
|
|
# Switch to non-root user for security
|
|
|
|
USER nginx
|
|
|
|
|
2025-08-13 00:51:44 +01:00
|
|
|
# Expose port 80
|
|
|
|
EXPOSE 80
|
|
|
|
|
2025-08-15 20:40:39 +01:00
|
|
|
# Add healthcheck
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
|
|
CMD curl -f http://localhost/health || exit 1
|
|
|
|
|
2025-08-13 00:51:44 +01:00
|
|
|
# Start nginx
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|