Skip to content

Commit 22fb0eb

Browse files
authored
fix(api): update buildspec and Dockerfile to prepare workspace packag… (#1775)
* fix(api): update buildspec and Dockerfile to prepare workspace packages for Docker * chore: deslop * revert(api): update buildspec and Dockerfile to streamline Docker build process
1 parent 70ff9c7 commit 22fb0eb

File tree

3 files changed

+15
-51
lines changed

3 files changed

+15
-51
lines changed

apps/api/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ RUN curl -fsSL https://bun.sh/install | bash \
1515
&& export PATH="/root/.bun/bin:$PATH" \
1616
&& bun install --production --ignore-scripts || true
1717

18-
# Copy pre-built workspace packages (must be before copying app contents)
1918
COPY node_modules/@trycompai ./node_modules/@trycompai
19+
COPY node_modules/@prisma ./node_modules/@prisma
20+
COPY node_modules/.prisma ./node_modules/.prisma
2021

21-
# Now copy the pre-built app contents (dist/, prisma/, etc.)
2222
COPY . .
2323

24-
# Generate Prisma client inside the image (ensures runtime client matches installed deps)
25-
RUN npx prisma generate
26-
2724
# Set environment variables
2825
ENV NODE_ENV=production
2926
ENV PORT=3333

apps/api/buildspec.yml

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,67 +32,51 @@ phases:
3232
- echo "Installing API dependencies only..."
3333
- bun install --filter=@comp/api --frozen-lockfile || bun install --filter=@comp/api --ignore-scripts || bun install --ignore-scripts
3434

35-
# Build email package (required dependency for API)
3635
- echo "Building @trycompai/email package..."
3736
- cd packages/email
3837
- bun run build
3938
- cd ../..
4039

41-
# Build NestJS application (prebuild automatically handles Prisma)
4240
- echo "Building NestJS application..."
4341
- echo "APP_NAME is set to $APP_NAME"
4442
- echo "Current directory $(pwd)"
4543
- echo "Available apps $(ls -la apps/)"
4644
- cd apps/api
4745
- echo "Changed to $(pwd)"
48-
- echo "Running build (includes automatic prebuild db:generate)..."
4946
- bun run build
5047

51-
# Verify build output exists
5248
- echo "Checking build output..."
5349
- ls -la dist/
5450
- ls -la dist/src/
5551
- '[ -f "dist/src/main.js" ] || { echo "❌ main.js not found in dist/src"; exit 1; }'
5652

57-
# Create self-contained bundle for Docker (stay in apps/api)
58-
- echo "Creating self-contained bundle..."
5953
- mkdir -p ../docker-build
60-
61-
# Copy built application (preserves NestJS structure)
62-
- echo "Copying built application..."
6354
- cp -r dist/* ../docker-build/
64-
65-
# Copy prisma folder (needed for runtime imports)
66-
- echo "Copying prisma folder..."
6755
- cp -r prisma ../docker-build/
6856

69-
# Verify files were copied correctly
7057
- echo "Verifying copied files..."
7158
- ls -la ../docker-build/
7259
- ls -la ../docker-build/src/
7360
- '[ -f "../docker-build/src/main.js" ] || { echo "❌ main.js not found in docker-build/src"; exit 1; }'
7461

75-
# Copy entire node_modules for runtime (includes @trycompai/db from npm)
76-
- echo "Skipping host node_modules copy; Dockerfile installs prod deps inside image"
77-
78-
# Copy built workspace packages (needed for runtime)
79-
# Only copy packages that are actually imported at runtime
80-
# Email package is already bundled, so only need its dist
81-
- echo "Copying built workspace packages..."
8262
- mkdir -p ../docker-build/node_modules/@trycompai
83-
# Email package - copy dist and package.json (needed at runtime)
8463
- mkdir -p ../docker-build/node_modules/@trycompai/email
8564
- cp -r ../../packages/email/dist ../docker-build/node_modules/@trycompai/email/
8665
- cp ../../packages/email/package.json ../docker-build/node_modules/@trycompai/email/
66+
- mkdir -p ../docker-build/node_modules/@trycompai/ui
67+
- cp -r ../../packages/ui/dist ../docker-build/node_modules/@trycompai/ui/
68+
- cp ../../packages/ui/package.json ../docker-build/node_modules/@trycompai/ui/
69+
- mkdir -p ../docker-build/node_modules/@trycompai/utils
70+
- cp -r ../../packages/utils/src ../docker-build/node_modules/@trycompai/utils/
71+
- cp ../../packages/utils/package.json ../docker-build/node_modules/@trycompai/utils/
72+
73+
- cp -r ../../node_modules/@prisma ../docker-build/node_modules/@prisma
74+
- cp -r ../../node_modules/.prisma ../docker-build/node_modules/.prisma
8775

88-
# Copy Dockerfile
89-
- echo "Copying Dockerfile..."
9076
- cp Dockerfile ../docker-build/
91-
- echo "Copying package manifests for image install..."
9277
- cp package.json ../docker-build/
9378
- cp ../../bun.lock ../docker-build/ || true
9479

95-
# Build Docker image
9680
- echo "Building Docker image..."
9781
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t $ECR_REPOSITORY_URI:$IMAGE_TAG ../docker-build/
9882
- docker tag $ECR_REPOSITORY_URI:$IMAGE_TAG $ECR_REPOSITORY_URI:latest

bun.lock

Lines changed: 4 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)