Skip to content

Commit

Permalink
fixed docker behaviour with pinohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenithGD committed Jan 31, 2025
1 parent a322f99 commit 60aa4c5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ PORT=...
API_URL=...
SECRET_KEY=SECRET
TURSO_DATABASE_URL=...
TURSO_AUTH_TOKEN=...
TURSO_AUTH_TOKEN=...
LOG_FILE=... # specify log file for production here (i.e. your container log file)
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
23 changes: 15 additions & 8 deletions api/config/logger.js
Original file line number Diff line number Diff line change
@@ -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'
},
Expand Down

0 comments on commit 60aa4c5

Please sign in to comment.