Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sh text eol=lf
docker-entrypoint.sh text eol=lf
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

# Only install runtime deps (sqlite, curl for healthcheck)
RUN apk add --no-cache sqlite-libs curl && \
# Only install runtime deps (sqlite, curl for healthcheck, su-exec for entrypoint)
RUN apk add --no-cache sqlite-libs curl su-exec && \
addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs

Expand All @@ -54,11 +54,14 @@ COPY --from=builder /app/src/lib/schema_features.sql ./src/lib/schema_features.s
# Data directory with proper permissions
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data

# Copy entrypoint
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

ENV DATA_DIR="/app/data"
VOLUME ["/app/data"]

# Switch to non-root user
USER nextjs
# Run as root initially so entrypoint can fix volume permissions, then drops to nextjs

EXPOSE 3000
ENV PORT=3000
Expand All @@ -67,4 +70,4 @@ ENV HOSTNAME="0.0.0.0"
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
CMD curl -f http://localhost:3000/api/health || exit 1

CMD ["node", "server.js"]
ENTRYPOINT ["/app/docker-entrypoint.sh"]
12 changes: 12 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Ensure data directory exists and is writable
mkdir -p /app/data

# Fix ownership if running as root (e.g., when host volume is root-owned)
if [ "$(id -u)" = "0" ]; then
chown -R nextjs:nodejs /app/data
exec su-exec nextjs node server.js
else
exec node server.js
fi
Loading