From 857b60e1f5a357f48d00f1b66a4491e622ab269c Mon Sep 17 00:00:00 2001 From: elpatron Date: Wed, 1 Oct 2025 23:05:21 +0200 Subject: [PATCH] Fix: Use startup script to create .storage directories at runtime - Changed from bind mount to named volume for .storage - Added start.sh script that creates required directories before starting the app - This prevents ENOENT errors when initializing admin user --- Dockerfile | 12 ++++++------ docker-compose-prod.yml | 4 +++- start.sh | 11 +++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile index 3c72982..7449fd9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,14 +44,15 @@ COPY --from=base /app/src/server/routes ./src/server/routes COPY --from=base /app/src/server/rpc ./src/server/rpc COPY --from=base /app/src/server/lib ./src/server/lib COPY --from=base /app/tsconfig.server.json ./tsconfig.server.json - -# Create .storage directory and subdirectories -RUN mkdir -p /app/.storage/users /app/.storage/bookings /app/.storage/treatments /app/.storage/availability /app/.storage/cancellation-tokens +COPY start.sh ./start.sh # Create non-root user for security RUN addgroup -g 1001 -S nodejs RUN adduser -S nextjs -u 1001 +# Make start script executable +RUN chmod +x /app/start.sh + # Change ownership of the app directory RUN chown -R nextjs:nodejs /app USER nextjs @@ -63,6 +64,5 @@ EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })" || exit 1 -# Start the application with ts-node and dedicated tsconfig for NodeNext -# Start the precompiled server JS (kein ts-node im Runtime) -CMD ["node", "server-dist/index.js"] +# Start the application with startup script +CMD ["/app/start.sh"] diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index 48a6494..0c279c6 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -12,7 +12,7 @@ services: - NODE_ENV=production restart: unless-stopped volumes: - - ./.storage:/app/.storage + - storage-data:/app/.storage networks: - stargirlnails-network healthcheck: @@ -56,6 +56,8 @@ services: # Volumes für persistente Daten volumes: + storage-data: + driver: local certbot-certs: driver: local certbot-webroot: diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..62bd17d --- /dev/null +++ b/start.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# Create .storage directories if they don't exist +mkdir -p /app/.storage/users +mkdir -p /app/.storage/bookings +mkdir -p /app/.storage/treatments +mkdir -p /app/.storage/availability +mkdir -p /app/.storage/cancellation-tokens + +# Start the application +exec node server-dist/index.js