Merge pull request #104 from HyunggyuJang/refactor/docker

Refactor: merge docker setup file into one dockerfile & one docker-compose.yml
This commit is contained in:
Danny Avila 2023-03-22 20:13:10 -04:00 committed by GitHub
commit 90b74aff2e
7 changed files with 77 additions and 90 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
**/node_modules
**/.env

35
Dockerfile Normal file
View file

@ -0,0 +1,35 @@
FROM node:19-alpine AS react-client
WORKDIR /client
# copy package.json into the container at /client
COPY /client/package*.json /client/
# install dependencies
RUN npm ci
# Copy the current directory contents into the container at /client
COPY /client/ /client/
# Build webpack artifacts
RUN npm run build
FROM node:19-alpine AS node-api
WORKDIR /api
# copy package.json into the container at /api
COPY /api/package*.json /api/
# install dependencies
RUN npm ci
# Copy the current directory contents into the container at /api
COPY /api/ /api/
# Copy the client side code
COPY --from=react-client /client/public /client/public
# Make port 3080 available to the world outside this container
EXPOSE 3080
# Expose the server to 0.0.0.0
ENV HOST=0.0.0.0
# Run the app when the container launches
CMD ["npm", "start"]
# Optional: for client with nginx routing
FROM nginx:stable-alpine AS nginx-client
WORKDIR /usr/share/nginx/html
COPY --from=react-client /client/public /usr/share/nginx/html
# Add your nginx.conf
COPY /client/nginx.conf /etc/nginx/conf.d/default.conf
ENTRYPOINT ["nginx", "-g", "daemon off;"]

View file

@ -1,2 +0,0 @@
/node_modules
.env

View file

@ -1,16 +0,0 @@
FROM node:19-alpine
WORKDIR /api
# copy package.json into the container at /api
COPY package*.json /api/
# install dependencies
RUN npm ci
# Copy the current directory contents into the container at /api
COPY . /api/
# Make port 3080 available to the world outside this container
EXPOSE 3080
# Expose the server to 0.0.0.0
ENV HOST=0.0.0.0
# Run the app when the container launches
CMD ["npm", "start"]
# docker build -t node-api .

View file

@ -1,2 +0,0 @@
/node_modules
.env

View file

@ -1,22 +0,0 @@
# Stage 1
FROM node:19-alpine as builder
WORKDIR /client
# copy package.json into the container at /client
COPY package*.json /client/
# install dependencies
RUN npm ci
# Copy the current directory contents into the container at /client
COPY . /client/
# Build webpack artifacts
RUN npm run build
# Stage 2
FROM nginx:stable-alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY --from=builder /client/public /usr/share/nginx/html
# Add your nginx.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
ENTRYPOINT ["nginx", "-g", "daemon off;"]
# docker build -t react-client .

View file

@ -1,50 +1,42 @@
version: "2" version: "3.4"
services: services:
client: # client:
image: react-client # image: nginx-client
build: ./client # build:
restart: always # context: .
ports: # target: nginx-client
- "3080:80" # restart: always
volumes: # ports:
- ./client:/client # - 3080:80
- /client/node_modules # volumes:
links: # - /client/node_modules
- api # depends_on:
networks: # - api
- webappnetwork api:
api: ports:
image: node-api - 3080:3080 # Change it to 9000:3080 if you want to use nginx
build: ./api depends_on:
restart: always - mongodb
env_file: image: node-api
- ./api/.env build:
environment: context: .
- HOST=0.0.0.0 target: node-api
- NODE_ENV=production restart: always
- MONGO_URI=mongodb://mongodb:27017/chatgpt-clone env_file:
ports: - ./api/.env
- "9000:3080" environment:
volumes: - HOST=0.0.0.0
- ./api:/api - NODE_ENV=production
- /api/node_modules - MONGO_URI=mongodb://mongodb:27017/chatgpt-clone
depends_on: volumes:
- mongodb - /client/node_modules
networks: - ./api:/api
- webappnetwork - /api/node_modules
mongodb: mongodb:
image: mongo image: mongo
restart: always restart: always
container_name: mongodb container_name: mongodb
volumes: volumes:
- ./data-node:/data/db - ./data-node:/data/db
ports: command: mongod --noauth
- 27020:27017
command: mongod --noauth
networks:
- webappnetwork
networks:
webappnetwork:
driver: bridge