diff --git a/.env b/.env new file mode 100644 index 0000000000000000000000000000000000000000..8c2600d2b2134c131948b78ec86bf9182cf4873d --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +BACKEND_PORT=3000 +FRONTEND_PORT=8080 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..275fcc90eda2686fdefbd87c8eeca2b779a621b8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: '1.0.0' + +services: + frontend: + build: + dockerfile: src/Dockerfile + env_file: + - .env + container_name: frontend-side + ports: + - '${FRONTEND_PORT}:${FRONTEND_PORT}' + stdin_open: true + tty: true + depends_on: + - backend + networks: + - letsDo-network + + backend: + build: + context: ./server + env_file: + - ./server/.env + container_name: node-server + ports: + - '${BACKEND_PORT}:${BACKEND_PORT}' + restart: always + depends_on: + - database + environment: + - DB_USER + - DB_PASSWORD + networks: + - letsDo-network + + database: + image: mongo + container_name: mongo-db + +networks: + letsDo-network: + driver: bridge diff --git a/package.json b/package.json index 58e31a880be7b6880f14b67b0c2a54cba5318b99..4bdd824a4a3edc0cbc03e1c45af99089118d548b 100644 --- a/package.json +++ b/package.json @@ -83,5 +83,6 @@ "dependencies": { "@babel/polyfill": "^7.12.1", "normalize.css": "^8.0.1" - } + }, + "proxy": "http://node-api:3000" } \ No newline at end of file diff --git a/server/.env b/server/.env index 11f8090109511334ab9658b68963e252ffba10f5..d73bc73a2f4c5327efeb68049ba4c8ce97101f08 100644 --- a/server/.env +++ b/server/.env @@ -1,4 +1,4 @@ -PORT=3000 +BACKEND_PORT=3000 DB_USER=yehorTodo19 DB_PASSWORD=Ik04adTsdmJrXt6d DB_NAME=test diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c24a7e106a00a93b789a3426b54bb633a316d968 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,13 @@ +FROM node:18-alpine + +WORKDIR /letsDo-app-root + +COPY package.json . + +RUN npm install + +COPY . . + +EXPOSE ${BACKEND_PORT} + +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/server/index.js b/server/index.js index 92291eeaa9eb2556c3387a7b1fd713abb939997a..46acaeed78d1ce2c129c658604ecc2311ffc064b 100644 --- a/server/index.js +++ b/server/index.js @@ -10,7 +10,7 @@ const app = express(); dotenv.config(); // * Constants -const { PORT } = process.env || 3000; +const { BACKEND_PORT } = process.env || 3000; const { DB_USER, DB_PASSWORD, DB_NAME } = process.env; // * Middleware @@ -27,8 +27,8 @@ async function start() { `mongodb+srv://${DB_USER}:${DB_PASSWORD}@cluster0.ooena3i.mongodb.net/${DB_NAME}` ); - app.listen(PORT, () => { - console.log(`Server started on port: ${PORT}`); + app.listen(BACKEND_PORT, () => { + console.log(`Server started on port: ${BACKEND_PORT}`); }); return null; diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..7fb0d1312bde2d406b17c286e09ca62797b93753 --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,15 @@ +FROM node:18-alpine + +WORKDIR /letsDo-app-root + +ADD src src + +COPY ../webpack.config.mjs . + +COPY ../package.json . + +RUN npm install + +EXPOSE ${FRONTEND_PORT} + +CMD [ "npm", "start" ] \ No newline at end of file