diff --git a/.dockerignore b/.dockerignore index 9b495245..1735a828 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,6 @@ node_modules +dist +data Dockerfile* docker-compose* .dockerignore 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/packages/core/src/versionStack/versionStack.ts b/packages/core/src/versionStack/versionStack.ts index ab5fb746..259c7a84 100644 --- a/packages/core/src/versionStack/versionStack.ts +++ b/packages/core/src/versionStack/versionStack.ts @@ -58,7 +58,7 @@ export class VersionStackService { throw new Error('parent not found') } - const firstFile = files[0] + const firstFile = files.find((f) => f.id === fileIds[0]) const sortIndex = firstFile?.sortIndex || null const stack = await tx.asset.create({ diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh new file mode 100644 index 00000000..0d61b1b9 --- /dev/null +++ b/scripts/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +if [ "$(id -u)" = "0" ]; then + # 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 "$@" +else + # Run the CMD directly if already running as non-root + exec "$@" +fi