From f9d3e736515e58212d89a3ebbf8b42b8e17b1697 Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 23 May 2025 16:19:22 +0200 Subject: [PATCH] build: Improve Docker dev setup, add nodemon config (#1145) * Updated the base image in `Dockerfile.dev` from `node:18-alpine` to `node:lts-alpine` to use more or less the same as for production docker build (where the client is build lts and server is 18... so yeah not really...) * Removed the `USER node` directive, to prevent permission issues as we hook the whole folder into the container. * Modified the `docker-compose-dev.yml` file to enhance the database healthcheck. The new healthcheck ensures not only postgres is ready but also the database is ready by running a sample query (`SELECT 1`) and adjusts the interval, retries, and start period for better reliability. * Added a `nodemon.json` configuration file to watch only relevant files (node_modules would be ignored but not files like the python venv) and avoid rapid successive restarts with the delay. --- Dockerfile.dev | 3 +-- docker-compose-dev.yml | 11 ++++++++--- server/nodemon.json | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 server/nodemon.json diff --git a/Dockerfile.dev b/Dockerfile.dev index d59e3cf3..6985fc57 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,8 +1,7 @@ -FROM node:18-alpine +FROM node:lts-alpine RUN apk -U upgrade \ && apk add bash build-base python3 xdg-utils --no-cache \ && npm install npm --global -USER node WORKDIR /app diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 3beb5685..2e4d08ce 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -109,10 +109,15 @@ services: - POSTGRES_DB=planka - POSTGRES_HOST_AUTH_METHOD=trust healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres -d planka"] - interval: 10s + test: + [ + "CMD-SHELL", + "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-planka} && psql -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-planka} -c 'SELECT 1'", + ] + interval: 3s timeout: 5s - retries: 5 + retries: 15 + start_period: 10s volumes: db-data: diff --git a/server/nodemon.json b/server/nodemon.json new file mode 100644 index 00000000..d552807c --- /dev/null +++ b/server/nodemon.json @@ -0,0 +1,15 @@ +{ + "watch": [ + "api/**/*.js", + "config/**/*.js", + "db/**/*.js", + "utils/**/*.js", + "app.js", + "constants.js" + ], + "ignore": ["node_modules", ".tmp", ".venv"], + "ext": "js,json", + "verbose": true, + "delay": 1000, + "legacyWatch": false +}