Skip to content

Commit 615c59c

Browse files
committed
chore: wip
1 parent 34d98a4 commit 615c59c

File tree

12 files changed

+76
-45
lines changed

12 files changed

+76
-45
lines changed

.stacks/core/actions/src/zip/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const to = p.projectStoragePath('framework/cloud/api.zip')
1515

1616
// zip all the paths into a single file
1717
await zip(from, to, {
18-
cwd: p.cloudPath('src/drivers/aws/runtime'),
18+
cwd: p.cloudPath('src/runtime'),
1919
})
2020

2121
log.info('zipped your API')

.stacks/core/cloud/build-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { log, runCommand } from '@stacksjs/cli'
22

3-
const result = await runCommand('bun build ./src/drivers/aws/runtime/server.ts --outdir src/drivers/aws/runtime --format esm --target bun', {
3+
const result = await runCommand('bun build ./src/runtime/server.ts --outdir src/runtime --format esm --target bun', {
44
cwd: import.meta.dir,
55
})
66

.stacks/core/cloud/build.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { log, runCommand } from '@stacksjs/cli'
22

3-
const result = await runCommand('bun build ./src/edge/origin-request.ts --outfile ./dist/origin-request.js && zip -r dist.zip dist/origin-request.js package.json', {
3+
const result = await runCommand('bun build ./src/edge/origin-request.ts --outfile ./dist/origin-request.js --outdir ./dist/', {
44
cwd: import.meta.dir,
55
})
66

77
if (result.isErr())
88
log.error(result.error)
9+
10+
const result2 = await runCommand('zip -r dist.zip dist/origin-request.js package.json', {
11+
cwd: import.meta.dir,
12+
})
13+
14+
if (result2.isErr())
15+
log.error(result2.error)

.stacks/core/cloud/cdk.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"app": "bun ./src/deploy.ts",
3+
"profile": "stacks",
34
"watch": {
45
"include": [
56
"**"
@@ -28,7 +29,6 @@
2829
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
2930
"@aws-cdk/aws-iam:minimizePolicies": true,
3031
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31-
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
3232
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
3333
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
3434
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
@@ -41,7 +41,6 @@
4141
"@aws-cdk/aws-route53-patters:useCertificate": true,
4242
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
4343
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44-
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
4544
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
4645
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
4746
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,

.stacks/core/cloud/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@
6969
"@aws-sdk/client-ssm": "^3.438.0",
7070
"@aws-sdk/lib-dynamodb": "^3.438.0",
7171
"@stacksjs/config": "workspace:*",
72+
"@stacksjs/env": "workspace:*",
7273
"@stacksjs/logging": "workspace:*",
7374
"@stacksjs/path": "workspace:*",
7475
"@stacksjs/router": "workspace:*",
7576
"@stacksjs/storage": "workspace:*",
7677
"@stacksjs/validation": "workspace:*",
78+
"aws-cdk": "^2.103.1",
7779
"aws-cdk-lib": "^2.103.1",
7880
"constructs": "^10.3.0"
7981
},
@@ -92,6 +94,7 @@
9294
"@aws-sdk/client-ssm": "^3.438.0",
9395
"@stacksjs/config": "workspace:*",
9496
"@stacksjs/dns": "workspace:*",
97+
"@stacksjs/env": "workspace:*",
9598
"@stacksjs/logging": "workspace:*",
9699
"@stacksjs/path": "workspace:*",
97100
"@stacksjs/router": "workspace:*",

.stacks/core/cloud/src/cloud/cdn.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Duration,
66
Fn,
77
NestedStack,
8+
CfnOutput as Output,
89
RemovalPolicy,
910
Stack,
1011
aws_certificatemanager as acm,
@@ -18,6 +19,7 @@ import {
1819
aws_route53_targets as targets,
1920
} from 'aws-cdk-lib'
2021
import type { Construct } from 'constructs'
22+
import { config } from '@stacksjs/config'
2123
import { hasFiles } from '@stacksjs/storage'
2224
import { path as p } from '@stacksjs/path'
2325
import type { NestedCloudProps } from '../types'
@@ -112,7 +114,7 @@ export class CdnStack extends NestedStack {
112114
cfnOriginRequestFunction.applyRemovalPolicy(RemovalPolicy.RETAIN)
113115

114116
// the actual CDN distribution
115-
new cloudfront.Distribution(this, 'Distribution', {
117+
const cdn = new cloudfront.Distribution(this, 'Distribution', {
116118
domainNames: [props.domain],
117119
defaultRootObject: 'index.html',
118120
comment: `CDN for ${config.app.url}`,
@@ -156,6 +158,10 @@ export class CdnStack extends NestedStack {
156158
],
157159
})
158160

161+
new Output(this, 'DistributionId', {
162+
value: cdn.distributionId,
163+
})
164+
159165
// setup the www redirect
160166
// Create a bucket for www.yourdomain.com and configure it to redirect to yourdomain.com
161167
const wwwBucket = new s3.Bucket(this, 'WwwBucket', {
@@ -253,31 +259,31 @@ export class CdnStack extends NestedStack {
253259
return config.cloud.deploy?.api
254260
}
255261

256-
apiBehaviorOptions(): Record<string, cloudfront.BehaviorOptions> {
257-
const origin = (path: '/api' | '/api/*' = '/api') => new origins.HttpOrigin(Fn.select(2, Fn.split('/', this.apiVanityUrl)), { // removes the https://
258-
originPath: path,
259-
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
260-
})
261-
262-
return {
263-
'/api': {
264-
origin: origin(),
265-
compress: true,
266-
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
267-
// cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
268-
cachePolicy: this.setApiCachePolicy(),
269-
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
270-
},
271-
'/api/*': {
272-
origin: origin('/api/*'),
273-
compress: true,
274-
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
275-
// cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
276-
cachePolicy: this.apiCachePolicy,
277-
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
278-
},
279-
}
280-
}
262+
// apiBehaviorOptions(): Record<string, cloudfront.BehaviorOptions> {
263+
// const origin = (path: '/api' | '/api/*' = '/api') => new origins.HttpOrigin(Fn.select(2, Fn.split('/', this.apiVanityUrl)), { // removes the https://
264+
// originPath: path,
265+
// protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
266+
// })
267+
268+
// return {
269+
// '/api': {
270+
// origin: origin(),
271+
// compress: true,
272+
// allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
273+
// // cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
274+
// cachePolicy: this.setApiCachePolicy(),
275+
// viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
276+
// },
277+
// '/api/*': {
278+
// origin: origin('/api/*'),
279+
// compress: true,
280+
// allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
281+
// // cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
282+
// cachePolicy: this.apiCachePolicy,
283+
// viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
284+
// },
285+
// }
286+
// }
281287

282288
docsBehaviorOptions(): Record<string, cloudfront.BehaviorOptions> {
283289
return {
Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
/* eslint-disable no-new */
2-
import { NestedStack, aws_s3_deployment as s3deploy } from 'aws-cdk-lib'
2+
import {
3+
NestedStack,
4+
Stack,
5+
StackOutputs,
6+
aws_cloudfront as cloudfront,
7+
aws_s3 as s3,
8+
aws_s3_deployment as s3deploy,
9+
} from 'aws-cdk-lib'
10+
import { config } from '@stacksjs/config'
311
import type { Construct } from 'constructs'
412
import type { NestedCloudProps } from '../types'
513

614
export class StorageStack extends NestedStack {
715
constructor(scope: Construct, props: NestedCloudProps) {
816
super(scope, 'Deploy', props)
917

18+
const bucketPrefix = `${props.appName}-${props.appEnv}`
19+
const privateSource = '../../../storage/private'
20+
const docsSource = '../../../storage/docs'
21+
const websiteSource = config.app.docMode ? docsSource : '../../../storage/public'
22+
const publicBucket = s3.Bucket.fromBucketName(this, 'PublicBucket', `${bucketPrefix}-${props.partialAppKey}`)
23+
const privateBucket = s3.Bucket.fromBucketName(this, 'PrivateBucket', `${bucketPrefix}-private-${props.partialAppKey}`)
24+
const distributionId = new StackOutputs(scope, 'MyStackOutputs', {
25+
stack: Stack.of(this),
26+
}).get('DistributionId')
27+
28+
const cdn = cloudfront.Distribution.fromDistributionAttributes(this, 'CDN', {
29+
domainName: props.domain,
30+
distributionId,
31+
})
32+
1033
new s3deploy.BucketDeployment(this, 'Website', {
11-
sources: [s3deploy.Source.asset(this.websiteSource)],
12-
destinationBucket: props.publicBucket,
13-
distribution: props.cdn,
34+
sources: [s3deploy.Source.asset(websiteSource)],
35+
destinationBucket: publicBucket,
36+
distribution: cdn,
1437
distributionPaths: ['/*'],
1538
})
1639

1740
new s3deploy.BucketDeployment(this, 'PrivateFiles', {
18-
sources: [s3deploy.Source.asset(this.privateSource)],
19-
destinationBucket: props.privateBucket,
41+
sources: [s3deploy.Source.asset(privateSource)],
42+
destinationBucket: privateBucket,
2043
})
2144
}
2245
}

.stacks/core/cloud/src/cloud/docs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class DocsStack extends NestedStack {
1212
super(scope, 'Docs', props)
1313
// if docsPrefix is not set, then we know we are in docsMode and the documentation lives at the root of the domain
1414
const docsPrefix = config.app.docMode ? undefined : config.docs.base
15-
const docsSource = '../../../storage/framework/docs'
1615

1716
new Output(this, 'DocsUrl', {
1817
value: `https://${props.domain}/${docsPrefix}`,

.stacks/core/cloud/src/cloud/security.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-new */
22
// waf and encryption
3+
import { config } from '@stacksjs/config'
34
import { Duration, NestedStack, RemovalPolicy, Tags, aws_kms as kms, aws_wafv2 as wafv2 } from 'aws-cdk-lib'
45
import type { Construct } from 'constructs'
56
import type { NestedCloudProps } from '../types'

.stacks/core/cloud/src/cloud/storage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export class StorageStack extends NestedStack {
77
super(scope, 'Storage', props)
88

99
const bucketPrefix = `${props.appName}-${props.appEnv}`
10-
// const docsSource = '../../../storage/docs'
11-
// const websiteSource = config.app.docMode ? docsSource : '../../../storage/public'
1210

1311
const publicBucket = new s3.Bucket(this, 'PublicBucket', {
1412
bucketName: `${bucketPrefix}-${props.partialAppKey}`,

0 commit comments

Comments
 (0)