Skip to content

Commit 515bb6f

Browse files
Add clj-kondo
1 parent 66ce4ce commit 515bb6f

File tree

11 files changed

+292
-4
lines changed

11 files changed

+292
-4
lines changed

functions/hub/clj-kondo/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
# syntax = docker/dockerfile:1.4
3+
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder
4+
5+
WORKDIR /tmp/build
6+
RUN mkdir /tmp/nix-store-closure
7+
8+
# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
9+
# hadolint ignore=SC2046
10+
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
11+
--mount=type=cache,target=/root/.cache \
12+
--mount=type=bind,target=/tmp/build \
13+
<<EOF
14+
nix \
15+
--extra-experimental-features "nix-command flakes" \
16+
--option filter-syscalls false \
17+
--extra-trusted-substituters "https://cache.iog.io" \
18+
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
19+
--show-trace \
20+
--log-format raw \
21+
build . --out-link /tmp/output/result
22+
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
23+
EOF
24+
25+
FROM scratch
26+
27+
WORKDIR /app
28+
29+
COPY --from=builder /tmp/nix-store-closure /nix/store
30+
COPY --from=builder /tmp/output/ /app/
31+
32+
ENTRYPOINT ["/app/result/bin/entrypoint"]
33+
CMD ["--help"]

functions/hub/clj-kondo/flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/hub/clj-kondo/flake.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
description = "fasttext";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils, ...}@inputs:
10+
11+
flake-utils.lib.eachDefaultSystem
12+
(system:
13+
let
14+
pkgs = import nixpkgs {
15+
inherit system;
16+
};
17+
18+
in rec
19+
{
20+
packages = rec {
21+
22+
# this derivation just contains the init.clj script
23+
scripts = pkgs.stdenv.mkDerivation {
24+
name = "scripts";
25+
src = ./.;
26+
installPhase = ''
27+
cp init.clj $out
28+
'';
29+
};
30+
31+
# the script must have gh in the PATH
32+
default = pkgs.writeShellScriptBin "entrypoint" ''
33+
export PATH=${pkgs.lib.makeBinPath [pkgs.clj-kondo]}
34+
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
35+
${pkgs.babashka}/bin/bb ${scripts} "$@"
36+
'';
37+
};
38+
});
39+
}

functions/hub/clj-kondo/init.clj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(ns init
2+
(:require
3+
[babashka.fs :as fs]
4+
[babashka.process]
5+
[cheshire.core]))
6+
7+
(try
8+
(let [[json-string & args] *command-line-args*
9+
{llm-args :args} (cheshire.core/parse-string json-string true)]
10+
(let [{:keys [out err] :as p} (-> (apply babashka.process/process
11+
{:out :string :err :string}
12+
"clj-kondo"
13+
(concat llm-args
14+
["--config" (pr-str
15+
{:output {:format :json}})]))
16+
(deref))]
17+
(let [dir (fs/file "/thread/clj-kondo")]
18+
(fs/create-dirs dir)
19+
(spit (fs/file dir "lint.json") out))
20+
(println out)
21+
(when (not (= 0 (:exit p)))
22+
(binding [*out* *err*]
23+
(println err)
24+
(System/exit (:exit p))))))
25+
(catch Throwable t
26+
(binding [*out* *err*]
27+
(println (str t))
28+
(System/exit 1))))

