-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk): added cdk code to deploy static Next.js website to cloudfr…
…ont + s3. (#37) * revert(cdk): removed Apple OAuth. * feat(webapp): static export for next. * feat: added .eslintignore to speed up lints. * ci: added clean scripts to package.json. * feat(cdk): added cdk code to deploy static Next.js website to cloudfront + s3.
- Loading branch information
Showing
24 changed files
with
517 additions
and
62 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
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,2 @@ | ||
/cdk.out | ||
/node_modules |
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
46 changes: 46 additions & 0 deletions
46
apps/snakecode-cdk/lib/stacks/StaticWebsiteHostingStack.ts
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,46 @@ | ||
import type { StackProps } from "aws-cdk-lib"; | ||
import { aws_s3, CfnOutput, RemovalPolicy, Stack } from "aws-cdk-lib"; | ||
import { Distribution, OriginAccessIdentity } from "aws-cdk-lib/aws-cloudfront"; | ||
import { S3Origin } from "aws-cdk-lib/aws-cloudfront-origins"; | ||
import { BucketAccessControl } from "aws-cdk-lib/aws-s3"; | ||
import { BucketDeployment, Source } from "aws-cdk-lib/aws-s3-deployment"; | ||
import type { Construct } from "constructs"; | ||
|
||
import type { StaticWebsiteHostingStackConfiguration } from "@snakecode/models"; | ||
|
||
export class StaticWebsiteHostingStack extends Stack { | ||
constructor(scope: Construct, id: string, props: StackProps & { staticWebsiteHostingStackConfiguration: StaticWebsiteHostingStackConfiguration; stage: string; staticAssetsFilePath: string; cfnOutputName: string }) { | ||
super(scope, id, props); | ||
|
||
const bucket = new aws_s3.Bucket(this, `${props.staticWebsiteHostingStackConfiguration.bucketName}-${props.stage}-${props.env!.region}`, { | ||
accessControl: BucketAccessControl.PRIVATE, | ||
|
||
// Ensures that the S3 bucket is properly cleaned up when the stack is deleted. | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
autoDeleteObjects: true, | ||
}); | ||
|
||
// TODO: Path is baked in at the moment | ||
// Is there some way to verify that this path exists? | ||
// Deploy the static website to the bucket. | ||
new BucketDeployment(this, `${props.staticWebsiteHostingStackConfiguration.bucketDeploymentName}-${props.stage}-${props.env!.region}`, { | ||
destinationBucket: bucket, | ||
sources: [Source.asset(props.staticAssetsFilePath)], | ||
}); | ||
|
||
const originAccessIdentity = new OriginAccessIdentity(this, `${props.staticWebsiteHostingStackConfiguration.originAccessIdentityName}-${props.stage}-${props.env!.region}`); | ||
bucket.grantRead(originAccessIdentity); | ||
|
||
const distribution = new Distribution(this, `${props.staticWebsiteHostingStackConfiguration.distributionName}`, { | ||
defaultRootObject: "index.html", | ||
defaultBehavior: { | ||
origin: new S3Origin(bucket, { originAccessIdentity }), | ||
}, | ||
}); | ||
|
||
new CfnOutput(this, props.cfnOutputName, { | ||
exportName: props.cfnOutputName.replaceAll("_", "-"), | ||
value: distribution.domainName, | ||
}); | ||
} | ||
} |
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,3 @@ | ||
/out | ||
/.next | ||
/node_modules |
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
{ | ||
"snakecode-amplify-stack": { | ||
"amplifyid": "d3thed3kk59i2n", | ||
"amplifyid": "dme6lbx52jvft", | ||
"userpoolsdomainurl": "snakecode-dev.auth.us-west-2.amazoncognito.com", | ||
"identitypoolid": "us-west-2:db458b37-0e50-4284-beb1-75c1e9c72890", | ||
"userpoolswebclientid": "3j97ggu8ccurvnnc4tkc3aua13", | ||
"userpoolsid": "us-west-2_93GYjaMY6", | ||
"identitypoolid": "us-west-2:24f4a730-f2d4-4533-a30b-273197201ea4", | ||
"userpoolswebclientid": "4qtj9vn0fn6ovj0ohi40ojaco4", | ||
"userpoolsid": "us-west-2_qKsYab2W1", | ||
"region": "us-west-2", | ||
"cognitoregion": "us-west-2" | ||
}, | ||
"snakecode-nextjs-ssg-hosting-stack": { | ||
"mainwebsitedomainname": "d14sb61hcjf629.cloudfront.net" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
output: "export", | ||
images: { | ||
unoptimized: true, | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; |
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
4 changes: 1 addition & 3 deletions
4
apps/snakecode-webapp/src/components/modules/courses/[course]/[section]/[lesson]/coding.tsx
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
3 changes: 1 addition & 2 deletions
3
apps/snakecode-webapp/src/components/modules/courses/[course]/[section]/lesson-button.tsx
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
7 changes: 3 additions & 4 deletions
7
apps/snakecode-webapp/src/pages/courses/[course]/[section]/[lesson]/index.tsx
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 |
---|---|---|
@@ -1,17 +1,15 @@ | ||
/** ****************************************************** | ||
Function used to export the CommitLint configuration. | ||
******************************************************* */ | ||
export const setCommitLintConfig = () => { | ||
return { | ||
extends: ["@commitlint/config-conventional", "@commitlint/config-lerna-scopes"], | ||
export const setCommitLintConfig = () => ({ | ||
extends: ["@commitlint/config-conventional", "@commitlint/config-lerna-scopes"], | ||
|
||
// Any rules defined below here will override rules from @commitlint/config-conventional | ||
rules: { | ||
"type-enum": [2, "always", ["feat", "fix", "ci", "docs", "style", "refactor", "test", "revert", "lint"]], | ||
"subject-empty": [2, "never"], | ||
"subject-full-stop": [2, "always", "."], | ||
"subject-max-length": [2, "always", 72], | ||
"type-case": [2, "always", "lower-case"], | ||
}, | ||
}; | ||
}; | ||
// Any rules defined below here will override rules from @commitlint/config-conventional | ||
rules: { | ||
"type-enum": [2, "always", ["feat", "fix", "ci", "docs", "style", "refactor", "test", "revert", "lint"]], | ||
"subject-empty": [2, "never"], | ||
"subject-full-stop": [2, "always", "."], | ||
"subject-max-length": [2, "always", 72], | ||
"type-case": [2, "always", "lower-case"], | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import type { AmplifyConfiguration } from "./ServiceConfiguration"; | ||
import type { AmplifyConfiguration, StaticWebsiteHostingStackConfiguration } from "./ServiceConfiguration"; | ||
|
||
export interface StageConfiguration { | ||
readonly amplifyStackConfiguration: AmplifyConfiguration; | ||
readonly staticWebsiteHostingStackConfiguration: StaticWebsiteHostingStackConfiguration; | ||
} |
Oops, something went wrong.