From 5268e7618b06d84c5234c3c3337e29a9a5463e35 Mon Sep 17 00:00:00 2001 From: Thibault Pouch Date: Thu, 19 Mar 2026 21:27:56 +0100 Subject: [PATCH] fix: update environment variable handling in Docker Compose files and improve contributing documentation --- .env.example | 12 ++++++++++++ CONTRIBUTING.md | 2 +- README.md | 7 +++++-- docker-compose.prod.yml | 2 +- docker-compose.yml | 4 ++-- nest-backend/docker-compose.yml | 4 +++- 6 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1125703 --- /dev/null +++ b/.env.example @@ -0,0 +1,12 @@ +# Host-side port for the API container (container port remains 3000) +API_HOST_PORT=3001 + +DATABASE_URL="postgresql://user:password@localhost:5432/nest_db" +JWT_SECRET="change_me_to_a_long_random_string" +PORT=3000 + +ADMIN_USERNAME="admin" +ADMIN_EMAIL="admin@example.com" +ADMIN_PASSWORD="change_me" +FRONT_ORIGIN="http://localhost:5173" +INTRA_ORIGIN="http://localhost:5174" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 833ce3b..a0449b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,7 +49,7 @@ npm install ### 3. Set Up Environment -Create `.env` files based on the examples in each project. See the main [README.md](./README.md) for required environment variables. +Create a root `.env` file from `.env.example` (`cp .env.example .env`) and adjust values as needed. See the main [README.md](./README.md) for required environment variables. ### 4. Create a Branch diff --git a/README.md b/README.md index 41657f9..7e9df1b 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,11 @@ nest-intra/ # Staff-only internal portal (React + Vite) ### 1. Backend Setup ```bash -cd nest-backend +# from repository root cp .env.example .env -# Edit .env with your database credentials +# Edit .env with your credentials + +cd nest-backend npm install npm run db:push # Initialize database schema npm run db:seed # Populate with sample data @@ -35,6 +37,7 @@ npm run dev # Start dev server (http://localhost:3000) #### Backend Environment Variables ```env +API_HOST_PORT=3001 DATABASE_URL="postgresql://user:password@localhost:5432/nest_db" JWT_SECRET="your-secret-key" PORT=3000 diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index b0529cc..0b3d02b 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -18,7 +18,7 @@ services: image: git.crowmate.fr/crowmate/nest-api:latest restart: unless-stopped ports: - - "3000:3000" + - "${API_HOST_PORT:-3001}:3000" environment: DATABASE_URL: postgresql://nest_user:nest_password@db:5432/nest_db depends_on: diff --git a/docker-compose.yml b/docker-compose.yml index f4f46d6..e0b0324 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,9 +18,9 @@ services: build: ./nest-backend restart: unless-stopped ports: - - "3000:3000" + - "${API_HOST_PORT:-3001}:3000" env_file: - - ./nest-backend/.env + - ./.env environment: DATABASE_URL: postgresql://nest_user:nest_password@db:5432/nest_db depends_on: diff --git a/nest-backend/docker-compose.yml b/nest-backend/docker-compose.yml index d972564..fe3aae7 100644 --- a/nest-backend/docker-compose.yml +++ b/nest-backend/docker-compose.yml @@ -18,7 +18,9 @@ services: build: . restart: unless-stopped ports: - - "3000:3000" + - "${API_HOST_PORT:-3001}:3000" + env_file: + - ../.env environment: DATABASE_URL: postgresql://nest_user:nest_password@db:5432/nest_db JWT_SECRET: ${JWT_SECRET:-change_me_in_production}