functions/hub/clj-kondo/runbook.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Background
2+
3+
The `curl` function has one parameter.
4+
5+
* `args`: the args to send to the image
6+
7+
## Usage
8+
9+
This function should be given a rw bind mount for the root of a project.
10+
11+
```sh
12+
docker run --rm \
13+
--mount type=bind,source=/Users/slim/docker/labs-ai-tools-for-devs,target=/project \
14+
--workdir /project \
15+
vonwig/clj-kondo:latest '{"args": ["--lint","."]}' | jq .
16+
```
17+
18+
## Build
19+
20+
```sh
21+
docker build -t vonwig/clj-kondo:latest .
22+
```
23+
24+
```sh
25+
# docker:command=build
26+
27+
docker buildx build \
28+
--builder hydrobuild \
29+
--platform linux/amd64,linux/arm64 \
30+
--tag vonwig/clj-kondo:latest \
31+
--file Dockerfile \
32+
--push .
33+
docker pull vonwig/clj-kondo:latest
34+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lint the clojure code in this project by passing the arguments `--lint .`.

prompts/clj-kondo/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
extractors:
3+
- name: go-linguist
4+
- name: project-facts
5+
model: gpt-4
6+
stream: true
7+
functions:
8+
- name: clj-kondo
9+
description: "lint clojure code"
10+
parameters:
11+
type: object
12+
properties:
13+
args:
14+
type: array
15+
description: "the arguments to pass to the linter"
16+
items:
17+
type: string
18+
container:
19+
image: vonwig/clj-kondo:latest
20+
---
21+
22+
# Background
23+
24+
Ask about violations in a project that contains clojure code.
25+
26+
## Running the tool
27+
28+
```sh
29+
docker run --rm \
30+
-it \
31+
-v /var/run/docker.sock:/var/run/docker.sock \
32+
--mount type=volume,source=docker-prompts,target=/prompts \
33+
--mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \
34+
--mount type=bind,source=/Users/slim/docker/labs-ai-tools-for-devs/prompts,target=/app/local \
35+
--workdir /app \
36+
vonwig/prompts:local run \
37+
/Users/slim/docker/labs-ai-tools-for-devs \
38+
jimclark106 \
39+
"$(uname -o)" \
40+
local/clj-kondo \
41+
--pat "$(cat ~/.secrets/dockerhub-pat-ai-tools-for-devs.txt)" \
42+
--thread-id "clj-kondo" \
43+
--save-thread-volume
44+
```
45+

prompts/curl/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
extractors:
3+
- name: go-linguist
4+
- name: docker-lsp
5+
model: gpt-4
6+
stream: true
7+
functions:
8+
- name: curl
9+
description: "Run a curl command"
10+
parameters:
11+
type: object
12+
properties:
13+
args:
14+
type: string
15+
description: "The arguments to pass to curl"
16+
container:
17+
image: vonwig/curl:latest
18+
---
19+
20+
# Background
21+
22+
* read tl/dr examples
23+
* read man pages
24+
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+
## Running the tool
32+
33+
```sh
34+
DIR=$PWD
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=/Users/slim/docker/labs-make-runbook/prompts,target=/my-prompts \
40+
--workdir /my-prompts \
41+
vonwig/prompts:latest run \
42+
$DIR \
43+
$USER \
44+
"$(uname -o)" \
45+
project_type
46+
# "github:docker/labs-make-runbook?ref=main&path=prompts/curl"
47+
```

runbook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bb -m clean-local-images
4646

4747
```sh
4848
docker run --rm \
49-
-it \
49+
-it \
5050
-v /var/run/docker.sock:/var/run/docker.sock \
5151
--mount type=bind,source=$PWD,target=/app/local \
5252
--workdir /app \

src/docker.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
;; entrypoint is an array of strings
6868
;; env is a map
6969
;; Env is an array of name=value strings
70-
(defn create-container [{:keys [image entrypoint command host-dir env thread-volume]}]
70+
(defn create-container [{:keys [image entrypoint command host-dir env thread-id]}]
7171
(let [payload (json/generate-string
7272
(merge
7373
{:Image image
@@ -79,7 +79,7 @@
7979
{:Binds
8080
(concat [(format "%s:/project:rw" host-dir)
8181
"docker-lsp:/docker-lsp"]
82-
(when thread-volume (format "%s:/thread" thread-volume)))}
82+
(when thread-id [(format "%s:/thread:rw" thread-id)]))}
8383
:WorkingDir "/project"})
8484
(when entrypoint {:Entrypoint entrypoint})
8585
(when command {:Cmd command})))]

0 commit comments

Comments
 (0)