-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (50 loc) · 1.62 KB
/
Dockerfile
File metadata and controls
66 lines (50 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
FROM node:20-alpine
# Install pnpm and build dependencies for native modules
RUN apk add --no-cache python3 make g++ postgresql-client wget && \
npm install -g pnpm
# Set working directory
WORKDIR /app
# Copy package files for better Docker layer caching
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY turbo.json ./
# Copy package.json files for each workspace
COPY packages/typescript-config/package.json ./packages/typescript-config/
COPY packages/eslint-config/package.json ./packages/eslint-config/
COPY apps/api/package.json ./apps/api/
# Install dependencies (with fallback for optional deps)
RUN pnpm install --no-frozen-lockfile
# Copy the rest of the source code
COPY . .
# Generate Prisma client and prepare database
WORKDIR /app/apps/api
RUN npx prisma generate
# Build the API only
WORKDIR /app
RUN pnpm build --filter=api
# Create startup script for database initialization
RUN cat > /app/start.sh << 'EOF'
#!/bin/sh
set -e
echo "=== DesterLib Container Startup ==="
echo "Waiting for database to be ready..."
until pg_isready -h ${POSTGRES_HOST:-postgres} -p ${POSTGRES_PORT:-5432} -U ${POSTGRES_USER:-postgres}; do
echo "Database is unavailable - sleeping"
sleep 2
done
echo "Database is ready!"
# Push database schema
cd /app/apps/api
echo "Running Prisma database push..."
npx prisma db push --accept-data-loss
# Start the application
cd /app/apps/api
echo "Starting application..."
echo "Current working directory: $(pwd)"
echo "Starting DesterLib API server on port ${PORT:-3001}..."
npm start
EOF
RUN chmod +x /app/start.sh
# Expose port
EXPOSE 3001
# Default command (production)
CMD ["/app/start.sh"]