Skip to content

feat: add CloudFront #14

feat: add CloudFront

feat: add CloudFront #14

Workflow file for this run

name: Deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
AWS_REGION: eu-west-3
ORIGIN_BUCKET_NAME: twitch-live-17102024-my-web-site-origin
ROLE_ARN: arn:aws:iam::448878779811:role/twitch-live-17102024-my-web-site
ROLE_SESSON_NAME: github-ipppontech-my-web-site-to-aws-via-oidc
# Permission can be added at job level or workflow level
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
terraform-10-boostrap:
runs-on: ubuntu-latest
defaults:
run:
working-directory: infrastructure/10_bootstrap
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.ROLE_ARN }}
role-session-name: ${{ env.ROLE_SESSION_NAME }}
aws-region: ${{ env.AWS_REGION }}
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.9.7"
terraform_wrapper: false
- run: terraform fmt -check -recursive
- run: terraform init -backend=false
- run: terraform validate
- run: terraform init
- run: terraform plan -out=tfplan.out
- run: terraform apply -input=false tfplan.out
terraform-20-cloudfront:
runs-on: ubuntu-latest
defaults:
run:
working-directory: infrastructure/20_cloudfront
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.ROLE_ARN }}
role-session-name: ${{ env.ROLE_SESSION_NAME }}
aws-region: ${{ env.AWS_REGION }}
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.9.7"
terraform_wrapper: false
- run: terraform fmt -check -recursive
- run: terraform init -backend=false
- run: terraform validate
- run: terraform init
- run: terraform plan -out=tfplan.out
- run: terraform apply -input=false tfplan.out
build:
needs:
- terraform-10-boostrap
- terraform-20-cloudfront
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.ROLE_ARN }}
role-session-name: ${{ env.ROLE_SESSION_NAME }}
aws-region: ${{ env.AWS_REGION }}
- name: Use Node.js LTS
uses: actions/setup-node@v4
with:
cache: 'npm'
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
- uses: unfor19/install-aws-cli-action@v1
with:
version: 2
verbose: false
- name: build
run: |
npm ci
npm run build
- name: clean S3 origin bucket
run: |
aws s3api delete-objects \
--bucket ${{ env.ORIGIN_BUCKET_NAME }} \
--delete "$(aws s3api list-object-versions \
--bucket ${{ env.ORIGIN_BUCKET_NAME }} \
--output=json \
--query='{Objects: Versions[].{Key:Key,VersionId:VersionId}}')"
- name: copy dist folder to S3
run: |
aws s3 cp --recursive dist s3://${{ env.ORIGIN_BUCKET_NAME }}/