Skip to content

Commit

Permalink
Add hub functions
Browse files Browse the repository at this point in the history
  • Loading branch information
slimslenderslacks committed Jul 11, 2024
1 parent c4eb943 commit 66184b8
Show file tree
Hide file tree
Showing 23 changed files with 792 additions and 5 deletions.
33 changes: 33 additions & 0 deletions functions/findutils/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

# syntax = docker/dockerfile:1.4
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder

WORKDIR /tmp/build
RUN mkdir /tmp/nix-store-closure

# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
# hadolint ignore=SC2046
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
--mount=type=cache,target=/root/.cache \
--mount=type=bind,target=/tmp/build \
<<EOF
nix \
--extra-experimental-features "nix-command flakes" \
--option filter-syscalls false \
--extra-trusted-substituters "https://cache.iog.io" \
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
--show-trace \
--log-format raw \
build . --out-link /tmp/output/result
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
EOF

FROM scratch

WORKDIR /app

COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/output/ /app/

ENTRYPOINT ["/app/result/bin/entrypoint"]
CMD ["--help"]
61 changes: 61 additions & 0 deletions functions/findutils/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions functions/findutils/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
description = "gh cli function";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils, ...}@inputs:

flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};

in rec
{
packages = rec {

# this derivation just contains the init.clj script
scripts = pkgs.stdenv.mkDerivation {
name = "scripts";
src = ./.;
installPhase = ''
cp init.clj $out
'';
};

# the script must have gh in the PATH
default = pkgs.writeShellScriptBin "entrypoint" ''
export PATH=${pkgs.lib.makeBinPath [pkgs.findutils]}
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
${pkgs.babashka}/bin/bb ${scripts} "$@"
'';
};
});
}
24 changes: 24 additions & 0 deletions functions/findutils/init.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns init
(:require [cheshire.core]
[babashka.process]))

(defn run [args]
(-> (apply babashka.process/process
{:out :string}
args)
(deref)
(babashka.process/check)
:out))

(try
(let [[json-string & args] *command-line-args*
{:keys [glob]} (cheshire.core/parse-string json-string true)]
(println
(run
(concat
args
[glob]))))
(catch Throwable t
(binding [*out* *err*]
(println (str "Error: " (.getMessage t)))
(System/exit 1))))
36 changes: 36 additions & 0 deletions functions/findutils/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Background

The `write_file` function has wo parameters.

* `path`: is a relative path from some project_root
* `content`: is the content that should be written into the file

## Usage

This function should be given a rw bind mount for the root of a project.

```sh
docker run --rm \
--mount type=bind,source=$PWD,target=/project \
--entrypoint /app/result/bin/entrypoint \
--workdir /project \
vonwig/findutils:latest '{"glob":"*.md"}' find "." "-name"
```

## Build

```sh
docker build -t vonwig/findutils:latest .
```

```sh
# docker:command=build

docker buildx build \
--builder hydrobuild \
--platform linux/amd64,linux/arm64 \
--tag vonwig/findutils:latest \
--file Dockerfile \
--push .
docker pull vonwig/findutils:latest
```
2 changes: 1 addition & 1 deletion functions/github_cli/init.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:out))

(try
(let [[type json-string] *command-line-args*
(let [[json-string type] *command-line-args*
{:keys [owner name public]} (cheshire.core/parse-string json-string true)]
(cond
(= type "repo-create")
Expand Down
2 changes: 1 addition & 1 deletion functions/github_cli/runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ docker run --rm \
--entrypoint /app/result/bin/entrypoint \
--workdir /project \
-e GITHUB_TOKEN="$(cat ~/.secrets/github-lsp-pat)" \
vonwig/github-cli:latest repo-create '{"owner":"slimslenderslacks","name":"test1","public":true}'
vonwig/github-cli:latest '{"owner":"slimslenderslacks","name":"test1","public":true}' repo-create
```

## Build
Expand Down
33 changes: 33 additions & 0 deletions functions/hub/fasttext/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

# syntax = docker/dockerfile:1.4
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder

WORKDIR /tmp/build
RUN mkdir /tmp/nix-store-closure

# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
# hadolint ignore=SC2046
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
--mount=type=cache,target=/root/.cache \
--mount=type=bind,target=/tmp/build \
<<EOF
nix \
--extra-experimental-features "nix-command flakes" \
--option filter-syscalls false \
--extra-trusted-substituters "https://cache.iog.io" \
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
--show-trace \
--log-format raw \
build . --out-link /tmp/output/result
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
EOF

FROM scratch

WORKDIR /app

COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/output/ /app/

ENTRYPOINT ["/app/result/bin/entrypoint"]
CMD ["--help"]
61 changes: 61 additions & 0 deletions functions/hub/fasttext/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions functions/hub/fasttext/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
description = "fasttext";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils, ...}@inputs:

flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};

in rec
{
packages = rec {

# this derivation just contains the init.clj script
scripts = pkgs.stdenv.mkDerivation {
name = "scripts";
src = ./.;
installPhase = ''
cp init.clj $out
'';
};

# the script must have gh in the PATH
default = pkgs.writeShellScriptBin "entrypoint" ''
export PATH=${pkgs.lib.makeBinPath [pkgs.fasttext]}
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
${pkgs.babashka}/bin/bb ${scripts} "$@"
'';
};
});
}
19 changes: 19 additions & 0 deletions functions/hub/fasttext/init.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns init
(:require
[babashka.process]
[cheshire.core]))

(try
(let [[json-string & args] *command-line-args*
{:keys []} (cheshire.core/parse-string json-string true)]
(println
(-> (apply babashka.process/process
{:out :string}
"fasttext" args)
(deref)
(babashka.process/check)
:out)))
(catch Throwable t
(binding [*out* *err*]
(println (str "Error: " (.getMessage t)))
(System/exit 1))))
Loading

0 comments on commit 66184b8

Please sign in to comment.