Dockerfile.unified-working 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. && docker-php-ext-configure gd --with-freetype --with-jpeg \
  25. && docker-php-ext-install gd zip pdo_mysql \
  26. && a2enmod rewrite \
  27. && a2enmod headers
  28. # Install Composer
  29. COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
  30. # Set working directory for backend
  31. WORKDIR /var/www/html
  32. # Copy backend source code
  33. COPY backend/ ./
  34. # Install backend dependencies
  35. RUN composer install --no-dev --optimize-autoloader
  36. # Create api directory and copy backend files there
  37. 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/
  38. # Copy built frontend files to root directory
  39. COPY --from=frontend-build /app/frontend/dist/ ./
  40. # Create uploads directory and set permissions
  41. RUN mkdir -p uploads && chmod -R 755 uploads
  42. # Copy Apache configuration
  43. COPY docker/apache-unified-simple.conf /etc/apache2/sites-available/unified.conf
  44. # Enable the unified site
  45. RUN a2ensite unified.conf && a2dissite 000-default.conf
  46. # Set environment variables for frontend build
  47. ARG VUE_APP_API_URL=/api
  48. ENV VUE_APP_API_URL=/api
  49. # Expose port 80
  50. EXPOSE 80
  51. # Health check
  52. HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
  53. CMD curl -f http://localhost/api/company.php || exit 1
  54. # Copy database initialization script
  55. COPY backend/init-database.php /var/www/html/init-database.php
  56. # Copy entrypoint script
  57. COPY backend/entrypoint.sh /var/www/html/entrypoint.sh
  58. RUN chmod +x /var/www/html/entrypoint.sh
  59. # Start with entrypoint script
  60. ENTRYPOINT ["/var/www/html/entrypoint.sh"]