|
1 | 1 | import { APP_DIR, ConfigIO, findConfigRoot } from '../../../lib'; |
2 | 2 | import type { AwsDeploymentTarget } from '../../../schema'; |
3 | | -import { validateAwsCredentials } from '../../aws/account'; |
| 3 | +import { detectAccount, validateAwsCredentials } from '../../aws/account'; |
4 | 4 | import { ExecLogger } from '../../logging'; |
5 | 5 | import { setupPythonProject } from '../../operations/python/setup'; |
| 6 | +import { getTemplatePath } from '../../templates/templateRoot'; |
6 | 7 | import * as fs from 'node:fs'; |
7 | 8 | import * as path from 'node:path'; |
8 | 9 |
|
@@ -87,19 +88,27 @@ export async function resolveImportTarget(options: ResolveTargetOptions): Promis |
87 | 88 | onProgress?.('Validating AWS credentials...'); |
88 | 89 | await validateAwsCredentials(); |
89 | 90 |
|
| 91 | + // Validate credentials match the target account |
| 92 | + const callerAccount = await detectAccount(); |
| 93 | + if (callerAccount && target.account && callerAccount !== target.account) { |
| 94 | + throw new Error( |
| 95 | + `Your AWS credentials are for account ${callerAccount}, but the target "${target.name}" is configured for account ${target.account}.\nEnsure your credentials match the deployment target.` |
| 96 | + ); |
| 97 | + } |
| 98 | + |
90 | 99 | return target; |
91 | 100 | } |
92 | 101 |
|
93 | 102 | // ============================================================================ |
94 | 103 | // Stack Name |
95 | 104 | // ============================================================================ |
96 | 105 |
|
97 | | -function sanitize(name: string): string { |
| 106 | +function replaceUnderscoresWithDashes(name: string): string { |
98 | 107 | return name.replace(/_/g, '-'); |
99 | 108 | } |
100 | 109 |
|
101 | 110 | export function toStackName(projectName: string, targetName: string): string { |
102 | | - return `AgentCore-${sanitize(projectName)}-${sanitize(targetName)}`; |
| 111 | + return `AgentCore-${replaceUnderscoresWithDashes(projectName)}-${replaceUnderscoresWithDashes(targetName)}`; |
103 | 112 | } |
104 | 113 |
|
105 | 114 | // ============================================================================ |
@@ -238,36 +247,18 @@ export async function copyAgentSource(options: CopyAgentSourceOptions): Promise< |
238 | 247 | if (build === 'Container') { |
239 | 248 | const destDockerfile = path.join(appDir, 'Dockerfile'); |
240 | 249 | if (!fs.existsSync(destDockerfile)) { |
241 | | - onProgress?.('Generating Dockerfile for Container build'); |
242 | | - const entryModule = path.basename(options.entrypoint ?? 'main.py', '.py'); |
243 | | - fs.writeFileSync( |
244 | | - destDockerfile, |
245 | | - [ |
246 | | - 'FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim', |
247 | | - 'WORKDIR /app', |
248 | | - '', |
249 | | - 'ENV UV_SYSTEM_PYTHON=1 \\', |
250 | | - ' UV_COMPILE_BYTECODE=1 \\', |
251 | | - ' UV_NO_PROGRESS=1 \\', |
252 | | - ' PYTHONUNBUFFERED=1 \\', |
253 | | - ' DOCKER_CONTAINER=1', |
254 | | - '', |
255 | | - 'RUN useradd -m -u 1000 bedrock_agentcore', |
256 | | - '', |
257 | | - 'COPY pyproject.toml uv.lock ./', |
258 | | - 'RUN uv sync --frozen --no-dev --no-install-project', |
259 | | - '', |
260 | | - 'COPY --chown=bedrock_agentcore:bedrock_agentcore . .', |
261 | | - 'RUN uv sync --frozen --no-dev', |
262 | | - '', |
263 | | - 'USER bedrock_agentcore', |
264 | | - '', |
265 | | - 'EXPOSE 8080 8000 9000', |
266 | | - '', |
267 | | - `CMD ["opentelemetry-instrument", "python", "-m", "${entryModule}"]`, |
268 | | - '', |
269 | | - ].join('\n') |
270 | | - ); |
| 250 | + const isPython = options.entrypoint?.endsWith('.py') ?? true; |
| 251 | + if (isPython) { |
| 252 | + onProgress?.('Generating Dockerfile for Container build'); |
| 253 | + const entryModule = path.basename(options.entrypoint ?? 'main.py', '.py'); |
| 254 | + const templatePath = getTemplatePath('container', 'python', 'Dockerfile'); |
| 255 | + const template = fs.readFileSync(templatePath, 'utf-8'); |
| 256 | + fs.writeFileSync(destDockerfile, template.replace('{{entrypoint}}', entryModule)); |
| 257 | + } else { |
| 258 | + onProgress?.( |
| 259 | + 'No Dockerfile found. Please add a Dockerfile to the source directory for non-Python container builds.' |
| 260 | + ); |
| 261 | + } |
271 | 262 | } |
272 | 263 | } |
273 | 264 | } else { |
|
0 commit comments