Skip to content

Commit 5c4f8b2

Browse files
committed
add preview action + cloudfront distro
1 parent 022a747 commit 5c4f8b2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.github/workflows/preview.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Create PR Preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 15
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Deploy Preview
16+
uses: LocalStack/setup-localstack/preview@main
17+
with:
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }}
20+
preview-cmd: |
21+
make build
22+
make bootstrap
23+
make deploy
24+
make prepare-frontend-local
25+
make build-frontend
26+
make bootstrap-frontend
27+
make deploy-frontend
28+
distributionId=$(awslocal cloudfront list-distributions | jq -r '.DistributionList.Items[0].Id')
29+
echo "Open URL: $AWS_ENDPOINT_URL/cloudfront/$AWS_DEFAULT_REGION/$distributionId/"

packages/infra/cdk/aws-sdk-js-notes-app-frontend-stack.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
CfnOutput,
55
aws_s3 as s3,
66
aws_s3_deployment,
7+
aws_cloudfront as cloudfront,
8+
aws_cloudfront_origins as origins,
79
} from "aws-cdk-lib";
810
import { Construct } from "constructs";
911

@@ -22,6 +24,25 @@ export class AwsSdkJsNotesAppFrontendStack extends Stack {
2224
destinationBucket: websiteBucket,
2325
});
2426

27+
new cloudfront.Distribution(this, "WebsiteDistribution", {
28+
defaultRootObject: "index.html",
29+
defaultBehavior: {
30+
origin: new origins.S3Origin(websiteBucket),
31+
},
32+
errorResponses: [
33+
{
34+
httpStatus: 403,
35+
responseHttpStatus: 200,
36+
responsePagePath: "/index.html",
37+
},
38+
{
39+
httpStatus: 404,
40+
responseHttpStatus: 200,
41+
responsePagePath: "/index.html",
42+
},
43+
],
44+
});
45+
2546
new CfnOutput(this, "FrontendBucketWebsite", {
2647
value: `http://${websiteBucket.bucketName}.s3-website.localhost.localstack.cloud:4566/`,
2748
});

0 commit comments

Comments
 (0)