Skip to content

Commit

Permalink
add docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
minhquang31122000 committed Nov 15, 2024
1 parent 5d5a711 commit 6f32cc8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
28 changes: 13 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
FROM node:20.18.0
# Stage 1: Build the React app
FROM node:20.18.0 AS build

# Set the working directory
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
COPY . .

# Install dependencies
RUN npm install

# Copy the rest of the application code to the working directory
COPY . .
# Use environment variables for the build
ARG REACT_APP_API_SERVICE_URL
ENV REACT_APP_API_SERVICE_URL=${REACT_APP_API_SERVICE_URL}

# Build the React app
# Build the app
RUN npm run build

# Install serve to serve the build folder
RUN npm install -g serve

# Set the command to run the app
CMD ["serve", "-s", "build"]
# Stage 2: Serve with Nginx
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose the port the app runs on
EXPOSE 5000
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
services:
movies-app-client:
build:
context: .
dockerfile: Dockerfile
args:
REACT_APP_API_SERVICE_URL: ${REACT_APP_API_SERVICE_URL}
ports:
- "3000:80"
env_file:
- .env
9 changes: 9 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;

location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri /index.html;
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@testing-library/user-event": "^13.2.1",
"axios": "^1.3.2",
"dayjs": "^1.11.7",
"dotenv": "^16.4.5",
"formik": "^2.2.9",
"query-string": "^8.1.0",
"react": "^18.2.0",
Expand Down Expand Up @@ -51,4 +52,4 @@
"last 1 safari version"
]
}
}
}
3 changes: 3 additions & 0 deletions src/api/client/public.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import queryString from "query-string";

const baseURL = process.env.REACT_APP_API_SERVICE_URL;

console.log({ baseURL });


const publicClient = axios.create({
baseURL,
paramsSerializers: {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4065,6 +4065,11 @@ dotenv@^10.0.0:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

dotenv@^16.4.5:
version "16.4.5"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

duplexer@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6"
Expand Down

0 comments on commit 6f32cc8

Please sign in to comment.