-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-api.sh
More file actions
executable file
·66 lines (59 loc) · 2.21 KB
/
sync-api.sh
File metadata and controls
executable file
·66 lines (59 loc) · 2.21 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
#!/bin/bash
# 1. Get the values from terraform output
API_URL=$(terraform output -raw api_url)
GEMINI_URL=$(terraform output -raw gemini_service_url)
USER_POOL_ID=$(terraform output -raw user_pool_id)
CLIENT_ID=$(terraform output -raw client_id)
S3_BUCKET=$(terraform output -raw s3_bucket_name)
if [ -z "$API_URL" ] || [ "$API_URL" == "null" ]; then
echo "Error: Could not find outputs in terraform."
exit 1
fi
# 2. Update the API_BASE and GEMINI_API_URL constants in app.js
# Remove trailing slash from URLs if present
GEMINI_URL_CLEAN=${GEMINI_URL%/}
API_URL_CLEAN=${API_URL%/}
sed -i "s|const API_BASE = \".*\";|const API_BASE = \"$API_URL_CLEAN\";|" app.js
sed -i "s|const GEMINI_API_URL = \".*\";|const GEMINI_API_URL = \"$GEMINI_URL_CLEAN\";|" app.js
# 3. Update poolData in auth.js
sed -i "s|UserPoolId: '.*'|UserPoolId: '$USER_POOL_ID'|" auth.js
sed -i "s|ClientId: '.*'|ClientId: '$CLIENT_ID'|" auth.js
# 4. Handle Cognito Endpoint (PRODUCTION: undefined)
sed -i "s|endpoint: '.*'|endpoint: undefined|" auth.js
echo "✅ Frontend synchronized with Terraform outputs."
echo " - API_URL: $API_URL"
echo " - Gemini Service URL: $GEMINI_URL"
echo " - UserPool: $USER_POOL_ID"
echo " - ClientId: $CLIENT_ID"
echo " - S3 Bucket: $S3_BUCKET"
# 5. Sync to S3
if [ ! -z "$S3_BUCKET" ] && [ "$S3_BUCKET" != "null" ]; then
echo "🚀 Syncing files to S3..."
aws s3 sync . s3://$S3_BUCKET \
--profile capaciti \
--exclude ".git/*" \
--exclude ".venv/*" \
--exclude ".terraform/*" \
--exclude "*.tf" \
--exclude "*.tfstate*" \
--exclude "*.hcl" \
--exclude "*.zip" \
--exclude "venv/*" \
--exclude "__pycache__/*" \
--exclude "*.py" \
--exclude "requirements.txt" \
--exclude "gemini_build/*" \
--exclude "README.md" \
--exclude "sync-api.sh" \
--exclude "task.md" \
--exclude "node_modules/*" \
--exclude "FET_ATPs_Organized/*" \
--exclude "extracted_atp_data.json" \
--exclude "response.json" \
--exclude "terraform.tfvars" \
--exclude ".gitignore" \
--delete
echo "✅ S3 Sync Complete."
else
echo "⚠️ S3 Bucket not found, skipping sync."
fi