fix: Resolve backend logger permission errors
- Fix logger path to use relative path from backend directory - Add LOG_DIR environment variable support for custom log paths - Create logs directory with .gitkeep to ensure it exists - Add docker-entrypoint.sh to handle runtime permissions - Optimize Dockerfile to set proper permissions for nodejs user - Ensure logs directory is writable by the application 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Ensure logs directory exists with correct permissions
|
||||
if [ ! -d "/app/logs" ]; then
|
||||
mkdir -p /app/logs
|
||||
fi
|
||||
|
||||
# Start the application
|
||||
exec node src/app.js
|
||||
@@ -3,7 +3,7 @@ const DailyRotateFile = require('winston-daily-rotate-file');
|
||||
const path = require('path');
|
||||
const config = require('../config');
|
||||
|
||||
const logDir = path.join(__dirname, '../../../logs');
|
||||
const logDir = process.env.LOG_DIR || path.join(__dirname, '../../logs');
|
||||
|
||||
// Define log format
|
||||
const logFormat = winston.format.combine(
|
||||
|
||||
@@ -17,15 +17,18 @@ RUN npm ci --only=production
|
||||
# Copy application files
|
||||
COPY . .
|
||||
|
||||
# Create logs directory
|
||||
RUN mkdir -p logs
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nodejs -u 1001
|
||||
|
||||
# Change ownership
|
||||
RUN chown -R nodejs:nodejs /app
|
||||
# Create logs directory with proper permissions
|
||||
RUN mkdir -p logs && \
|
||||
chown -R nodejs:nodejs /app && \
|
||||
chmod 755 logs
|
||||
|
||||
# Copy and set permissions for entrypoint
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Switch to non-root user
|
||||
USER nodejs
|
||||
@@ -34,4 +37,4 @@ USER nodejs
|
||||
EXPOSE 3000
|
||||
|
||||
# Start the application
|
||||
CMD ["node", "src/app.js"]
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
@@ -0,0 +1,2 @@
|
||||
# This file ensures the logs directory is tracked in git
|
||||
# Actual log files are ignored by .gitignore
|
||||
Reference in New Issue
Block a user