From 965ca36525a913c660b7180f0b8f72ed99b50d0a Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Mon, 29 Jan 2024 18:21:15 +0800 Subject: [PATCH] use pm2 to guard and monitor the web service in docker file (#2238) --- web/Dockerfile | 5 +++++ web/docker/entrypoint.sh | 2 +- web/docker/pm2.json | 21 ++++++++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/web/Dockerfile b/web/Dockerfile index 7c3117bcba..18cd3331ed 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -40,12 +40,17 @@ ENV TZ UTC RUN ln -s /usr/share/zoneinfo/${TZ} /etc/localtime \ && echo ${TZ} > /etc/timezone +# global runtime packages +RUN yarn global add pm2 \ + && yarn cache clean + WORKDIR /app/web COPY --from=builder /app/web/public ./public COPY --from=builder /app/web/.next/standalone ./ COPY --from=builder /app/web/.next/static ./.next/static +COPY docker/pm2.json ./pm2.json COPY docker/entrypoint.sh ./entrypoint.sh ARG COMMIT_SHA diff --git a/web/docker/entrypoint.sh b/web/docker/entrypoint.sh index 393b03fdb2..4f8a977cf6 100755 --- a/web/docker/entrypoint.sh +++ b/web/docker/entrypoint.sh @@ -10,4 +10,4 @@ export NEXT_PUBLIC_PUBLIC_API_PREFIX=${APP_API_URL}/api export NEXT_PUBLIC_SENTRY_DSN=${SENTRY_DSN} export NEXT_PUBLIC_SITE_ABOUT=${SITE_ABOUT} -node ./server.js +pm2 start ./pm2.json --no-daemon diff --git a/web/docker/pm2.json b/web/docker/pm2.json index 7929a8315d..85e5171203 100644 --- a/web/docker/pm2.json +++ b/web/docker/pm2.json @@ -1,12 +1,11 @@ { - "apps": [ - { - "name": "WebApp", - "exec_mode": "cluster", - "instances": 1, - "script": "./node_modules/next/dist/bin/next", - "cwd": "/app/web", - "args": "start" - } - ] - } + "apps": [ + { + "name": "dify-web", + "script": "/app/web/server.js", + "cwd": "/app/web", + "exec_mode": "cluster", + "instances": 2 + } + ] +}