Skip to content

Commit d1c4e58

Browse files
Add qrencode function
* this uses the tool qrencode to generate a qr code png for a url
1 parent 89e9589 commit d1c4e58

File tree

8 files changed

+211
-17
lines changed

8 files changed

+211
-17
lines changed

functions/hub/qrencode/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/qrencode/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/qrencode/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.qrencode]}
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/qrencode/init.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(ns init
2+
(:require
3+
[babashka.process]
4+
[cheshire.core]))
5+
6+
(try
7+
(let [[json-string & args] *command-line-args*
8+
{:keys [url filename]} (cheshire.core/parse-string json-string true)]
9+
(println
10+
(-> (apply babashka.process/process
11+
{:out :string}
12+
["qrencode" "-o" (format "/project/%s" filename) url])
13+
(deref)
14+
(babashka.process/check)
15+
:out)))
16+
(catch Throwable t
17+
(binding [*out* *err*]
18+
(println (str "Error: " (.getMessage t)))
19+
(System/exit 1))))

functions/hub/qrencode/runbook.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Background
2+
3+
The `qrencode` 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=$PWD,target=/project \
14+
--entrypoint /app/result/bin/entrypoint \
15+
--workdir /project \
16+
vonwig/qrencode:latest '{"args": "-o /project/crap.png https://github.com/docker/labs-ai-tools-for-devs"}'
17+
```
18+
19+
```sh
20+
open crap.png
21+
```
22+
23+
## Build
24+
25+
```sh
26+
docker build -t vonwig/qrencode:latest .
27+
```
28+
29+
```sh
30+
# docker:command=build
31+
32+
docker buildx build \
33+
--builder hydrobuild \
34+
--platform linux/amd64,linux/arm64 \
35+
--tag vonwig/qrencode:latest \
36+
--file Dockerfile \
37+
--push .
38+
docker pull vonwig/qrencode:latest
39+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Generate a QR code for the url
2+
https://github.com/docker/labs-ai-tools-for-devs.

prompts/qrencode/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
tool_choice: auto
3+
functions:
4+
- name: qrencode
5+
description: "Generate a QR code for a URL"
6+
parameters:
7+
type: object
8+
properties:
9+
url:
10+
description: "The URL to encode"
11+
type: string
12+
filename:
13+
type: string
14+
description: "The name of the PNG file to write"
15+
container:
16+
image: vonwig/qrencode:latest
17+
---
18+

prompts/recommended_tags/README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
---
2-
extractors:
3-
tool_choice: auto
42
model: llama3.1
53
url: http://localhost:11434/v1/chat/completions
64
stream: false
75
functions:
86
- name: docker_scout_tag_recommendation
97
---
108

11-
# How to Run
12-
13-
```sh
14-
# docker:command=recommended-tags
15-
bb -m prompts run \
16-
--host-dir /Users/slim/docker/labs-make-runbook \
17-
--user jimclark106 \
18-
--platform darwin \
19-
--prompts-dir prompts/recommended_tags \
20-
--nostream
21-
```
22-
23-
```clj
24-
(core.println "hey")
25-
```

0 commit comments

Comments
 (0)