Dockerfile.unified-working 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Multi-stage build for unified backend + frontend container
  2. FROM node:18-alpine AS frontend-build
  3. # Set working directory for frontend build
  4. WORKDIR /app/frontend
  5. # Copy frontend package files
  6. COPY frontend/package*.json ./
  7. # Install frontend dependencies
  8. RUN npm ci --only=production
  9. # Copy frontend source code
  10. COPY frontend/ ./
  11. # Build frontend for production
  12. RUN npm run build && ls -la dist/
  13. # Backend + Frontend unified container
  14. FROM php:8.1-apache
  15. # Install system dependencies and PHP extensions
  16. RUN apt-get update && apt-get install -y \
  17. libzip-dev \
  18. libpng-dev \
  19. libjpeg-dev \
  20. libfreetype6-dev \
  21. zip \
  22. unzip \
  23. curl \
  24. nodejs \
  25. npm \
  26. && docker-php-ext-configure gd --with-freetype --with-jpeg \
  27. && docker-php-ext-install gd zip pdo_mysql \
  28. && a2enmod rewrite \
  29. && a2enmod headers
  30. # Install Composer
  31. COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
  32. # Set working directory for backend
  33. WORKDIR /var/www/html
  34. # Copy backend source code
  35. COPY backend/ ./
  36. # Install backend dependencies
  37. RUN composer install --no-dev --optimize-autoloader
  38. # Create api directory and copy backend files there
  39. RUN mkdir -p api && cp -r *.php api/ && cp -r models api/ && cp -r vendor api/ && cp composer.json api/ && cp -r config api/ && cp -r middleware api/ && cp -r database api/
  40. # Copy built frontend files to root directory
  41. COPY --from=frontend-build /app/frontend/dist/ ./
  42. RUN find /var/www/html -name "*.html" -o -name "*.js" -o -name "*.css" | wc -l && echo "Frontend files copied successfully"
  43. # Create uploads directory and set permissions
  44. RUN mkdir -p uploads && chmod -R 755 uploads
  45. # Copy Apache configuration
  46. COPY docker/apache-unified-simple.conf /etc/apache2/sites-available/unified.conf
  47. # Enable the unified site
  48. RUN a2ensite unified.conf && a2dissite 000-default.conf
  49. # Set environment variables for frontend build
  50. ARG VUE_APP_API_URL=/api
  51. ENV VUE_APP_API_URL=/api
  52. # Expose port 80
  53. EXPOSE 80
  54. # Health check
  55. HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
  56. CMD curl -f http://localhost/api/company.php || exit 1
  57. # Copy database initialization script
  58. COPY backend/init-database.php /var/www/html/init-database.php
  59. # Copy entrypoint script
  60. COPY backend/entrypoint.sh /var/www/html/entrypoint.sh
  61. RUN chmod +x /var/www/html/entrypoint.sh
  62. # Start with entrypoint script
  63. ENTRYPOINT ["/var/www/html/entrypoint.sh"]