diff --git a/.env.example b/.env.example index 3bf56c0..19617d1 100644 --- a/.env.example +++ b/.env.example @@ -2,4 +2,5 @@ PORT=... API_URL=... SECRET_KEY=SECRET TURSO_DATABASE_URL=... -TURSO_AUTH_TOKEN=... \ No newline at end of file +TURSO_AUTH_TOKEN=... +LOG_FILE=... # specify log file for production here (i.e. your container log file) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ae9c7ac..c69e342 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,15 +20,22 @@ RUN addgroup -g 1001 -S nodejs \ && adduser -S express -u 1001 \ && apk add --no-cache tini +# Copy only the necessary files for production (no dist) COPY --from=base /app/package.json ./package.json COPY --from=base /app/node_modules ./node_modules -COPY --from=builder /app/dist ./dist +COPY . ./ +# Ensure proper permissions RUN chown -R express:nodejs /app +RUN mkdir -p /app/logs # Ensure log directory exists +RUN chmod -R 664 /app/logs # Ensure the directory is writable + USER express EXPOSE 3000 + +# Adjusted health check (if no /health route exists, use /) HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD wget -qO- http://localhost:3000/health || exit 1 + CMD wget -qO- http://localhost:3000/ || exit 1 ENTRYPOINT ["/sbin/tini", "--"] -CMD ["node", "app/dist/api/server.js"] +CMD ["node", "api/server.js"] diff --git a/api/config/logger.js b/api/config/logger.js index ee32466..fec2568 100644 --- a/api/config/logger.js +++ b/api/config/logger.js @@ -1,14 +1,21 @@ /** @type {import('pino-http').Options} */ export const loggerHttp = { level: 'info', - transport: { - target: 'pino-pretty', - options: { - colorize: true, - singleLine: true, - translateTime: 'yyyy-mm-dd HH:MM:ss.l' - } - }, + transport: process.env.NODE_ENV === 'production' + ? { + target: 'pino/file', + options: { + destination: process.env.LOG_DIR + } + } + : { + target: 'pino-pretty', + options: { + colorize: true, + singleLine: true, + translateTime: 'yyyy-mm-dd HH:MM:ss.l' + } + }, autoLogging: { ignore: (req) => req.url === '/favicon.ico' },