Skip to content

Commit 372c2b5

Browse files
committed
chore(build): update buildspec for Docker image build and push process
1 parent dbc3d0b commit 372c2b5

File tree

3 files changed

+73
-22
lines changed

3 files changed

+73
-22
lines changed

buildspec.yml

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
1-
# Prepare standalone build
2-
- echo "Preparing standalone build..."
3-
- echo "DEBUG - Checking what Next.js built..."
4-
- ls -la .next/
5-
- ls -la .next/standalone/ || echo "No standalone directory"
6-
- echo "DEBUG - Checking if static files exist..."
7-
- ls -la .next/static/ || echo "No static directory found"
8-
- echo "DEBUG - Copying static files to standalone..."
9-
- cp -r public .next/standalone/apps/app/ || echo "No public folder"
10-
- cp -r .next/static .next/standalone/apps/app/.next/ || echo "No .next/static directory"
11-
- echo "DEBUG - Final verification..."
12-
- ls -la .next/standalone/ || echo "Standalone empty"
13-
- echo "Looking for static files in standalone..."
14-
- find .next/standalone -type f -name "*.css" | head -5 || echo "No CSS files found"
15-
- find .next/standalone -type f -name "*.js" | head -5 || echo "No JS files found"
16-
- find .next/standalone -type f -name "*.ttf" | head -3 || echo "No font files found"
17-
- echo "Checking specific paths..."
18-
- ls -la .next/standalone/apps/app/.next/static/chunks/ || echo "No chunks directory"
19-
- ls -la .next/standalone/apps/app/.next/static/media/ || echo "No media directory"
20-
- ls -la .next/standalone/apps/app/public/ || echo "No public directory"
1+
version: 0.2
2+
3+
phases:
4+
pre_build:
5+
commands:
6+
- echo "Logging in to Amazon ECR..."
7+
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
8+
- REPOSITORY_URI=$ECR_REPOSITORY_URI
9+
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
10+
- IMAGE_TAG=${COMMIT_HASH:=latest}
11+
- echo "Installing Bun..."
12+
- curl -fsSL https://bun.sh/install | bash
13+
- export PATH="/root/.bun/bin:$PATH"
14+
- echo "Installing Turbo..."
15+
- bun add -g turbo
16+
17+
build:
18+
commands:
19+
# Validate environment variables
20+
- echo "Validating environment variables..."
21+
- '[ -n "$DATABASE_URL" ] || { echo "❌ DATABASE_URL is not set"; exit 1; }'
22+
- '[ -n "$BASE_URL" ] || { echo "❌ BASE_URL is not set"; exit 1; }'
23+
- '[ -n "$BETTER_AUTH_URL" ] || { echo "❌ BETTER_AUTH_URL is not set"; exit 1; }'
24+
- '[ -n "$TRUST_APP_URL" ] || { echo "❌ TRUST_APP_URL is not set"; exit 1; }'
25+
26+
- echo "Pruning workspace for @comp/api..."
27+
# Generate the pruned workspace in ./out
28+
- bunx turbo prune --scope=@comp/api --docker
29+
30+
- echo "Building Docker image..."
31+
# Build using the pruned context (./out)
32+
# The Dockerfile is located at ./out/full/apps/api/Dockerfile
33+
- docker build -f out/full/apps/api/Dockerfile -t $ECR_REPOSITORY_URI:$IMAGE_TAG out/
34+
- docker tag $ECR_REPOSITORY_URI:$IMAGE_TAG $ECR_REPOSITORY_URI:latest
35+
36+
post_build:
37+
commands:
38+
- echo "Pushing images to ECR..."
39+
- docker push $ECR_REPOSITORY_URI:$IMAGE_TAG
40+
- docker push $ECR_REPOSITORY_URI:latest
41+
- echo "Updating ECS service..."
42+
- aws ecs update-service --cluster $ECS_CLUSTER_NAME --service $ECS_SERVICE_NAME --force-new-deployment
43+
- 'printf "[{\"name\":\"%s-container\",\"imageUri\":\"%s\"}]" api $ECR_REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json'
44+
45+
cache:
46+
paths:
47+
- '/root/.bun/install/cache/**/*'
48+
# We can cache turborepo cache if we used it, but we are pruning.
49+
50+
artifacts:
51+
files:
52+
- imagedefinitions.json
53+
name: ${APP_NAME}-build

bun.lock

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@
328328
"typescript": "^5.8.3",
329329
},
330330
},
331+
"packages/db": {
332+
"name": "@trycompai/db",
333+
"version": "1.3.17",
334+
"dependencies": {
335+
"@prisma/client": "^6.13.0",
336+
"dotenv": "^16.4.5",
337+
"zod": "^4.1.12",
338+
},
339+
"devDependencies": {
340+
"@types/node": "^24.2.0",
341+
"prisma": "^6.13.0",
342+
"ts-node": "^10.9.2",
343+
"typescript": "^5.9.2",
344+
},
345+
},
331346
"packages/email": {
332347
"name": "@trycompai/email",
333348
"version": "1.0.0",
@@ -1966,7 +1981,7 @@
19661981

19671982
"@trycompai/analytics": ["@trycompai/analytics@workspace:packages/analytics"],
19681983

1969-
"@trycompai/db": ["@trycompai/db@1.3.17", "", { "dependencies": { "@prisma/client": "^6.13.0", "dotenv": "^16.4.5" } }, "sha512-vrKf+/YGdQhpP470xWhysL3RDL8v16pS90AafF718YcRI6mI/XUqlirNMS43+XtOksrc5CHITyBLLOd848bFDA=="],
1984+
"@trycompai/db": ["@trycompai/db@workspace:packages/db"],
19701985

19711986
"@trycompai/email": ["@trycompai/email@workspace:packages/email"],
19721987

@@ -5624,7 +5639,9 @@
56245639

56255640
"@trigger.dev/sdk/uuid": ["[email protected]", "", { "bin": { "uuid": "dist/bin/uuid" } }, "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA=="],
56265641

5627-
"@trycompai/db/dotenv": ["[email protected]", "", {}, "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ=="],
5642+
"@trycompai/db/dotenv": ["[email protected]", "", {}, "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow=="],
5643+
5644+
"@trycompai/db/zod": ["[email protected]", "", {}, "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ=="],
56285645

56295646
"@trycompai/email/resend": ["[email protected]", "", { "dependencies": { "@react-email/render": "1.1.2" } }, "sha512-R8eBOFQDO6dzRTDmaMEdpqrkmgSjPpVXt4nGfWsZdYOet0kqra0xgbvTES6HmCriZEXbmGk3e0DiGIaLFTFSHA=="],
56305647

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"workspaces": [
8686
"apps/*",
8787
"packages/analytics",
88+
"packages/db",
8889
"packages/email",
8990
"packages/integrations",
9091
"packages/kv",

0 commit comments

Comments
 (0)