一句话:提出 DRAFT,利用 LLM 迭代修复并优化 Dockerfile,实现自动生成可成功构建的镜像。
针对项目常缺少 Dockerfile、开发者需反复试错构建的问题,论文提出 DRAFT。DRAFT 模拟开发者迭代行为:先生成初始 Dockerfile,再根据构建反馈迭代提示 LLM 生成补丁,直到成功执行;随后优化镜像体积。作者在 35 个 C、Java、Go、Python、Ruby 项目上评估,并与 Copilot、Actions_remaker、Repo2docker、Boxing、Starter 比较。DRAFT 成功为 28 个项目生成 Dockerfile,成功率 80%,显著高于对比工具;生成时间最大 19.57 分钟、中位数 33.78 秒,镜像体积减少 67.14%,构建时间减少 3.62%。该工具可减轻手工创建构建规范的负担。
Project maintainers on platforms like GitHub usually provide a document (e.g., a Readme) describing how to build and use their software, whose instructions, often written in natural language, might sometimes be ambiguous or platform-specific. This task can be eased by containerization, which allows developers to define the build environments required for their software and to enable automatic builds. Docker is the leading platform in this field and relies on Dockerfiles for correct execution. Practitioners who want to use and build projects that do not include a Dockerfile need to develop it themselves. They often need to perform multiple builds by trial and error to discover the correct build steps and build dependencies (e.g., third-party library necessary for software builds). To address this challenge, we propose a novel approach and tool called Dockerfile Refinement and Fixing Tool (DRAFT), which can automatically generate a working Dockerfile by a Large Language Model (LLM). The core idea of DRAFT is that it emulates developers’ behavior iteratively. Specifically, DRAFT is used to iteratively generate prompts to instruct the LLM to generate patches for an initially generated Dockerfile until it executes successfully. Subsequently, it attempts to optimize the Dockerfile to reduce the size of the image it builds. We evaluated DRAFT on 35 projects and compared it with the Dockerfiles generated by Copilot (based on ChatGPT 4.0), Actions_remaker, Repo2docker, Boxing, and Starter in five different languages (C, Java, Go, Python, and Ruby). The evaluation results show that DRAFT can successfully generate Dockerfiles for 28 projects, resulting in a success rate of 80%, which is much higher than all compared tools. The time consumed by DRAFT on generating Dockerfiles is 19.57 minutes at maximum with the median at 33.78s. Using DRAFT can reduce image size by 67.14% and build time by 3.62%. DRAFT relieves practitioners from the burden of manually creating build specifications.