Skip to content

Commit 6b6a424

Browse files
Pull images without creds when not opted in
* Update curl prompts * test pulling new function images after cleaning
1 parent cd6fd7f commit 6b6a424

File tree

6 files changed

+38
-56
lines changed

6 files changed

+38
-56
lines changed

dev/clean_local_images.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
"vonwig/fasttext"
1717
"vonwig/typos"
1818
"vonwig/what-is-my-ip"
19-
"vonwig/findutils"})
19+
"vonwig/findutils"
20+
"vonwig/qrencode"
21+
"vonwig/curl"
22+
"vonwig/standardjs"
23+
"vonwig/eslint"
24+
"vonwig/git"
25+
"vonwig/clj-kondo"
26+
"vonwig/extractor-eslint"})
2027

2128
(comment
2229
(docker/delete-image {:image "vonwig/function_write_files"}))

prompts/curl/100_user_prompts.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
Run the curl command to fetch https://www.example.com
1+
Run the curl command to fetch gists for user slimslenderslacks from GitHub.
22

3-
If you get an error, run `curl --help` and use the output to try again.

prompts/curl/README.md

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
11
---
2-
extractors:
3-
- name: linguist
4-
- name: project-facts
52
model: gpt-4
63
stream: true
74
functions:
85
- name: curl
9-
description: "Run a curl command"
6+
description: "Run a curl command."
107
parameters:
118
type: object
129
properties:
1310
args:
14-
type: string
15-
description: "The arguments to pass to curl"
11+
type: string
12+
description: "The arguments to pass to curl"
1613
container:
1714
image: vonwig/curl:latest
1815
---
1916

2017
# Background
2118

19+
Run curl commands.
20+
21+
* read the contents of `curl --help`
2222
* read tl/dr examples
2323
* read man pages
2424

25-
After ragging the above content, do we know enough about curl to create and run curl examples.
26-
27-
Also, what about defining outcomes and having the tool verify that we actually ran this correctly and got the expected results?
28-
29-
At the end, we should report the command line, and the version of curl that we used.
30-
31-
## How to run
25+
After ragging the above content, do we know enough about curl to create and run curl examples?
3226

33-
```sh
34-
# docker:command=curl
35-
docker run --rm -it \
36-
-v /var/run/docker.sock:/var/run/docker.sock \
37-
--mount type=volume,source=docker-prompts,target=/prompts \
38-
--mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \
39-
--mount type=bind,source=$PWD,target=/app/local \
40-
--workdir /app \
41-
vonwig/prompts:latest run \
42-
--host-dir $PWD \
43-
--user $USER \
44-
--platform "$(uname -o)" \
45-
--prompts-dir local
46-
# "github:docker/labs-make-runbook?ref=main&path=prompts/curl"
47-
```

prompts/dockerfiles/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,3 @@ These prompts add Dockerfile authoring skills to the assistant.
1717
* the [user prompts](100_user_prompt.md) direct the assist to extract details about the project, and then write a Dockerfile to the root of the project.
1818
* the [npm best practices](npm-best-practices.md) is are added to the system prompts whenever the assist detects that this is an NPM project.
1919

20-
## functions
21-
22-
These instructions in these prompts rely on 3 functions
23-
24-
1. `analyze_project` - requires read-only access to the project and extracts details from the project to give the assistant context for authoring the Dockerfile
25-
2. `write_files` - has read-write access to the project and will write Dockerfiles so that developers don't have to copy and paste data out of a chat.
26-
3. `docker_scout_tag_recommendation` - uses Docker Scout to improve the choice tag selection during code generation.

runbook.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ docker run --rm \
158158
"$(uname -o)" \
159159
local/prompts/eslint \
160160
--pat "$(cat ~/.secrets/dockerhub-pat-ai-tools-for-devs.txt)" \
161-
--thread-id "something" \
162-
--save-thread-volume
161+
--thread-id "something"
163162
```
164163

165164
# Test bad commands

src/docker.clj

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@
2525
(defn pull-image [{:keys [image identity-token creds]}]
2626
(curl/post
2727
(format "http://localhost/images/create?fromImage=%s" image)
28-
{:raw-args ["--unix-socket" "/var/run/docker.sock"]
29-
:throw false
30-
:headers {"X-Registry-Auth"
31-
;; I don't think we'll be pulling images
32-
;; from registries that support identity tokens
33-
(-> (cond
34-
identity-token {:identitytoken identity-token}
35-
creds creds)
36-
(json/generate-string)
37-
(encode))}}))
28+
(merge
29+
{:raw-args ["--unix-socket" "/var/run/docker.sock"]
30+
:throw false}
31+
(when (or creds identity-token)
32+
{:headers {"X-Registry-Auth"
33+
;; I don't think we'll be pulling images
34+
;; from registries that support identity tokens
35+
(-> (cond
36+
identity-token {:identitytoken identity-token}
37+
creds creds)
38+
(json/generate-string)
39+
(encode))}}))))
3840

3941
(comment
4042
(let [pat (string/trim (slurp "/Users/slim/.secrets/dockerhub-pat-ai-tools-for-devs.txt"))]
@@ -100,8 +102,8 @@
100102

101103
(defn remove-volume [{:keys [Name]}]
102104
(curl/delete (format "http://localhost/volumes/%s" Name)
103-
{:raw-args ["--unix-socket" "/var/run/docker.sock"]
104-
:throw false}))
105+
{:raw-args ["--unix-socket" "/var/run/docker.sock"]
106+
:throw false}))
105107

106108
(defn inspect-container [{:keys [Id]}]
107109
(curl/get
@@ -174,10 +176,13 @@
174176
:req-un [::image]))
175177

176178
(defn run-function [m]
177-
(when (and (:user m) (and (not (:offline m)) (or (:pat m) (creds/credential-helper->jwt))))
178-
(pull (assoc m :creds {:username (:user m)
179-
:password (or (:pat m) (creds/credential-helper->jwt))
180-
:serveraddress "https://index.docker.io/v1/"})))
179+
(pull (merge m
180+
{:serveraddress "https://index.docker.io/v1/"}
181+
(let [jwt (creds/credential-helper->jwt)]
182+
(when (and (:user m)
183+
(or (:pat m) jwt))
184+
{:creds {:username (:user m)
185+
:password (or (:pat m) jwt)}}))))
181186
(let [x (create m)]
182187
(start x)
183188
(wait x)

0 commit comments

Comments
 (0)