Skip to content

Commit 00526f4

Browse files
Fix regression on in-docker tests with github prompt refs
1 parent 76993fc commit 00526f4

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

prompts/examples/qrencode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tools:
66
# Prompt user
77

88
Generate a QR code for the content
9-
'https://raw.githubusercontent.com/docker/labs-ai-tools-for-devs/main/prompts/qrencode/README.md'.
9+
'https://github.com/docker/labs-ai-tools-for-devs'.
1010
Save the generated image to `qrcode.png`.
1111
If the command fails, read the man page and try again.
1212
If successful, output the path to the generated image in markdown syntax.
@@ -16,6 +16,6 @@ If successful, output the path to the generated image in markdown syntax.
1616
After running the above prompt, there should be a file named `qrcode.png` in the current project's host directory.
1717

1818
```bash
19-
open qrcode.png
19+
open ~/vonwig/altaservice/qrcode.png
2020
```
2121

src/docker.clj

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[clojure.spec.alpha :as spec]
99
[clojure.string :as string]
1010
[creds]
11+
jsonrpc
1112
logging)
1213
(:import
1314
[java.net UnixDomainSocketAddress]
@@ -107,22 +108,23 @@
107108
;; Tty wraps the process in a pseudo terminal
108109
{:StdinOnce true
109110
:OpenStdin true}
110-
(defn create-container [{:keys [image entrypoint working-dir command host-dir env thread-id opts mounts] :or {opts {:Tty true}}}]
111+
(defn create-container [{:keys [image entrypoint working-dir command host-dir env thread-id opts mounts] :or {opts {:Tty true}} :as m}]
112+
#_(jsonrpc/notify :message {:content (str m)})
111113
(let [payload (json/generate-string
112114
(merge
113115
{:Image image}
114116
opts
115117
(when env {:env (->> env
116118
(map (fn [[k v]] (format "%s=%s" (name k) v)))
117119
(into []))})
118-
(when host-dir {:HostConfig
119-
{:Binds
120-
(concat [(format "%s:/project:rw" host-dir)
121-
"docker-lsp:/docker-lsp"
122-
"/var/run/docker.sock:/var/run/docker.sock"]
123-
(when thread-id [(format "%s:/thread:rw" thread-id)])
124-
mounts)}
125-
:WorkingDir (or working-dir "/project")})
120+
{:HostConfig
121+
{:Binds
122+
(concat ["docker-lsp:/docker-lsp"
123+
"/var/run/docker.sock:/var/run/docker.sock"]
124+
(when host-dir [(format "%s:/project:rw" host-dir)])
125+
(when thread-id [(format "%s:/thread:rw" thread-id)])
126+
mounts)}
127+
:WorkingDir (or working-dir "/project")}
126128
(when entrypoint {:Entrypoint entrypoint})
127129
(when command {:Cmd command})))]
128130
(curl/post

src/git.clj

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(ns git
22
(:require
33
[babashka.fs :as fs]
4-
[clojure.pprint :as pprint]
54
[clojure.string :as string]
65
dir
76
docker
8-
[hasch.core :as hasch]))
7+
[hasch.core :as hasch]
8+
jsonrpc))
99

1010
(set! *warn-on-reflection* true)
1111

@@ -58,18 +58,29 @@
5858

5959
(defn pull [{:keys [dir ref]}]
6060
(docker/run-container
61-
{:image "alpine/git:latest"
62-
:host-dir (str dir)
63-
:command (concat ["pull" "origin"]
64-
(when ref [ref]))}))
61+
(merge
62+
{:image "alpine/git:latest"
63+
:command (concat ["pull" "origin"]
64+
(when ref [ref]))}
65+
(if (string/starts-with? (str dir) "/prompts")
66+
{:working-dir (str dir)
67+
:mounts ["docker-prompts:/prompts:rw"]}
68+
{:host-dir (str dir)}))))
6569

6670
(defn clone [{:keys [dir owner repo ref ref-hash]}]
6771
(docker/run-container
68-
{:image "alpine/git:latest"
69-
:host-dir (str dir)
70-
:command (concat ["clone" "--depth" "1" (format "https://github.com/%s/%s" owner repo)]
71-
(when ref ["-b" ref])
72-
[(format "/project/%s" ref-hash)])}))
72+
(merge
73+
{:image "alpine/git:latest"}
74+
(if (string/starts-with? (str dir) "/prompts")
75+
{:working-dir (str dir)
76+
:command (concat ["clone" "--depth" "1" (format "https://github.com/%s/%s" owner repo)]
77+
(when ref ["-b" ref])
78+
[(format "/prompts/%s" ref-hash)])
79+
:mounts ["docker-prompts:/prompts:rw"]}
80+
{:host-dir (str dir)
81+
:command (concat ["clone" "--depth" "1" (format "https://github.com/%s/%s" owner repo)]
82+
(when ref ["-b" ref])
83+
[(format "/project/%s" ref-hash)])}))))
7384

7485
(defn prompt-file
7586
"returns the path or nil if the github ref does not resolve
@@ -78,9 +89,11 @@
7889
(when-let [{:keys [ref path] :as git-ref-map} (parse-github-ref ref)]
7990
(let [ref-hash (hashch (select-keys git-ref-map [:owner :repo :ref]))
8091
dir (fs/file (prompts-cache) ref-hash)
81-
_ (if (fs/exists? dir)
92+
m (if (fs/exists? dir)
8293
(pull {:dir dir :ref ref})
8394
(clone (merge git-ref-map {:dir (fs/parent dir) :ref-hash ref-hash})))]
95+
(when (not (= 0 (:exit-code m)))
96+
(jsonrpc/notify :error {:content (str m)}))
8497
(if path
8598
(let [cached-path (fs/file dir path)]
8699
(if (fs/exists? cached-path)

0 commit comments

Comments
 (0)