From aea4de17c4bcc2c602f835623580cd91658cb990 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Thu, 3 Sep 2026 17:01:18 +0700 Subject: [PATCH] refactor(docker): update health check and remove entrypoint script - Replaced the health check command in the Dockerfile to use a Node.js fetch call for improved reliability. - Removed the custom entrypoint script as it was deemed unnecessary, simplifying the Docker image. - Adjusted health check start period from 10s to 15s for better initialization timing. --- deploy/docker/cfdm/Dockerfile | 17 +++++------------ deploy/docker/cfdm/docker-entrypoint.sh | 15 --------------- docker-compose.yml | 6 ++---- 3 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 deploy/docker/cfdm/docker-entrypoint.sh diff --git a/deploy/docker/cfdm/Dockerfile b/deploy/docker/cfdm/Dockerfile index a7f4367..5ae9b89 100644 --- a/deploy/docker/cfdm/Dockerfile +++ b/deploy/docker/cfdm/Dockerfile @@ -29,31 +29,24 @@ RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \ && rm -rf /out/src /out/test /out/.turbo \ && rm -rf /out/node_modules/@cfdm/db/src /out/node_modules/@cfdm/db/scripts /out/node_modules/@cfdm/db/.turbo \ && rm -rf /out/node_modules/@cfdm/shared/src /out/node_modules/@cfdm/shared/.turbo \ - && find /out/node_modules/@cfdm -type f \( -name '*.d.ts' -o -name '*.map' -o -name 'tsconfig*.json' -o -name 'vitest.config.ts' -o -name 'drizzle.config.ts' \) -delete \ - && find /out/dist -type f \( -name '*.d.ts' -o -name 'tsconfig*.json' -o -name 'vitest.config.ts' -o -name 'drizzle.config.ts' \) -delete + && find /out/dist /out/node_modules/@cfdm -type f \( -name '*.d.ts' -o -name '*.map' -o -name 'tsconfig*.json' -o -name 'vitest.config.ts' -o -name 'drizzle.config.ts' \) -delete FROM ${BASE_NODE} AS runtime WORKDIR /app -RUN apk add --no-cache ca-certificates wget su-exec +RUN apk add --no-cache ca-certificates ARG VERSION=dev ARG GIT_SHA=unknown ARG BUILD_TIME= ENV NODE_ENV=production \ - NODE_OPTIONS=--enable-source-maps \ STATIC_DIR=/app/static \ DATABASE_URL=sqlite:/data/app.db \ SERVER_PORT=8080 \ APP_VERSION=${VERSION} \ GIT_SHA=${GIT_SHA} \ BUILD_TIME=${BUILD_TIME} -COPY --from=build --chown=node:node /out ./ -COPY deploy/docker/cfdm/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN chmod 755 /usr/local/bin/docker-entrypoint.sh \ - && mkdir -p /data \ - && chown node:node /data /app -ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +COPY --from=build /out ./ EXPOSE 8080 VOLUME ["/data"] HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ - CMD ["wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health"] -CMD ["node", "--max-old-space-size=384", "dist/server.js"] + CMD ["node", "-e", "fetch('http://127.0.0.1:8080/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"] +CMD ["node", "dist/server.js"] diff --git a/deploy/docker/cfdm/docker-entrypoint.sh b/deploy/docker/cfdm/docker-entrypoint.sh deleted file mode 100644 index 6270264..0000000 --- a/deploy/docker/cfdm/docker-entrypoint.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -set -eu - -mkdir -p /data - -if [ "$(id -u)" = "0" ]; then - chown -R node:node /data 2>/dev/null || true - chmod -R u+rwX /data 2>/dev/null || true - if su-exec node sh -c 'touch /data/.write-test && rm -f /data/.write-test'; then - exec su-exec node "$@" - fi - echo "cfdm: /data is not writable by user node after chown; starting as root" >&2 -fi - -exec "$@" diff --git a/docker-compose.yml b/docker-compose.yml index 907f316..4d6ca6a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,11 +19,9 @@ services: volumes: - ./data:/data restart: unless-stopped - init: true - mem_limit: 512m healthcheck: - test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health"] + test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8080/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"] interval: 30s timeout: 5s retries: 3 - start_period: 10s + start_period: 15s