-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5703dfc
commit 1a85577
Showing
6 changed files
with
214 additions
and
30 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,77 @@ | ||
import process from 'node:process' | ||
import { log } from '@stacksjs/cli' | ||
import { config, determineAppEnv } from '@stacksjs/config' | ||
import { env } from '@stacksjs/env' | ||
import { slug as slugify } from '@stacksjs/strings' | ||
import { ExitCode } from '@stacksjs/types' | ||
import { App } from 'aws-cdk-lib' | ||
import 'source-map-support/register' | ||
import { Cloud } from '../storage/framework/core/cloud/src/cloud' | ||
import { getOrCreateTimestamp } from '../storage/framework/core/cloud/src/helpers' | ||
import type { CloudOptions } from '../storage/framework/core/cloud/src/types' | ||
|
||
const app = new App() | ||
const appEnv = determineAppEnv() | ||
const appKey = config.app.key | ||
const domain = config.app.url | ||
const appName = config.app.name?.toLowerCase() ?? 'stacks' | ||
const slug = slugify(appName) | ||
const name = `${slug}-cloud` | ||
const account = env.AWS_ACCOUNT_ID | ||
// const region = env.AWS_DEFAULT_REGION | ||
const region = 'us-east-1' // currently, us-east-1 is the only fully-supported region | ||
let timestamp | ||
|
||
if (!appKey) { | ||
log.info('Please set an application key. You may need to run `buddy key:generate`.') | ||
process.exit(ExitCode.InvalidArgument) | ||
} | ||
|
||
const parts = appKey.split(':') | ||
if (parts && parts.length < 2) | ||
throw new Error( | ||
'Invalid format application key format. Expected a colon-separated string. You may need to run `buddy key:generate`.', | ||
) | ||
|
||
if (!account || !region) | ||
throw new Error('Stacks is missing your accountId or region. Please ensure it is set in your .env file') | ||
|
||
if (!domain) throw new Error('Missing app.url in config.') | ||
|
||
if (!appName) throw new Error('Missing app.name in config.') | ||
|
||
if (!config.team || Object.keys(config.team).length === 0) | ||
throw new Error( | ||
'Your ./config team needs to at least have one member defined. Please set yourself as a team member and try deploying again.', | ||
) | ||
|
||
const usEnv = { | ||
account, | ||
region, | ||
} | ||
|
||
try { | ||
timestamp = await getOrCreateTimestamp() | ||
} catch (error) { | ||
console.error('Error fetching timestamp', error) | ||
process.exit(ExitCode.FatalError) | ||
} | ||
|
||
export const options = { | ||
env: usEnv, | ||
name, | ||
slug, | ||
appEnv: appEnv ?? 'dev', | ||
appName, | ||
domain, | ||
timestamp, | ||
} satisfies CloudOptions | ||
|
||
const cloud = new Cloud(app, name, { | ||
...options, | ||
description: `The Stacks Cloud`, | ||
}) | ||
|
||
await cloud.init() | ||
|
||
app.synth() |
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,135 @@ | ||
import { config } from '@stacksjs/config' | ||
import { Stack } from 'aws-cdk-lib' | ||
import type { Construct } from 'constructs' | ||
import type { CloudOptions } from '../types' | ||
import { AiStack } from './ai' | ||
import { CdnStack } from './cdn' | ||
import { CliStack } from './cli' | ||
import { ComputeStack } from './compute' | ||
import { DeploymentStack } from './deployment' | ||
import { DnsStack } from './dns' | ||
import { DocsStack } from './docs' | ||
import { EmailStack } from './email' | ||
import { FileSystemStack } from './file-system' | ||
import { JumpBoxStack } from './jump-box' | ||
import { NetworkStack } from './network' | ||
import { PermissionsStack } from './permissions' | ||
import { QueueStack } from './queue' | ||
import { RedirectsStack } from './redirects' | ||
import { SecurityStack } from './security' | ||
import { StorageStack } from './storage' | ||
|
||
// import { DashboardStack } from './dashboard' | ||
|
||
export class Cloud extends Stack { | ||
dns: DnsStack | ||
security: SecurityStack | ||
storage: StorageStack | ||
network: NetworkStack | ||
fileSystem: FileSystemStack | ||
jumpBox: JumpBoxStack | ||
docs: DocsStack | ||
email: EmailStack | ||
redirects: RedirectsStack | ||
permissions: PermissionsStack | ||
ai: AiStack | ||
cli: CliStack | ||
api!: ComputeStack | ||
cdn!: CdnStack | ||
queue!: QueueStack | ||
deployment!: DeploymentStack | ||
scope: Construct | ||
props: CloudOptions | ||
|
||
constructor(scope: Construct, id: string, props: CloudOptions) { | ||
super(scope, id, props) | ||
this.scope = scope | ||
this.props = props | ||
|
||
// please beware: be careful changing the order of the stack creations below | ||
this.dns = new DnsStack(this, props) | ||
this.security = new SecurityStack(this, { | ||
...props, | ||
zone: this.dns.zone, | ||
}) | ||
|
||
this.storage = new StorageStack(this, { | ||
...props, | ||
kmsKey: this.security.kmsKey, | ||
}) | ||
|
||
this.network = new NetworkStack(this, props) | ||
|
||
this.fileSystem = new FileSystemStack(this, { | ||
...props, | ||
vpc: this.network.vpc, | ||
}) | ||
|
||
this.jumpBox = new JumpBoxStack(this, { | ||
...props, | ||
vpc: this.network.vpc, | ||
fileSystem: this.fileSystem.fileSystem, | ||
}) | ||
|
||
this.docs = new DocsStack(this, props) | ||
|
||
this.email = new EmailStack(this, { | ||
...props, | ||
zone: this.dns.zone, | ||
}) | ||
|
||
this.redirects = new RedirectsStack(this, props) | ||
|
||
this.permissions = new PermissionsStack(this) | ||
|
||
// new DashboardStack(this) | ||
|
||
this.ai = new AiStack(this, props) | ||
|
||
this.cli = new CliStack(this, props) | ||
} | ||
|
||
// we use an async init() method here because we need to wait for the | ||
|
||
async init() { | ||
if (config.api?.deploy) { | ||
const props = this.props | ||
this.api = new ComputeStack(this, { | ||
...props, | ||
vpc: this.network.vpc, | ||
fileSystem: this.fileSystem.fileSystem, | ||
zone: this.dns.zone, | ||
certificate: this.security.certificate, | ||
}) | ||
|
||
this.queue = new QueueStack(this, { | ||
...props, | ||
cluster: this.api.cluster, | ||
taskDefinition: this.api.taskDefinition, | ||
}) | ||
|
||
await this.queue.init() | ||
|
||
this.cdn = new CdnStack(this, { | ||
...props, | ||
publicBucket: this.storage.publicBucket, | ||
logBucket: this.storage.logBucket, | ||
certificate: this.security.certificate, | ||
firewall: this.security.firewall, | ||
originRequestFunction: this.docs.originRequestFunction, | ||
zone: this.dns.zone, | ||
cliSetupUrl: this.cli.cliSetupUrl, | ||
askAiUrl: this.ai.askAiUrl, | ||
summarizeAiUrl: this.ai.summarizeAiUrl, | ||
lb: this.api?.lb, | ||
}) | ||
|
||
this.deployment = new DeploymentStack(this, { | ||
...props, | ||
publicBucket: this.storage.publicBucket, | ||
privateBucket: this.storage.privateBucket, | ||
cdn: this.cdn.distribution, | ||
}) | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.