From 9716373fa2d754177d4e71082b9079b71daab971 Mon Sep 17 00:00:00 2001 From: Luc SORIGNET Date: Sat, 15 Feb 2025 13:01:02 +0100 Subject: [PATCH] feat: preparation du dockerfile pour le frontend [#13] --- Front-End/Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 41 ++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 Front-End/Dockerfile diff --git a/Front-End/Dockerfile b/Front-End/Dockerfile new file mode 100644 index 0000000..dcfb896 --- /dev/null +++ b/Front-End/Dockerfile @@ -0,0 +1,36 @@ +# Build argument pour choisir le mode +ARG BUILD_MODE=production + +# Build stage pour production uniquement +FROM node:18-alpine AS builder +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . +RUN npm run build + +# Development stage +FROM node:18-alpine AS development +ENV NODE_ENV=development +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +# Ajout de la surveillance des fichiers pour le hot reload +ENV WATCHPACK_POLLING=true +ENV CHOKIDAR_USEPOLLING=true +COPY . . +EXPOSE 3000 +CMD ["npm", "run", "dev"] + +# Production stage +FROM node:18-alpine AS production +WORKDIR /app +ENV NODE_ENV=production +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +EXPOSE 3000 +CMD ["node", "server.js"] + +# Final stage selection +FROM ${BUILD_MODE} diff --git a/docker-compose.yml b/docker-compose.yml index 0c10cff..c725dc9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,5 @@ -# A Docker Compose must always start with the version tag. -# We use '3' because it's the last version. -#version: '3' +version: '3' -# You should know that Docker Compose works with services. -# 1 service = 1 container. -# For example, a service, a server, a client, a database... -# We use the keyword 'services' to start to create services. services: redis: image: 'redis:latest' @@ -15,27 +9,14 @@ services: environment: - TZ=Europe/Paris - # The name of our service is "database" - # but you can use the name of your choice. - # Note: This may change the commands you are going to use a little bit. database: - # Official Postgres image from DockerHub (we use the last version) image: 'postgres:latest' - - # By default, a Postgres database is running on the 5432 port. - # If we want to access the database from our computer (outside the container), - # we must share the port with our computer's port. - # The syntax is [port we want on our machine]:[port we want to retrieve in the container] - # Note: You are free to change your computer's port, - # but take into consideration that it will change the way - # you are connecting to your database. ports: - 5432:5432 - environment: - POSTGRES_USER: postgres # The PostgreSQL user (useful to connect to the database) - POSTGRES_PASSWORD: postgres # The PostgreSQL password (useful to connect to the database) - POSTGRES_DB: school # The PostgreSQL default database (automatically created at first launch) + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: school TZ: Europe/Paris backend: @@ -56,3 +37,17 @@ services: - database command: python start.py + frontend: + build: + context: ./Front-End + args: + - BUILD_MODE=development + ports: + - 3000:3000 + volumes: + - ./Front-End:/app + environment: + - TZ=Europe/Paris + depends_on: + - backend +