Add trailing slash back to URLs #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Frontend to S3 | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: ["main"] | |
| paths: | |
| - "src/application/frontend/**" | |
| - ".github/workflows/frontend-deploy.yaml" | |
| env: | |
| AWS_REGION: "us-east-1" | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| build-and-deploy: | |
| name: Build and Deploy Frontend | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: src/application/frontend/package-lock.json | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v3 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
| role-session-name: ${{ github.run_id }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Clean previous builds | |
| working-directory: src/application/frontend | |
| run: | | |
| echo "Cleaning previous build artifacts..." | |
| rm -rf .next out node_modules/.cache | |
| echo "Clean complete" | |
| - name: Install dependencies | |
| working-directory: src/application/frontend | |
| run: | | |
| echo "Installing dependencies with clean install..." | |
| npm ci | |
| echo "Dependencies installed" | |
| - name: Build Next.js application | |
| working-directory: src/application/frontend | |
| env: | |
| NEXT_PUBLIC_API_BASE_URL: ${{ secrets.NEXT_PUBLIC_API_BASE_URL }} | |
| NODE_ENV: production | |
| run: | | |
| echo "Building frontend with API base URL: $NEXT_PUBLIC_API_BASE_URL" | |
| echo "Node environment: $NODE_ENV" | |
| npm run build | |
| echo "Build complete" | |
| # Verify build output | |
| if [ ! -d "out" ]; then | |
| echo "Error: 'out' directory not found after build" | |
| exit 1 | |
| fi | |
| echo "Build output contents:" | |
| ls -la out/ | |
| # Check for critical files | |
| if [ ! -f "out/index.html" ]; then | |
| echo "Error: index.html not found in build output" | |
| exit 1 | |
| fi | |
| echo "Build verification complete" | |
| - name: Deploy to S3 | |
| working-directory: src/application/frontend | |
| env: | |
| BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} | |
| run: | | |
| echo "Deploying to S3 bucket: $BUCKET_NAME" | |
| echo "Step 1: Syncing static assets with long cache..." | |
| # Sync static assets (_next/static/*) with long cache | |
| aws s3 sync out/ s3://$BUCKET_NAME/ \ | |
| --delete \ | |
| --cache-control "public, max-age=31536000, immutable" \ | |
| --exclude "*.html" \ | |
| --exclude "*.json" \ | |
| --exclude "*.txt" \ | |
| --exclude "*.xml" | |
| echo "Static assets synced" | |
| echo "Step 2: Syncing HTML and metadata files with short cache..." | |
| # Sync HTML, JSON, and text files with short cache for SPA routing | |
| aws s3 sync out/ s3://$BUCKET_NAME/ \ | |
| --cache-control "public, max-age=0, must-revalidate" \ | |
| --exclude "*" \ | |
| --include "*.html" \ | |
| --include "*.json" \ | |
| --include "*.txt" \ | |
| --include "*.xml" | |
| echo "HTML and metadata files synced" | |
| echo "Deployment to S3 complete!" | |
| - name: Invalidate CloudFront Cache | |
| env: | |
| DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} | |
| run: | | |
| echo "Invalidating CloudFront cache for distribution: $DISTRIBUTION_ID" | |
| INVALIDATION_OUTPUT=$(aws cloudfront create-invalidation \ | |
| --distribution-id $DISTRIBUTION_ID \ | |
| --paths "/*" \ | |
| --output json) | |
| INVALIDATION_ID=$(echo $INVALIDATION_OUTPUT | jq -r '.Invalidation.Id') | |
| echo "Invalidation ID: $INVALIDATION_ID" | |
| echo " Cache invalidation initiated!" | |
| echo "Note: Invalidation typically takes 1-5 minutes to complete" |