File size: 1,648 Bytes
85b7ac8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | from __future__ import annotations
import random
from typing import Dict, Optional
from server.models import TaskDifficulty
from server.tasks.base import BaseTask
class DockerfileRuntimeTask(BaseTask):
NAME = "Dockerfile Runtime Errors"
DESCRIPTION = "Fix runtime/container execution issues in Dockerfiles"
DIFFICULTY = TaskDifficulty.MEDIUM
AVAILABLE_SECRETS = []
SCENARIOS = [
{
"id": "missing_workdir",
"files": [
{
"path": "Dockerfile",
"type": "dockerfile",
"content": "FROM node:18-alpine\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nCMD [\"npm\", \"start\"]",
},
{"path": "package.json", "type": "other", "content": '{"name": "app", "scripts": {"start": "node index.js"}}'},
],
"error": {
"phase": "docker_run",
"message": "Error: Cannot find module '/package.json'",
},
"expected_fixes": [
{
"file": "Dockerfile",
"type": "contains",
"expected": "WORKDIR /app",
"hint": "Set a working directory before COPY/RUN",
}
],
}
]
def load_scenario(self, scenario_id: Optional[str] = None) -> Dict:
if scenario_id:
for scenario in self.SCENARIOS:
if scenario["id"] == scenario_id:
return scenario
raise ValueError(f"Unknown scenario: {scenario_id}")
return random.choice(self.SCENARIOS)
|