Dockerfile-prompti dynaaminen: tarkistaa onko pyproject.toml generoitu
Jos pyproject.toml puuttuu, käytetään uv pip install suoraan. COPY-rivi listaa vain oikeasti olemassa olevat .py-tiedostot. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2250,18 +2250,22 @@ ${Object.entries(generatedFiles).map(([n, c]) => `--- ${n} ---\n${c}`).join('\n\
|
||||
termLog(`\n<span style="color:#d29922;font-weight:bold">[${step6}] DevOps</span> — Dockerfile`);
|
||||
pipelineStep('tester', 'Dockerfile', 'active', 'Dockerfile');
|
||||
const mainFile = Object.keys(generatedFiles).find(f => f.includes('main') || f.includes('app')) || Object.keys(generatedFiles)[0];
|
||||
const dockerPrompt = `Write a Dockerfile for this Python project using uv package manager.
|
||||
const hasPyproject = 'pyproject.toml' in generatedFiles;
|
||||
const pyFiles = Object.keys(generatedFiles).filter(f => f.endsWith('.py'));
|
||||
const depStep = hasPyproject
|
||||
? 'COPY pyproject.toml .\nRUN uv sync --no-dev'
|
||||
: `RUN uv pip install --system fastapi uvicorn sqlalchemy`;
|
||||
const dockerPrompt = `Write a Dockerfile. Output ONLY the Dockerfile, nothing else.
|
||||
|
||||
RULES:
|
||||
- Base: python:3.12-slim
|
||||
- Install uv: COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
||||
- COPY pyproject.toml and then: RUN uv sync --no-dev
|
||||
- COPY all .py files
|
||||
- EXPOSE 8000
|
||||
- CMD ["uv", "run", "uvicorn", "${mainFile.replace('.py','')}:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
- Only output Dockerfile content, no explanations
|
||||
FROM python:3.12-slim
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
||||
WORKDIR /app
|
||||
${depStep}
|
||||
COPY ${pyFiles.join(' ')} ./
|
||||
EXPOSE 8000
|
||||
CMD ["uv", "run", "uvicorn", "${mainFile.replace('.py','')}:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
Files: ${Object.keys(generatedFiles).join(', ')}`;
|
||||
Adapt this template if needed. Project files: ${Object.keys(generatedFiles).join(', ')}`;
|
||||
const dockerfile = await kpnRun(agentPrompts.tester.model, dockerPrompt, false, 256);
|
||||
if (dockerfile) generatedFiles['Dockerfile'] = dockerfile;
|
||||
pipelineStep('tester', 'Dockerfile', 'done', 'Dockerfile', dockerfile);
|
||||
|
||||
Reference in New Issue
Block a user