Skip to content

Commit

Permalink
feat: add dns for jukebox (#800)
Browse files Browse the repository at this point in the history
Signed-off-by: hxtree <[email protected]>
  • Loading branch information
hxtree authored Feb 4, 2024
1 parent e34e607 commit 90fd28f
Show file tree
Hide file tree
Showing 50 changed files with 528 additions and 64 deletions.
9 changes: 4 additions & 5 deletions clients/admin-client/bin/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node
// TODO deploy to AWS
// import * as cdk from 'aws-cdk-lib';
// import { AdminClientStack } from '../stacks/admin-client-stack';
import * as cdk from 'aws-cdk-lib';
import { AdminClientStack } from '../stacks/admin-client.stack';

// const app = new cdk.App();
const app = new cdk.App();

// new AdminClientStack(app, 'AdminClientStack', {});
new AdminClientStack(app, 'AdminClientStack', {});
2 changes: 1 addition & 1 deletion clients/admin-client/cdk.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app": "create-bundle && npx ts-node --esm --prefer-ts-exts bin/app.ts",
"app": "rushx build && npx ts-node --esm --prefer-ts-exts bin/app.ts",
"watch": {
"include": ["src/", "stacks/", "pages/", "components/"],
"exclude": ["__tests__", "*.test.ts", "*.e2e-spec.ts"]
Expand Down
14 changes: 12 additions & 2 deletions clients/admin-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
"dev": "vite",
"build": "tsc && vite build",
"build:all": "rush build -t .",
"artifact": "create-artifact @cats-cradle/admin-client",
"lint": "eslint --format visualstudio \"./src/**/*.tsx\" --fix",
"lint:ci": "eslint --format visualstudio \"./src/**/*.tsx\" --fix-dry-run",
"preview": "vite preview",
"test": "",
"test:cov": ""
"test:cov": "",
"cdk:bootstrap": "cdk bootstrap",
"cdk:diff": "cdk diff",
"cdk:synth": "cdk synth",
"cdk:hotswap": "cdk deploy --hotswap",
"cdk:deploy": "cdk deploy",
"cdk:watch": "cdk watch",
"cdk:destroy": "cdk destroy",
"depcheck": "npx depcheck"
},
"dependencies": {
"react": "18.2.0",
Expand Down Expand Up @@ -39,6 +48,7 @@
"@types/jest": "29.5.11",
"jest": "29.7.0",
"jest-environment-jsdom": "~29.6.1",
"@cats-cradle/base-nodejs": "workspace:*"
"@cats-cradle/base-nodejs": "workspace:*",
"constructs": "^10.2.70"
}
}
123 changes: 121 additions & 2 deletions clients/admin-client/stacks/admin-client.stack.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,121 @@
// TODO deploy to ec2
// https://nextjs.org/docs/pages/building-your-application/deploying
import { Construct } from 'constructs';
import * as cdk from 'aws-cdk-lib';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import { StackProps } from 'aws-cdk-lib';
import { Bucket, BucketAccessControl } from 'aws-cdk-lib/aws-s3';
import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment';
import {
Distribution,
OriginAccessIdentity,
ResponseHeadersPolicy,
} from 'aws-cdk-lib/aws-cloudfront';
import { S3Origin } from 'aws-cdk-lib/aws-cloudfront-origins';
import * as route53 from 'aws-cdk-lib/aws-route53';
import * as targets from 'aws-cdk-lib/aws-route53-targets';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';

