Skip to content

Commit

Permalink
feat: add split docker composes, remove ports env
Browse files Browse the repository at this point in the history
  • Loading branch information
Alikohd committed Dec 12, 2024
1 parent 273e4b4 commit 55f23d3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
5 changes: 1 addition & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BACKEND_PORT=8080
DATABASE_HOST=mongo
DATABASE_PORT_MAPPING=27017
DATABASE_NAME=gym-db
Expand All @@ -9,6 +8,4 @@ DATABASE_URL=mongodb://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST

# change jwt secret
JWT_SECRET_PHRASE=NDQ1ZjAzNjQtMzViZi00MDRjLTljZjQtNjNjYWIyZTU5ZDYw
JWT_LIFETIME=7200000

FRONTEND_PORT=3000
JWT_LIFETIME=7200000
11 changes: 11 additions & 0 deletions .env_dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DATABASE_HOST=localhost
DATABASE_PORT_MAPPING=27017
DATABASE_NAME=gym-db
DATABASE_USERNAME=root
# change password
DATABASE_PASSWORD=root
DATABASE_URL=mongodb://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}:27017/${DATABASE_NAME}?authSource=admin

# change jwt secret
JWT_SECRET_PHRASE=NDQ1ZjAzNjQtMzViZi00MDRjLTljZjQtNjNjYWIyZTU5ZDYw
JWT_LIFETIME=7200000
41 changes: 41 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3.8'

services:
backend:
build: ./gym-rest-api
image: gym-rest-1.0.0
container_name: gym-rest
env_file:
- .env
ports:
- "127.0.0.1:8080:8080"
depends_on:
- mongo

frontend:
build: ./frontend
env_file:
- .env
image: gym-frontend-1.0.0
container_name: gym-frontend
ports:
- "127.0.0.1:3000:3000"

mongo:
image: mongo:8.0
restart: always
env_file:
- .env
ports:
- "27017:27017"
expose:
- 27017
volumes:
- mongo-gym-db:/data/db
- ./gym-rest-api/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
environment:
MONGO_INITDB_ROOT_USERNAME: ${DATABASE_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${DATABASE_PASSWORD}

volumes:
mongo-gym-db:
6 changes: 2 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
env_file:
- .env
ports:
- "127.0.0.1:${BACKEND_PORT}:8080"
- "127.0.0.1:8080:8080"
depends_on:
- mongo

Expand All @@ -19,15 +19,13 @@ services:
image: gym-frontend-1.0.0
container_name: gym-frontend
ports:
- "127.0.0.1:${FRONTEND_PORT}:3000"
- "127.0.0.1:3000:3000"

mongo:
image: mongo:8.0
restart: always
env_file:
- .env
ports:
- "27017"
expose:
- 27017
volumes:
Expand Down

0 comments on commit 55f23d3

Please sign in to comment.