Skip to content

Commit 66184b8

Browse files
Add hub functions
1 parent c4eb943 commit 66184b8

File tree

23 files changed

+792
-5
lines changed

23 files changed

+792
-5
lines changed

functions/findutils/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/findutils/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/findutils/flake.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
description = "gh cli function";
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.findutils]}
34+
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
35+
${pkgs.babashka}/bin/bb ${scripts} "$@"
36+
'';
37+
};
38+
});
39+
}

functions/findutils/init.clj

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

functions/findutils/runbook.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Background
2+
3+
The `write_file` function has wo parameters.
4+
5+
* `path`: is a relative path from some project_root
6+
* `content`: is the content that should be written into the file
7+
8+
## Usage
9+
10+
This function should be given a rw bind mount for the root of a project.
11+
12+
```sh
13+
docker run --rm \
14+
--mount type=bind,source=$PWD,target=/project \
15+
--entrypoint /app/result/bin/entrypoint \
16+
--workdir /project \
17+
vonwig/findutils:latest '{"glob":"*.md"}' find "." "-name"
18+
```
19+
20+
## Build
21+
22+
```sh
23+
docker build -t vonwig/findutils:latest .
24+
```
25+
26+
```sh
27+
# docker:command=build
28+
29+
docker buildx build \
30+
--builder hydrobuild \
31+
--platform linux/amd64,linux/arm64 \
32+
--tag vonwig/findutils:latest \
33+
--file Dockerfile \
34+
--push .
35+
docker pull vonwig/findutils:latest
36+
```

functions/github_cli/init.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
:out))
1212

1313
(try
14-
(let [[type json-string] *command-line-args*
14+
(let [[json-string type] *command-line-args*
1515
{:keys [owner name public]} (cheshire.core/parse-string json-string true)]
1616
(cond
1717
(= type "repo-create")

functions/github_cli/runbook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ docker run --rm \
1515
--entrypoint /app/result/bin/entrypoint \
1616
--workdir /project \
1717
-e GITHUB_TOKEN="$(cat ~/.secrets/github-lsp-pat)" \
18-
vonwig/github-cli:latest repo-create '{"owner":"slimslenderslacks","name":"test1","public":true}'
18+
vonwig/github-cli:latest '{"owner":"slimslenderslacks","name":"test1","public":true}' repo-create
1919
```
2020

2121
## Build

functions/hub/fasttext/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/fasttext/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/fasttext/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.fasttext]}
34+
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
35+
${pkgs.babashka}/bin/bb ${scripts} "$@"
36+
'';
37+
};
38+
});
39+
}

0 commit comments

Comments
 (0)