diff --git a/compose.yml b/compose.yml index ac6a75d..8cd6bf2 100644 --- a/compose.yml +++ b/compose.yml @@ -13,9 +13,6 @@ services: dockerfile: ./docker/php/Dockerfile env_file: .env restart: always - volumes: - - ./public/.vite:/var/www/html/public/.vite - - ./public/assets:/var/www/html/public/assets networks: - webifycms-site diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 11c8bbb..a933a62 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,3 +1,20 @@ +# ── Stage 1: Build frontend assets ────────────────────────────── +FROM node:24-alpine AS frontend + +WORKDIR /build + +# install dependencies first (layer cache) +COPY package.json package-lock.json ./ +RUN npm ci --no-audit --no-fund + +# copy source files needed by Vite +COPY assets/ ./assets/ +COPY vite.config.js ./ + +# build production assets +RUN npm run build + +# ── Stage 2: PHP-FPM runtime ─────────────────────────────────── FROM php:8.4-fpm-alpine # copy Composer binary into the container @@ -18,6 +35,10 @@ RUN composer dump-autoload --classmap-authoritative --no-dev # copy application source COPY --chown=app:app . . +# copy built frontend assets from stage 1 +COPY --from=frontend --chown=app:app /build/public/assets/ ./public/assets/ +COPY --from=frontend --chown=app:app /build/public/.vite/ ./public/.vite/ + # create non-root user RUN addgroup -g 1000 -S app && adduser -u 1000 -S app -G app @@ -32,4 +53,4 @@ USER app # expose port 9000 and start php-fpm EXPOSE 9000 -CMD ["php-fpm"] \ No newline at end of file +CMD ["php-fpm"] diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 6f694db..07d0f50 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -28,13 +28,6 @@ fi echo ">>> Pulling latest changes..." git pull origin main -# Build frontend assets -echo ">>> Installing npm dependencies..." -npm ci --no-audit --no-fund - -echo ">>> Building frontend assets..." -npm run build - # Stop existing containers echo ">>> Stopping existing containers..." docker compose down