File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ RUN npm ci --ignore-scripts
1313# Copy source code (excluding server directory)
1414COPY . .
1515
16+ # Accept backend URL as build argument
17+ ARG VITE_API_BASE_URL
18+ ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
19+
1620# Build the frontend
1721RUN npm run build
1822
Original file line number Diff line number Diff line change @@ -12,10 +12,24 @@ steps:
1212 - ' ./server'
1313 id : ' build-backend-image'
1414
15- # Build the frontend container image
15+ # Get backend URL for frontend build
16+ - name : ' gcr.io/google.com/cloudsdktool/cloud-sdk'
17+ entrypoint : ' bash'
18+ args :
19+ - ' -c'
20+ - |
21+ # Try to get existing backend URL, fallback to default
22+ BACKEND_URL=$$(gcloud run services describe craftscape-backend --region us-central1 --format="value(status.url)" 2>/dev/null || echo "https://craftscape-backend-998275462099.us-central1.run.app")
23+ echo "$$BACKEND_URL" > /workspace/backend_url.txt
24+ echo "Backend URL for frontend: $$BACKEND_URL"
25+ id : ' get-backend-url'
26+
27+ # Build the frontend container image with backend URL
1628 - name : ' gcr.io/cloud-builders/docker'
1729 args :
1830 - ' build'
31+ - ' --build-arg'
32+ - ' VITE_API_BASE_URL=$$(cat /workspace/backend_url.txt)'
1933 - ' -t'
2034 - ' gcr.io/$PROJECT_ID/craftscape-frontend:$COMMIT_SHA'
2135 - ' -t'
2438 - ' Dockerfile'
2539 - ' .'
2640 id : ' build-frontend-image'
41+ waitFor : ['get-backend-url']
2742
2843 # Push the backend container image to Container Registry
2944 - name : ' gcr.io/cloud-builders/docker'
Original file line number Diff line number Diff line change @@ -36,12 +36,24 @@ gcloud services enable run.googleapis.com
3636gcloud services enable containerregistry.googleapis.com
3737gcloud services enable cloudbuild.googleapis.com
3838
39+ # Get backend URL
40+ Write-Host " "
41+ Write-Host " Getting backend service URL..." - ForegroundColor Yellow
42+ $BACKEND_URL = gcloud run services describe craftscape- backend -- region $REGION -- format= " value(status.url)" 2> $null
43+
44+ if ([string ]::IsNullOrEmpty($BACKEND_URL )) {
45+ Write-Host " ⚠ Backend service not found. Using default URL." - ForegroundColor Yellow
46+ $BACKEND_URL = " https://craftscape-backend-998275462099.us-central1.run.app"
47+ }
48+
49+ Write-Host " Backend URL: $BACKEND_URL " - ForegroundColor Cyan
50+
3951# Build the Docker image
4052Write-Host " "
4153Write-Host " Building Docker image..." - ForegroundColor Yellow
4254Write-Host " Image: $IMAGE_NAME " - ForegroundColor Cyan
4355
44- docker build - t $IMAGE_NAME .
56+ docker build - t $IMAGE_NAME -- build-arg VITE_API_BASE_URL = $BACKEND_URL .
4557
4658if ($LASTEXITCODE -ne 0 ) {
4759 Write-Host " ✗ Docker build failed!" - ForegroundColor Red
You can’t perform that action at this time.
0 commit comments