chore: add node docker service for vite dev server and prod build

This commit is contained in:
thibaud-leclere
2026-03-28 13:14:09 +01:00
parent c3dab636b1
commit d175202163
6 changed files with 66 additions and 1 deletions

2
.gitignore vendored
View File

@@ -13,3 +13,5 @@
/.phpunit.cache/
###< phpunit/phpunit ###
/.idea/
/node_modules/
/public/build/

View File

@@ -55,6 +55,15 @@ symfony\:cache-clear: ## Vide le cache Symfony
test: ## Lance les tests PHPUnit
docker compose exec app php bin/phpunit
node\:shell: ## Ouvre un shell dans le conteneur node
docker compose exec node sh
node\:install: ## Installe les dépendances npm
docker compose exec node npm install
node\:build: ## Build les assets pour la production
docker compose exec node npm run build
help: ## Affiche cette aide
@grep -E '^[a-zA-Z_\\:-]+:.*## ' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = "## "} {gsub(/\\:/, ":", $$1); sub(/:[^:]*$$/, "", $$1); printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'

View File

@@ -6,7 +6,6 @@ services:
target: dev
environment:
APP_ENV: dev
volumes:
- .:/app
- vendor:/app/vendor
@@ -17,6 +16,17 @@ services:
ports:
- "0.0.0.0:5432:5432"
node:
build:
context: .
dockerfile: docker/node/Dockerfile
target: dev
volumes:
- .:/app
- node_modules:/app/node_modules
ports:
- "5173:5173"
volumes:
vendor:
node_modules:

View File

@@ -4,6 +4,8 @@ services:
context: .
dockerfile: docker/app/Dockerfile
target: prod
additional_contexts:
node-build: docker/node
image: git.lclr.dev/thibaud-lclr/ltbxd-actorle/app:latest
ports:
- "80:80"

View File

@@ -30,6 +30,21 @@ ENV APP_ENV=dev \
POSTGRES_USER=app \
POSTGRES_PASSWORD=pwd
###
# Node build stage (for prod assets)
###
FROM node:22-alpine AS node-build
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install
COPY assets/ ./assets/
COPY vite.config.js ./
RUN npm run build
###
# Prod stage
###
@@ -40,6 +55,9 @@ RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist
COPY . .
# Copy Vite-built assets
COPY --from=node-build /app/public/build /app/public/build
RUN APP_ENV=prod composer dump-autoload --classmap-authoritative \
&& APP_ENV=prod composer run-script post-install-cmd \
&& chown -R www-data:www-data var/

24
docker/node/Dockerfile Normal file
View File

@@ -0,0 +1,24 @@
FROM node:22-alpine AS base
WORKDIR /app
###
# Dev stage
###
FROM base AS dev
# Dependencies are mounted via volume, install at startup
CMD ["sh", "-c", "npm install && npx vite"]
###
# Build stage (used by app prod image)
###
FROM base AS build
COPY package.json package-lock.json* ./
RUN npm install
COPY assets/ ./assets/
COPY vite.config.js ./
RUN npm run build