|
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 |
0 commit comments