-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial updates for deploying UI into an s3 bucket. Will need further changes to support with github actions
- Loading branch information
Showing
12 changed files
with
196 additions
and
349 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Deploy Angular App to S3 and CloudFront | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # Adjust to your deployment branch | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' # Adjust as needed | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build Angular App | ||
run: npm run build --prod | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: "ca-central-1" # Adjust to match your AWS region | ||
|
||
# this will require the bucket to exist | ||
# so terraform step will need to run first | ||
- name: Sync files to S3 | ||
run: | | ||
aws s3 sync ./dist/your-angular-app s3://wfprev_site_bucket \ | ||
--delete \ | ||
--cache-control max-age=31536000,public \ | ||
--exclude index.html | ||
aws s3 cp ./dist/your-angular-app/index.html s3://wfprev_site_bucket/index.html \ | ||
--cache-control max-age=0,no-cache,no-store,must-revalidate | ||
- name: Invalidate CloudFront Cache | ||
run: | | ||
aws cloudfront create-invalidation \ | ||
--distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \ | ||
--paths "/*" | ||
# see distribution ID section in terraform scripts | ||
# Like the sync, this means we need to run terraform first, then | ||
# trigger this action with the returned distribution ID |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# CloudFront Origin Access Identity (OAI) for secure access to S3 | ||
resource "aws_cloudfront_origin_access_identity"."oai" { | ||
comment = "OAI for wfprev UI" | ||
} | ||
|
||
# CloudFront Distribution | ||
resource "aws_cloudfront_distribution" "wfprev_app_distribution" { | ||
origin { | ||
domain_name = aws_s3_bucket.wfprev_site_bucket.bucket_regional_domain_name | ||
origin_id = "S3-${aws_s3_bucket.wfprev_site_bucket.id}" | ||
|
||
s3_origin_config { | ||
origin_access_identity = aws_cloudfront_origin_access_identity.oai.cloudfront_access_identity_path | ||
} | ||
} | ||
|
||
enabled = true | ||
is_ipv6_enabled = true | ||
default_root_object = "index.html" | ||
|
||
# Configure cache behaviors | ||
default_cache_behavior { | ||
allowed_methods = ["GET", "HEAD", "OPTIONS"] | ||
cached_methods = ["GET", "HEAD"] | ||
target_origin_id = "S3-${aws_s3_bucket.wfprev_site_bucket.id}" | ||
viewer_protocol_policy = "redirect-to-https" | ||
|
||
forwarded_values { | ||
query_string = false | ||
|
||
cookies { | ||
forward = "none" | ||
} | ||
} | ||
|
||
min_ttl = 0 | ||
default_ttl = 86400 | ||
max_ttl = 31536000 | ||
} | ||
|
||
# Viewer Certificate | ||
viewer_certificate { | ||
cloudfront_default_certificate = true | ||
} | ||
|
||
restrictions { | ||
geo_restriction { | ||
restriction_type = "none" | ||
} | ||
} | ||
} | ||
|
||
output "cloudfront_distribution_id" { | ||
value = aws_cloudfront_distribution.wfprev_app_distribution.id | ||
} |
Oops, something went wrong.