cloudnative-devops-debug-env / server /tasks /task_1_build_errors.py
Krishna1107's picture
inference fixed, port changed to 7860
eb895b1
"""Task 1: Dockerfile Syntax Errors — EASY.
Agent fixes common Dockerfile instruction/syntax mistakes:
typos in filenames, invalid base image tags, bad RUN syntax,
quoted EXPOSE values, missing FROM instruction.
"""
from server.models import TaskDifficulty
from server.tasks.base import BaseTask
class DockerfileSyntaxTask(BaseTask):
NAME = "Dockerfile Syntax Errors"
DESCRIPTION = "Fix syntax and instruction errors in Dockerfiles"
DIFFICULTY = TaskDifficulty.EASY
AVAILABLE_SECRETS = []
SCENARIOS = [
# Scenario 1: Typo in requirements filename
{
"id": "typo_filename",
"files": [
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.9-slim\n"
"WORKDIR /app\n"
"COPY requirments.txt .\n"
"RUN pip install --no-cache-dir -r requirements.txt\n"
"COPY . .\n"
'CMD ["python", "app.py"]'
),
},
{
"path": "requirements.txt",
"type": "requirements",
"content": "flask==2.0.0\nrequests==2.28.0",
},
],
"error": {
"phase": "docker_build",
"message": "COPY failed: file not found in build context: requirments.txt",
"exit_code": 1,
"failed_step": "COPY requirments.txt .",
"line_hint": 3,
},
"expected_fixes": [
{
"file": "Dockerfile",
"type": "contains",
"expected": "COPY requirements.txt",
"hint": "Check spelling of the requirements filename — 'requirments' vs 'requirements'",
}
],
},
# Scenario 2: Wrong base image tag (extra 'm')
{
"id": "invalid_base_image",
"files": [
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.9-slimm\n"
"WORKDIR /app\n"
"COPY requirements.txt .\n"
"RUN pip install -r requirements.txt\n"
"COPY . .\n"
"EXPOSE 7860\n"
'CMD ["python", "app.py"]'
),
},
{
"path": "requirements.txt",
"type": "requirements",
"content": "flask==2.0.0",
},
],
"error": {
"phase": "docker_build",
"message": (
"pull access denied for python:3.9-slimm, "
"repository does not exist or may require 'docker login'"
),
"exit_code": 1,
"failed_step": "FROM python:3.9-slimm",
"line_hint": 1,
},
"expected_fixes": [
{
"file": "Dockerfile",
"type": "not_contains",
"expected": "FROM python:3.9-slimm",
"hint": "The base image tag is 'slim', not 'slimm' — remove the extra 'm'",
}
],
},
# Scenario 3: && operator on its own line (invalid Dockerfile instruction)
{
"id": "invalid_run_syntax",
"files": [
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.9\n"
"WORKDIR /app\n"
"COPY . .\n"
"RUN pip install -r requirements.txt\n"
" && python setup.py install\n"
'CMD ["python", "main.py"]'
),
},
{
"path": "requirements.txt",
"type": "requirements",
"content": "numpy==1.21.0",
},
],
"error": {
"phase": "docker_build",
"message": "Dockerfile parse error: unknown instruction: &&",
"exit_code": 1,
"line_hint": 5,
},
"expected_fixes": [
{
"file": "Dockerfile",
"type": "contains",
"expected": "RUN pip install -r requirements.txt && python setup.py install",
"hint": (
"Multi-line RUN commands must use backslash continuation "
"(RUN cmd1 \\\\\\n && cmd2) or be written on one line"
),
}
],
},
# Scenario 4: COPY references a file that doesn't exist in context
{
"id": "copy_missing_source",
"files": [
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM nginx:alpine\n"
"COPY nginx.conf /etc/nginx/nginx.conf\n"
"COPY dist/ /usr/share/nginx/html\n"
"EXPOSE 80\n"
'CMD ["nginx", "-g", "daemon off;"]'
),
},
{
"path": "build/index.html",
"type": "other",
"content": "<!DOCTYPE html><html><body>Hello</body></html>",
},
],
"error": {
"phase": "docker_build",
"message": "COPY failed: file not found in build context: dist/",
"exit_code": 1,
"failed_step": "COPY dist/ /usr/share/nginx/html",
"line_hint": 3,
},
"expected_fixes": [
{
"file": "Dockerfile",
"type": "contains",
"expected": "COPY build/",
"hint": "The build output is in 'build/' not 'dist/' — check the build context files",
}
],
},
# Scenario 5: Missing FROM instruction — Dockerfile starts with WORKDIR
{
"id": "missing_from_instruction",
"files": [
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"WORKDIR /app\n"
"COPY requirements.txt .\n"
"RUN pip install -r requirements.txt\n"
"COPY . .\n"
'CMD ["python", "app.py"]'
),
},
{
"path": "requirements.txt",
"type": "requirements",
"content": "flask==2.0.0",
},
],
"error": {
"phase": "docker_build",
"message": "Dockerfile parse error: FROM is required as the first instruction",
"exit_code": 1,
"line_hint": 1,
},
"expected_fixes": [
{
"file": "Dockerfile",
"type": "contains",
"expected": "FROM python:",
"hint": "Every Dockerfile must start with a FROM instruction",
}
],
},
]