#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" BUCKET="rapport-admin" DISTRIBUTION_ID="E1S7BD7JARZ1BJ" export AWS_PROFILE="stratawiztech" export AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-ap-south-1}" REGION="$AWS_DEFAULT_REGION" if ! command -v aws >/dev/null 2>&1; then echo "AWS CLI is required. Install it and configure credentials, then run this script again." exit 1 fi echo "Building (VITE_API_MODE=production)..." VITE_API_MODE=production npm run build if [[ ! -f dist/index.html ]]; then echo "Build did not produce dist/index.html." exit 1 fi echo "Uploading hashed assets to s3://${BUCKET}/assets ..." aws s3 sync dist/assets "s3://${BUCKET}/assets" \ --region "$REGION" \ --delete \ --cache-control "public, max-age=31536000, immutable" echo "Uploading other static files..." aws s3 sync dist "s3://${BUCKET}" \ --region "$REGION" \ --delete \ --exclude "index.html" \ --exclude "assets/*" \ --cache-control "public, max-age=3600" echo "Uploading index.html..." aws s3 cp dist/index.html "s3://${BUCKET}/index.html" \ --region "$REGION" \ --cache-control "no-cache, no-store, must-revalidate" \ --content-type "text/html; charset=utf-8" echo "Invalidating CloudFront ${DISTRIBUTION_ID}..." INVALIDATION_ID="$(aws cloudfront create-invalidation \ --distribution-id "$DISTRIBUTION_ID" \ --paths "/*" \ --query 'Invalidation.Id' \ --output text)" echo "Deployed to s3://${BUCKET}. CloudFront invalidation: ${INVALIDATION_ID}"