From e4a20d1f54469d949bdc257183c7aaf3712e0c0d Mon Sep 17 00:00:00 2001 From: David Roe Date: Fri, 21 Jun 2024 10:49:17 -0700 Subject: [PATCH 1/2] Refactor docker Use local checkout instead of pulling from git during build Rearrange yarn installs and package.json copies to make more efficent docker layers. Separate the node module installs into their own layers. They're less likely to change vs the rest of the node code. This means multiple builds that don't change the dependencies don't need to reinstall the modules Don't use nodemon inside the docker container It doesn't really make sense since the files don't change in a built container This also resolves a fun issue I had with lots of attachments causing the container to run out of inotify watches --- Dockerfile | 14 ++++++-------- docker_start.sh | 2 +- mailserver/package.json | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index f454d26..1bb9fbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,20 +10,18 @@ RUN apt-get update && \ # Install yarn globally RUN npm install -g yarn -# Clone the repository -RUN git clone https://github.com/hppanpaliya/React-TrashMail +# Install pm2 globally +RUN npm install -g pm2 -# Install dependencies for the React project +# Copy in package.json files and run install to allow docker to cache themc +COPY react/package.json /React-TrashMail/react/ WORKDIR /React-TrashMail/react RUN yarn - - -# Install dependencies for the mailserver +COPY mailserver/package.json /React-TrashMail/mailserver/ WORKDIR /React-TrashMail/mailserver RUN yarn -# Install pm2 globally -RUN npm install -g pm2 +COPY . /React-TrashMail # Define mountable volume VOLUME ["/React-TrashMail/mailserver/attachments"] diff --git a/docker_start.sh b/docker_start.sh index 267cb88..83ca156 100644 --- a/docker_start.sh +++ b/docker_start.sh @@ -25,4 +25,4 @@ fi # Start the application cd /React-TrashMail/mailserver -pm2-runtime start yarn -- start +pm2-runtime start yarn -- start:docker diff --git a/mailserver/package.json b/mailserver/package.json index 6f916b5..13ae4fc 100644 --- a/mailserver/package.json +++ b/mailserver/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "start": "nodemon server.js", + "start:docker": "node server.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], From 08593319ea7b4ec745d44c8ee79dcc7e922426bf Mon Sep 17 00:00:00 2001 From: David Roe Date: Fri, 21 Jun 2024 11:20:30 -0700 Subject: [PATCH 2/2] Set pm2_home --- docker_start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker_start.sh b/docker_start.sh index 83ca156..499af46 100644 --- a/docker_start.sh +++ b/docker_start.sh @@ -25,4 +25,4 @@ fi # Start the application cd /React-TrashMail/mailserver -pm2-runtime start yarn -- start:docker +PM2_HOME=/React-Trashmail/mailserver pm2-runtime start yarn -- start:docker