build: add Docker entrypoint scripts for automated setup
- Add backend entrypoint with automated Prisma migrations and client regeneration - Add frontend entrypoint with dependency management - Update Dockerfiles to use entrypoint scripts - Ensures database schema stays in sync with Prisma Client after migrations
This commit is contained in:
@@ -15,8 +15,15 @@ RUN npm install
|
|||||||
# Copy application files
|
# Copy application files
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Copy and set permissions for entrypoint script
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start application
|
# Set entrypoint
|
||||||
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
|
|
||||||
|
# Default command (can be overridden)
|
||||||
CMD ["npm", "run", "dev"]
|
CMD ["npm", "run", "dev"]
|
||||||
|
|||||||
33
backend/docker-entrypoint.sh
Normal file
33
backend/docker-entrypoint.sh
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔧 Checking dependencies..."
|
||||||
|
|
||||||
|
# Install dependencies if node_modules doesn't exist or package.json changed
|
||||||
|
if [ ! -d "node_modules" ] || [ "package.json" -nt "node_modules" ]; then
|
||||||
|
echo "📦 Installing npm dependencies..."
|
||||||
|
npm install
|
||||||
|
else
|
||||||
|
echo "✅ Dependencies already installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate Prisma Client if not exists or schema changed
|
||||||
|
if [ ! -d "node_modules/.prisma/client" ] || [ "prisma/schema.prisma" -nt "node_modules/.prisma/client" ]; then
|
||||||
|
echo "🔨 Generating Prisma Client..."
|
||||||
|
npx prisma generate
|
||||||
|
else
|
||||||
|
echo "✅ Prisma Client already generated"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run pending database migrations
|
||||||
|
echo "🔄 Applying database migrations..."
|
||||||
|
npx prisma migrate deploy
|
||||||
|
|
||||||
|
# Regenerate Prisma Client after migrations to ensure sync
|
||||||
|
echo "🔨 Regenerating Prisma Client after migrations..."
|
||||||
|
npx prisma generate
|
||||||
|
|
||||||
|
echo "✅ Ready to start!"
|
||||||
|
|
||||||
|
# Execute the main command (passed as arguments to this script)
|
||||||
|
exec "$@"
|
||||||
@@ -11,8 +11,15 @@ RUN npm install
|
|||||||
# Copy project files
|
# Copy project files
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Copy and set permissions for entrypoint script
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
# Expose Vite dev server port
|
# Expose Vite dev server port
|
||||||
EXPOSE 5173
|
EXPOSE 5173
|
||||||
|
|
||||||
# Start dev server
|
# Set entrypoint
|
||||||
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
|
|
||||||
|
# Default command (can be overridden)
|
||||||
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
|
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
|
||||||
|
|||||||
17
frontend/docker-entrypoint.sh
Normal file
17
frontend/docker-entrypoint.sh
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔧 Checking dependencies..."
|
||||||
|
|
||||||
|
# Install dependencies if node_modules doesn't exist or package.json changed
|
||||||
|
if [ ! -d "node_modules" ] || [ "package.json" -nt "node_modules" ]; then
|
||||||
|
echo "📦 Installing npm dependencies..."
|
||||||
|
npm install
|
||||||
|
else
|
||||||
|
echo "✅ Dependencies already installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ Ready to start!"
|
||||||
|
|
||||||
|
# Execute the main command (passed as arguments to this script)
|
||||||
|
exec "$@"
|
||||||
Reference in New Issue
Block a user