export class AdminClientStack extends cdk.Stack {
public parentDomainName: string;
public acmCertificateArn: string;
public hostedZoneId: string;

constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

// s3 bucket
const bucket = new Bucket(this, 'Bucket', {
accessControl: BucketAccessControl.PRIVATE,
});

const originAccessIdentity = new OriginAccessIdentity(
this,
'OriginAccessIdentity',
);
bucket.grantRead(originAccessIdentity);

this.acmCertificateArn = ssm.StringParameter.fromStringParameterAttributes(
this,
`${id}-orgformation-certs-wildcard-cert1-arn`,
{
parameterName: 'orgformation-certs-wildcard-cert1-arn',
},
).stringValue;

const certificate = acm.Certificate.fromCertificateArn(
this,
`${id}-acm-certificate`,
this.acmCertificateArn,
);

// DNS

// fetch parameters from SSM Parameter Store
this.parentDomainName = ssm.StringParameter.fromStringParameterAttributes(
this,
`${id}-ssm-domain-name`,
{
parameterName: 'DOMAIN_NAME',
},
).stringValue;

// Retrieve parameters from SSM Parameter Store
this.hostedZoneId = ssm.StringParameter.fromStringParameterAttributes(
this,
`${id}-hosted-zone-id`,
{
parameterName: 'my-domains-hosted-zone-id',
},
).stringValue;

const subdomainName = 'admin';

const domainName = `${subdomainName}.${this.parentDomainName}`;

// cloudfront distribution
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const cloudFrontDistribution = new Distribution(this, 'Distribution', {
defaultRootObject: 'index.html',
defaultBehavior: {
origin: new S3Origin(bucket, { originAccessIdentity }),
// todo lock down CORS later
responseHeadersPolicy:
ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT,
},
domainNames: [domainName],
certificate,
});

// bucket resource
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const awsBucketResource = new BucketDeployment(this, 'BucketDeployment', {
destinationBucket: bucket,
sources: [Source.asset('./dist')],
});

const hostedZone = route53.PublicHostedZone.fromHostedZoneAttributes(
this,
`${id}-hosted-zone`,
{
hostedZoneId: this.hostedZoneId,
zoneName: domainName,
},
);

// Create a record set for the custom domain pointing to the CloudFront distribution
new route53.ARecord(this, 'AliasRecord', {
recordName: domainName,
target: route53.RecordTarget.fromAlias(
new targets.CloudFrontTarget(cloudFrontDistribution),
),
zone: hostedZone,
});

new cdk.CfnOutput(this, 'Cloud Front Distribution', {
value: cloudFrontDistribution.domainName,
});

new cdk.CfnOutput(this, 'Domain Name', {
value: `https://${domainName}`,
});
}
}
12 changes: 12 additions & 0 deletions clients/design-system/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@cats-cradle/design-system",
"entries": [
{
"version": "0.5.3",
"tag": "@cats-cradle/design-system_v0.5.3",
"date": "Sun, 04 Feb 2024 05:29:40 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/base-nodejs\" to `1.0.11`"
}
]
}
},
{
"version": "0.5.2",
"tag": "@cats-cradle/design-system_v0.5.2",
Expand Down
7 changes: 6 additions & 1 deletion clients/design-system/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/design-system

This log was last generated on Thu, 28 Dec 2023 16:54:41 GMT and should not be manually modified.
This log was last generated on Sun, 04 Feb 2024 05:29:40 GMT and should not be manually modified.

## 0.5.3
Sun, 04 Feb 2024 05:29:40 GMT

_Version update only_

## 0.5.2
Thu, 28 Dec 2023 16:54:41 GMT
Expand Down
2 changes: 1 addition & 1 deletion clients/design-system/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cats-cradle/design-system",
"private": false,
"version": "0.5.2",
"version": "0.5.3",
"module": "commonjs",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "3a8692dbe1ed4ef82ded5abeca0fd8a82b8f6560",
"pnpmShrinkwrapHash": "7ec5c1cd30817f579782876b74e76df4b257bf19",
"preferredVersionsHash": "a48003cf229dd47d077bcf6301ac15a6f90e1c34"
}
15 changes: 15 additions & 0 deletions libraries/faker-factory/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{
"name": "@cats-cradle/faker-factory",
"entries": [
{
"version": "1.2.10",
"tag": "@cats-cradle/faker-factory_v1.2.10",
"date": "Sun, 04 Feb 2024 05:29:40 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/base-nodejs\" to `1.0.11`"
},
{
"comment": "Updating dependency \"@cats-cradle/validation-schemas\" to `0.4.7`"
}
]
}
},
{
"version": "1.2.9",
"tag": "@cats-cradle/faker-factory_v1.2.9",
Expand Down
7 changes: 6 additions & 1 deletion libraries/faker-factory/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/faker-factory

This log was last generated on Thu, 28 Dec 2023 16:54:41 GMT and should not be manually modified.
This log was last generated on Sun, 04 Feb 2024 05:29:40 GMT and should not be manually modified.

## 1.2.10
Sun, 04 Feb 2024 05:29:40 GMT

_Version update only_

## 1.2.9
Thu, 28 Dec 2023 16:54:41 GMT
Expand Down
2 changes: 1 addition & 1 deletion libraries/faker-factory/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cats-cradle/faker-factory",
"version": "1.2.9",
"version": "1.2.10",
"main": "./dist/index.js",
"repository": {
"type": "git",
Expand Down
18 changes: 18 additions & 0 deletions libraries/nestjs-modules/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{
"name": "@cats-cradle/nestjs-modules",
"entries": [
{
"version": "0.2.18",
"tag": "@cats-cradle/nestjs-modules_v0.2.18",
"date": "Sun, 04 Feb 2024 05:29:40 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/base-nodejs\" to `1.0.11`"
},
{
"comment": "Updating dependency \"@cats-cradle/validation-schemas\" to `0.4.7`"
},
{
"comment": "Updating dependency \"@cats-cradle/faker-factory\" to `1.2.10`"
}
]
}
},
{
"version": "0.2.17",
"tag": "@cats-cradle/nestjs-modules_v0.2.17",
Expand Down
7 changes: 6 additions & 1 deletion libraries/nestjs-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/nestjs-modules

This log was last generated on Thu, 28 Dec 2023 16:54:41 GMT and should not be manually modified.
This log was last generated on Sun, 04 Feb 2024 05:29:40 GMT and should not be manually modified.

## 0.2.18
Sun, 04 Feb 2024 05:29:40 GMT

_Version update only_

## 0.2.17
Thu, 28 Dec 2023 16:54:41 GMT
Expand Down
2 changes: 1 addition & 1 deletion libraries/nestjs-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cats-cradle/nestjs-modules",
"version": "0.2.17",
"version": "0.2.18",
"main": "./dist/index.js",
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions libraries/pseudo-random/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@cats-cradle/pseudo-random",
"entries": [
{
"version": "0.0.6",
"tag": "@cats-cradle/pseudo-random_v0.0.6",
"date": "Sun, 04 Feb 2024 05:29:40 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/base-nodejs\" to `1.0.11`"
}
]
}
},
{
"version": "0.0.5",
"tag": "@cats-cradle/pseudo-random_v0.0.5",
Expand Down
7 changes: 6 additions & 1 deletion libraries/pseudo-random/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/pseudo-random

This log was last generated on Thu, 28 Dec 2023 16:54:41 GMT and should not be manually modified.
This log was last generated on Sun, 04 Feb 2024 05:29:40 GMT and should not be manually modified.

## 0.0.6
Sun, 04 Feb 2024 05:29:40 GMT

_Version update only_

## 0.0.5
Thu, 28 Dec 2023 16:54:41 GMT
Expand Down
2 changes: 1 addition & 1 deletion libraries/pseudo-random/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cats-cradle/pseudo-random",
"version": "0.0.5",
"version": "0.0.6",
"main": "./dist/index.js",
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions libraries/validation-schemas/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@cats-cradle/validation-schemas",
"entries": [
{
"version": "0.4.7",
"tag": "@cats-cradle/validation-schemas_v0.4.7",
"date": "Sun, 04 Feb 2024 05:29:40 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/base-nodejs\" to `1.0.11`"
}
]
}
},
{
"version": "0.4.6",
"tag": "@cats-cradle/validation-schemas_v0.4.6",
Expand Down
7 changes: 6 additions & 1 deletion libraries/validation-schemas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/validation-schemas

This log was last generated on Thu, 28 Dec 2023 16:54:41 GMT and should not be manually modified.
This log was last generated on Sun, 04 Feb 2024 05:29:40 GMT and should not be manually modified.

## 0.4.7
Sun, 04 Feb 2024 05:29:40 GMT

_Version update only_

## 0.4.6
Thu, 28 Dec 2023 16:54:41 GMT
Expand Down
Loading

0 comments on commit 90fd28f

Please sign in to comment.