From 22c073b49d53bb7c32a46a2d0efbaeb393fe4a07 Mon Sep 17 00:00:00 2001 From: hysimok Date: Sun, 24 Oct 2021 23:45:58 +0900 Subject: [PATCH 1/3] FEAT: docker-compose with Dockerfile --- .gitignore | 1 + backend/Dockerfile | 7 +++++++ docker-compose.yml | 48 +++++++++++++++++++++++++++++++++++++++++++++ frontend/Dockerfile | 7 +++++++ 4 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..bdbe8ad --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,7 @@ +FROM node:lts-alpine3.13 +WORKDIR /usr/src/backend + +COPY . . +RUN npm install +RUN npm run build +CMD npm run start \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2a77a4e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +services: + # nestjs: + # build: ./nestjs-toy/ + # ports: + # - "3000:3000" + database: + image: postgres + environment: + POSTGRES_PASSWORD: "${DB_PASSWORD}" + POSTGRES_USER: "${DB_USERNAME}" + POSTGRES_DB: "${DB_NAME}" + POSTGRES_INITDB_ARGS: "" + POSTGRES_INITDB_WALDIR: "" + POSTGRES_HOST_AUTH_METHOD: "" + volumes: + # - ./initdb.d:/docker-entrypoint-initdb.d + - db_data:/var/lib/postgresql/data + + backend: + build: ./backend + ports: + - "5000:5000" + environment: + DB_HOST: "database" + DB_PORT: "${DB_PORT}" + DB_USERNAME: "${DB_USERNAME}" + DB_PASSWORD: "${DB_PASSWORD}" + DB_NAME: "${DB_NAME}" + FT_CLIENT_ID: "${FT_CLIENT_ID}" + FT_CLIENT_SECRET: "${FT_CLIENT_SECRET}" + FT_CALLBACK: "${FT_CALLBACK}" + JWT_SECRET: "${JWT_SECRET}" + SESSION_SECRET: "${SESSION_SECRET}" + CLIENT_ADDRESS: "${CLIENT_ADDRESS}" + + frontend: + build: ./frontend + ports: + - "3000:3000" + environment: + REACT_APP_42_CLIENT_ID: ${REACT_APP_42_CLIENT_ID} + REACT_APP_42_CLIENT_SECRET: ${REACT_APP_42_CLIENT_SECRET} + REACT_APP_42_CALLBACK: ${REACT_APP_42_CALLBACK} + REACT_APP_SERVER_ADDRESS: ${REACT_APP_SERVER_ADDRESS} + REACT_APP_SOCKET_ADDRESS: ${REACT_APP_SOCKET_ADDRESS} + +volumes: + db_data: \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..b409dc3 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,7 @@ +FROM node:lts-alpine3.13 +WORKDIR /usr/src/frontend + +COPY . . +RUN npm install +RUN npm run build +CMD npm run start \ No newline at end of file From 13a54d9a45325032870c120717ba1a5144e9fec1 Mon Sep 17 00:00:00 2001 From: hysimok Date: Mon, 25 Oct 2021 23:24:42 +0900 Subject: [PATCH 2/3] [REPLACE] environment -> env_file --- docker-compose.yml | 38 +++++++++----------------------------- package-lock.json | 3 --- 2 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 package-lock.json diff --git a/docker-compose.yml b/docker-compose.yml index 2a77a4e..caddce6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,48 +1,28 @@ +version: '3' + services: - # nestjs: - # build: ./nestjs-toy/ - # ports: - # - "3000:3000" database: image: postgres + ports: + - "5432:5432" environment: POSTGRES_PASSWORD: "${DB_PASSWORD}" POSTGRES_USER: "${DB_USERNAME}" POSTGRES_DB: "${DB_NAME}" - POSTGRES_INITDB_ARGS: "" - POSTGRES_INITDB_WALDIR: "" - POSTGRES_HOST_AUTH_METHOD: "" volumes: # - ./initdb.d:/docker-entrypoint-initdb.d - - db_data:/var/lib/postgresql/data + - ./db_data:/var/lib/postgresql/data backend: build: ./backend ports: - "5000:5000" - environment: - DB_HOST: "database" - DB_PORT: "${DB_PORT}" - DB_USERNAME: "${DB_USERNAME}" - DB_PASSWORD: "${DB_PASSWORD}" - DB_NAME: "${DB_NAME}" - FT_CLIENT_ID: "${FT_CLIENT_ID}" - FT_CLIENT_SECRET: "${FT_CLIENT_SECRET}" - FT_CALLBACK: "${FT_CALLBACK}" - JWT_SECRET: "${JWT_SECRET}" - SESSION_SECRET: "${SESSION_SECRET}" - CLIENT_ADDRESS: "${CLIENT_ADDRESS}" + env_file: + - ./backend/.env frontend: build: ./frontend ports: - "3000:3000" - environment: - REACT_APP_42_CLIENT_ID: ${REACT_APP_42_CLIENT_ID} - REACT_APP_42_CLIENT_SECRET: ${REACT_APP_42_CLIENT_SECRET} - REACT_APP_42_CALLBACK: ${REACT_APP_42_CALLBACK} - REACT_APP_SERVER_ADDRESS: ${REACT_APP_SERVER_ADDRESS} - REACT_APP_SOCKET_ADDRESS: ${REACT_APP_SOCKET_ADDRESS} - -volumes: - db_data: \ No newline at end of file + env_file: + - ./frontend/.env diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 48e341a..0000000 --- a/package-lock.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "lockfileVersion": 1 -} From 77978a45a8d9c1d87ac1e89f1e8e9a26c307c0c3 Mon Sep 17 00:00:00 2001 From: hysimok Date: Mon, 25 Oct 2021 23:56:49 +0900 Subject: [PATCH 3/3] add container_name configuration --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index caddce6..22e6a03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,7 @@ version: '3' services: database: image: postgres + container_name: database ports: - "5432:5432" environment: @@ -15,6 +16,7 @@ services: backend: build: ./backend + container_name: backend ports: - "5000:5000" env_file: @@ -22,6 +24,7 @@ services: frontend: build: ./frontend + container_name: frontend ports: - "3000:3000" env_file: