Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 86
feat: implement project deploy command#2001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3253ab05ae34c878348f65e568705bcd05f7e328eae8224855008322aeba2dbd682e878910f5dd1c1fb285ebc1554129909bdfeb6e9365ba4cca59c569c562bb0ba2eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { existsSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import z from "zod"; | ||
| import { ProjectStateError } from "../../errors/errors"; | ||
| import type { ReadWriteJson } from "../../io"; | ||
| // The generated app tags every stack with the target it was synthesized for. Selecting | ||
| // on the tag keeps the CLI from reproducing the app's stack-naming convention. | ||
| const TARGET_TAG = "agentcore:target-name"; | ||
| const STACK_ARTIFACT = "aws:cloudformation:stack"; | ||
| // Artifacts are keyed by the hierarchical id the toolkit matches stack patterns against. | ||
| const AssemblyManifestSchema = z.object({ | ||
| artifacts: z | ||
| .record( | ||
| z.string(), | ||
| z.object({ | ||
| type: z.string(), | ||
| properties: z.object({ tags: z.record(z.string(), z.string()).optional() }).optional(), | ||
| }), | ||
| ) | ||
| .default({}), | ||
| }); | ||
| /** | ||
| * Asks the synthesized manifest which stack belongs to `target`, rather than deriving | ||
| * the name and hoping it matches what synth chose. | ||
| */ | ||
| export async function stackForTarget( | ||
| json: ReadWriteJson, | ||
| assemblyDirectory: string, | ||
| target: string, | ||
| ): Promise<string> { | ||
| const path = join(assemblyDirectory, "manifest.json"); | ||
| // deploy synthesizes immediately before this, so a missing manifest means synth wrote | ||
| // somewhere else rather than that the user skipped a step. | ||
| if (!existsSync(path)) { | ||
| throw new ProjectStateError(`No synthesized cloud assembly was found at ${path}.`); | ||
| } | ||
| const manifest = await json.read(path, AssemblyManifestSchema); | ||
| const stacks = Object.entries(manifest.artifacts).filter( | ||
| ([, artifact]) => artifact.type === STACK_ARTIFACT, | ||
| ); | ||
| const match = stacks.find(([, artifact]) => artifact.properties?.tags?.[TARGET_TAG] === target); | ||
| if (!match) { | ||
| throw new ProjectStateError( | ||
| `The synthesized cloud assembly has no stack for deployment target '${target}'. ` + | ||
| `${path} defines ${stacks.length} stack(s), none tagged ${TARGET_TAG}='${target}'.`, | ||
| ); | ||
| } | ||
| return match[0]; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the synth output the stack name? Is there a reason we need to re-derive it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing is re-derived.
stackForTargetreads synth's manifest.json and selects the stack whoseagentcore:target-nametag matches, precisely so the CLI never reproduces the app's naming conventionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess re-derive is the wrong word, but I'm wondering why the build doesn't output the stack name allowing us to avoid inspecting the assembly directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept the manifest lookup in #2058 because generic build has no deployment target and may synthesize multiple stacks; the cloud assembly is CDK synth’s structured output, so returning one stack from build would still require this lookup while leaking CDK-specific semantics into the build contract. Clarified the implementation in c76b638 by renaming stackForTarget/stackName to stackArtifactIdForTarget/stackArtifactId.