- Changed aws-region from us-east-2 to us-east-1 for correct deployment - Updated S3 website URL to use us-east-1 endpoint - Added note about CloudFlare proxy for production serving
70 lines
2.2 KiB
YAML
70 lines
2.2 KiB
YAML
# Workflow for building and deploying a Next.js site to AWS S3
|
|
name: Deploy Next.js site to S3
|
|
|
|
on:
|
|
# Runs on pushes targeting the default branch
|
|
push:
|
|
branches: ["master"]
|
|
|
|
# Allows you to run this workflow manually from the Actions tab
|
|
workflow_dispatch:
|
|
|
|
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
|
concurrency:
|
|
group: "s3-deployment"
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
id-token: write
|
|
contents: read
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "20"
|
|
cache: 'npm'
|
|
|
|
- name: Create .env.local file
|
|
run: |
|
|
echo "YOUTUBE_API_KEY=${{ secrets.YOUTUBE_API_KEY }}" > .env.local
|
|
echo "S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}" >> .env.local
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Restore Next.js cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
.next/cache
|
|
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
|
|
|
|
- name: Build Next.js site
|
|
env:
|
|
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
|
|
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
|
|
run: npm run build:static
|
|
|
|
- name: Configure AWS credentials
|
|
uses: aws-actions/configure-aws-credentials@v4
|
|
with:
|
|
role-to-assume: ${{ secrets.CC_OIDC_ROLE }}
|
|
aws-region: us-east-1
|
|
|
|
- name: Deploy to S3
|
|
run: |
|
|
aws s3 sync out/ s3://${{ secrets.S3_BUCKET_NAME }} --delete --no-cli-pager
|
|
|
|
- name: Output deployment URL
|
|
run: |
|
|
echo "🎉 Deployment successful!"
|
|
echo "S3 website URL: http://${{ secrets.S3_BUCKET_NAME }}.s3-website-us-east-1.amazonaws.com"
|
|
echo "Note: Site will be served through CloudFlare proxy for production"
|