From 55f23d332a0964c1d45074831e5d61a253967536 Mon Sep 17 00:00:00 2001 From: Alekhd <90794297+Alikohd@users.noreply.github.com> Date: Thu, 12 Dec 2024 22:31:31 +0300 Subject: [PATCH] feat: add split docker composes, remove ports env --- .env | 5 +---- .env_dev | 11 +++++++++++ docker-compose-dev.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 6 ++---- 4 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 .env_dev create mode 100644 docker-compose-dev.yaml diff --git a/.env b/.env index b24f432..83af99b 100644 --- a/.env +++ b/.env @@ -1,4 +1,3 @@ -BACKEND_PORT=8080 DATABASE_HOST=mongo DATABASE_PORT_MAPPING=27017 DATABASE_NAME=gym-db @@ -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 \ No newline at end of file +JWT_LIFETIME=7200000 \ No newline at end of file diff --git a/.env_dev b/.env_dev new file mode 100644 index 0000000..07ee5b3 --- /dev/null +++ b/.env_dev @@ -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 \ No newline at end of file diff --git a/docker-compose-dev.yaml b/docker-compose-dev.yaml new file mode 100644 index 0000000..0898b88 --- /dev/null +++ b/docker-compose-dev.yaml @@ -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: \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 1dc50d2..431f682 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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 @@ -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: