diff --git a/Dockerfile b/Dockerfile index 6fc9b2c..3f6aa0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,58 @@ -FROM node:18 AS build +# syntax=docker/dockerfile:1.4 +# 1. For build React app +FROM node:lts AS development + +# Set working directory WORKDIR /app -# Copy only package files first (better caching) -COPY package*.json ./ +# +COPY package.json /app/package.json +COPY package-lock.json /app/package-lock.json -# This layer will be cached if package.json doesn't change -RUN npm ci --legacy-peer-deps +# Same as npm install +RUN npm ci + +COPY . /app + +ENV CI=true +ENV PORT=3000 + +CMD [ "npm", "start" ] + +FROM development AS build -# Copy source code (this changes more often) -COPY . . RUN npm run build + +FROM development as dev-envs +RUN < /etc/nginx/conf.d/default.conf -EXPOSE 80 \ No newline at end of file + +# Copy config nginx +COPY --from=build /app/.nginx/nginx.conf /etc/nginx/conf.d/default.conf + +WORKDIR /usr/share/nginx/html + +# Remove default nginx static assets +RUN rm -rf ./* + +# Copy static assets from builder stage +COPY --from=build /app/build . + +# Containers run nginx with global directives and daemon off +ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file