Skip to content

Commit 32f9303

Browse files
should prevent a permission issue with /data/ when deploying
1 parent 028aaba commit 32f9303

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ FROM node:22-alpine AS production
4242

4343
WORKDIR /app
4444

45-
# Create non-root user for security
45+
# Create non-root user for security and install su-exec for entrypoint
4646
RUN addgroup -g 1001 -S nodejs && \
47-
adduser -S nodejs -u 1001
47+
adduser -S nodejs -u 1001 && \
48+
apk add --no-cache su-exec
4849

4950
# Copy backend package files
5051
COPY backend/package.json ./
@@ -62,8 +63,9 @@ COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
6263
# Create data directory for SQLite databases
6364
RUN mkdir -p /app/data && chown -R nodejs:nodejs /app/data
6465

65-
# Switch to non-root user
66-
USER nodejs
66+
# Copy entrypoint script
67+
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
68+
RUN chmod +x /app/docker-entrypoint.sh
6769

6870
# Expose port
6971
EXPOSE 3000
@@ -76,5 +78,6 @@ ENV PORT=3000
7678
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
7779
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
7880

79-
# Start the server
81+
# Start via entrypoint (runs as root to fix permissions, then drops to nodejs)
82+
ENTRYPOINT ["/app/docker-entrypoint.sh"]
8083
CMD ["node", "dist/index.js"]

docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Ensure /app/data is writable by the nodejs user (uid 1001)
5+
# This handles the case where a volume is mounted with root ownership
6+
chown -R nodejs:nodejs /app/data 2>/dev/null || true
7+
8+
# Drop privileges and run the command as the nodejs user
9+
exec su-exec nodejs "$@"

0 commit comments

Comments
 (0)