diff --git a/Dockerfile b/Dockerfile index 1130e2fc..4d93fdd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,6 +47,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ socat \ ca-certificates \ bubblewrap \ + gosu \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -69,5 +70,12 @@ COPY --chown=bun:bun --from=builder /app/prisma.config.ts.prod ./prisma.config.t # Expose port (Bun Hono defaults to 3000) EXPOSE 3000 +# Switch back to root at the end so the container runs the entrypoint as root +USER root +COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +ENTRYPOINT ["docker-entrypoint.sh"] + # Default command: run migrations and start API server CMD ["sh", "-c", "bun prisma migrate deploy && bun index.js"] diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh new file mode 100644 index 00000000..10ae2ac6 --- /dev/null +++ b/scripts/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +# Check if /app/data exists and is not owned by the bun user (UID 1000) +if [ -d "/app/data" ]; then + if [ "$(stat -c '%u' /app/data)" != "1000" ]; then + echo "Correcting permissions on /app/data..." + chown -R bun:bun /app/data + fi +fi + +# Run the CMD as the bun user +exec gosu bun "$@"