You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are a Platform Engineer with deep knowledge of Dockerfiles. You have access to a workspace.
74
+
Use the read, write and build tools to complete the following assignment.
75
+
76
+
- Build the Dockerfile in the provided workspace at the path: "$dockerfile"
77
+
- Optimize the Dockerfile for reducing its size, number of layers, and build time. And if possible, increasing the security level of the image by implementing best practices.
78
+
- Ensure to not downgrade any version found in the Dockerfile.
79
+
- If the Dockerfile is already optimized, just return an explanation that you couldn't optimize it.
80
+
- Make sure the Dockerfile builds correctly before going to the next step.
81
+
- If you have changes to make, write the optimized Dockerfile to the workspace, at the same path "$dockerfile".
82
+
83
+
At the end, return an explanation of the changes you made to the Dockerfile.
84
+
$extra_context
85
+
`)
86
+
87
+
returnllm
88
+
}
89
+
90
+
// Create a new PullRequest with the changes in the workspace, the given title and body, returns the PR URL
// Create a new workspace, using third-party module
31
118
ws:=dag.Workspace(githubToken, repoURL)
32
-
// Run the agent loop in the workspace
33
-
after:=dag.Llm().
34
-
WithWorkspace(ws).
35
-
WithPrompt(`
36
-
You are a Platform Engineer with deep knowledge of Dockerfiles. You have access to a workspace.
37
-
Use the read, write, build, find, create-pr tools to complete the following assignment.
119
+
originalWorkdir:=ws.Workdir()
38
120
39
-
1. Look for a Dockerfile in the workspace (use the find tool with the "*Dockerfile*" pattern).
40
-
2. Read the Dockerfile and optimize it for reducing its size, number of layers,
41
-
and build time. And if possible, increasing the security level of the image by implementing best practices.
42
-
3. Write the optimized Dockerfile to the workspace, in the same directory, replacing the original one.
43
-
4. Build the container from the optimized Dockerfile to ensure it builds.
44
-
5. Create a Pull Request with the changes in the workspace, with a useful title, the body should include the whole explanation of the changes made to the Dockerfile.
45
-
6. Return the Pull Request URL as the last message.
return"", fmt.Errorf("failed to get image info: %w", err)
159
+
}
160
+
161
+
// We consider the optimization satisfactory if the size of the image is smaller
162
+
iflastImgInfo[1] <originalImgInfo[1] {
163
+
break
164
+
}
165
+
166
+
// Otherwise we give extra context to the LLM and try again
167
+
extraContext="\n\nYou previously attempted to optimize the Dockerfile, but the changes were not satisfactory. Here are the details:\n\n"
168
+
extraContext+=fmt.Sprintf("- The number of layers is %d in the original image, and %d layers in the optimized version.\n", originalImgInfo[0], lastImgInfo[0])
169
+
extraContext+=fmt.Sprintf("- The original image size is %d bytes, and the optimized image size is %d bytes.\n\n", originalImgInfo[1], lastImgInfo[1])
170
+
extraContext+="Please make the necessary changes to the Dockerfile to improve the image size and number of layers.\n"
171
+
// FIXME: add the modified Dockerfile to the extra context?
0 commit comments