# Stage 1: Composer
FROM composer:2.5 AS composer
WORKDIR /app/datapallas-portal
COPY ./wp-plugins/datapallas-portal /app/datapallas-portal
RUN composer install --no-interaction --prefer-dist --no-progress --no-suggest --no-dev --optimize-autoloader

# Stage 2: Node
FROM node:20-alpine AS theme-builder
WORKDIR /app/datapallas-theme
COPY ./wp-plugins/datapallas-portal /var/www/html/wp-content/plugins/datapallas-portal
COPY ./wp-themes/datapallas-theme /app/datapallas-theme
RUN (npm ci --no-audit --no-fund --legacy-peer-deps || npm install --no-audit --no-fund --legacy-peer-deps) && npm run production

# Stage 3: Final
FROM wordpress:6.8.2-php8.4-apache

COPY --from=composer /app/datapallas-portal /var/www/html/wp-content/plugins/datapallas-portal
COPY --from=theme-builder /app/datapallas-theme/theme /var/www/html/wp-content/themes/datapallas-theme

# Create directories with proper permissions
RUN mkdir -p /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade \
    && chown -R www-data:www-data /var/www/html/wp-content