From 91df163ee6c9130c607be60dd693b98f829a97ca Mon Sep 17 00:00:00 2001 From: Albin Karlsson Date: Thu, 21 Mar 2024 16:12:25 +0100 Subject: [PATCH] Update Dockerfile to use client and server --- Dockerfile | 32 +++++++++++++++++++------------- README.md | 10 +++++++++- server/package.json | 2 -- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 32979fd..0516b14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,25 @@ -FROM node:lts-alpine +# Stage 1: Build the React client app +FROM node:lts-alpine as client-builder -# Create app directory -WORKDIR /usr/src/app +WORKDIR /usr/src/client +COPY client/package*.json ./ +RUN npm ci --only=production +COPY client/ . +RUN npm run build -# Install app dependencies -# A wildcard is used to ensure both package.json AND package-lock.json are copied -# where available (npm@5+) -COPY package*.json ./ +# Stage 2: Build the Node server +FROM node:lts-alpine as server-builder -# RUN npm install -# If you are building your code for production -RUN npm ci --omit=dev +WORKDIR /usr/src/server +COPY server/package*.json ./ +RUN npm ci --only=production +COPY server/ . -# Bundle app source -COPY . . +# Copy the built React app from the client-builder stage +COPY --from=client-builder /usr/src/client/build ./public +# Expose the port that the server is running on EXPOSE 3000 -CMD [ "node", "server.js" ] + +# Specify the command to run the server +CMD ["node", "server.js"] \ No newline at end of file diff --git a/README.md b/README.md index 3fde399..b097402 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,18 @@ Some talking fruits -How to update the server: +## How to update the server: + ``` docker build . -t nonhumannonsense/council-of-foods:latest docker push nonhumannonsense/council-of-foods:latest ``` Then update the server, see server repo. + +## How to run the server + +``` +docker build . -t nonhumannonsense/council-of-foods:latest +docker push nonhumannonsense/council-of-foods:latest +``` diff --git a/server/package.json b/server/package.json index c64d437..191b2e9 100644 --- a/server/package.json +++ b/server/package.json @@ -4,8 +4,6 @@ "description": "", "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "node server.js", "dev": "nodemon server.js" }, "author": "",