create-react-app seems to struggle a bit [1] and many folks are recommending vite as an alternative, as that project is more active. For me the reason to switch to vite is to reduce dependencies and speed up the build process. Replacing create-react-app with vite reduce the number of dependencies from 1762 to 444. I was also quite surprised, by how small the actual diff in this commit is. From that perspective there is almost no discernible difference between the two tools. [1]: https://github.com/reactjs/react.dev/pull/5487#issuecomment-1409720741
56 lines
1.1 KiB
Docker
56 lines
1.1 KiB
Docker
FROM node:19-bullseye-slim AS build
|
|
|
|
RUN apt-get update && \
|
|
apt-get install -y \
|
|
git
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package.json and tsconfig.json
|
|
COPY ./app/package.json ./
|
|
COPY ./app/tsconfig.json ./
|
|
|
|
# Install Node.js dependencies
|
|
RUN npm install
|
|
|
|
# Copy public, and src directories
|
|
COPY ./app/public ./public
|
|
COPY ./app/src ./src
|
|
|
|
# Set environment variables
|
|
ENV NODE_ENV=production
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
FROM node:19-bullseye-slim AS server
|
|
|
|
# Set the working directory
|
|
WORKDIR /app
|
|
|
|
# Update the package index and install required dependencies
|
|
# RUN apt-get update && \
|
|
# apt-get install -y \
|
|
# curl \
|
|
# build-essential \
|
|
# libssl-dev \
|
|
# openssl
|
|
|
|
COPY ./server/package.json ./server/tsconfig.json ./
|
|
|
|
# Install Node.js dependencies from package.json
|
|
RUN npm install
|
|
|
|
# Copy the rest of the application code into the working directory
|
|
COPY ./server/src ./src
|
|
|
|
RUN CI=true sh -c "cd /app && mkdir data && npm run start && rm -rf data"
|
|
|
|
COPY --from=build /app/build /app/public
|
|
|
|
LABEL org.opencontainers.image.source="https://github.com/cogentapps/chat-with-gpt"
|
|
ENV PORT 3000
|
|
|
|
CMD ["npm", "run", "start"]
|