diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-14 16:11:42 +0000 |
|---|---|---|
| committer | pjotr <pjotr.public01@thebird.nl> | 2026-11-14 22:05:30 +0000 |
| commit | d80efbbcde23b2839393557b25a3de41e985da7a (patch) | |
| tree | ac55eaa5994922e2ca86de20a3fa60d4ab8a3882 | |
| parent | 1d057240d0224fadc067d3c130765aec905d2865 (diff) | |
| download | gn-machines-d80efbbcde23b2839393557b25a3de41e985da7a.tar.gz | |
gn4ai.scm: a GN4AI container, MariaDB and gn-auth outside it
A store-sharing container for genenetwork4, named where the other
machine definitions are (the repo root, as asked): service on :3003, ssh
on :2223, because 3000/3001 are the host's own instances, 8081 the
gn-auth stub, 2222 another container's ssh and 3306 MariaDB.
MariaDB and gn-auth stay outside. --network shares the host's network
namespace, so 127.0.0.1 inside is the host's loopback and SQL_URI keeps
resolving; nothing here reaches into either.
Paths, because this is where containers actually break:
--expose (ro) gn4-data (42 GB), gn4-index (97 GB), the code tree (the
R/python scripts the API runs, the gn-bnw driver),
~/.julia
--share (rw) factory/gn4-container -- gn4.env (0600: SQL_URI's
password, every directory, the ports), HOME,
TMPDIR, tokens.sqlite, baskets, the Wikidata cache and
every engine cache, since a container's root is
ephemeral
gn4.env is a file rather than fields in this .scm because SQL_URI carries
a password and store paths are world-readable. HOME is in there for the
reason the slurm container taught: gemma-wrapper locks $HOME/.<hash>.lck
and dies without a writable one.
Four things that only failed at run time, each fixed here:
* a bare shepherd-service cannot go to (service ...) -- that wants a
service-type -- so it is (simple-service 'gn4ai shepherd-root-service-type
(list gn4ai-service));
* (container-ssh-service ...) returns a LIST of services, so it is
appended, not wrapped in (list ...);
* %gn4-binary must be the STORE path, not the GC-root symlink under
factory/: only the store and the listed paths are mounted inside, so
the symlink does not exist there (it fails as a 117-byte log line
saying nothing);
* the package list is the service's *runtime*, not decoration: without
python /compute/bnw answered "python3: No such file or directory" and
without gemma-wrapper /compute/gemma answered "failed to run
gemma-wrapper". Both were measured before adding python,
gemma-wrapper, r and the r-* packages the scan scripts load.
Verified against the running container: /version in 2 s, /groups/BXD
(200, database reachable through the shared netns), /compute/bnw (200, 30
edges), /compute/gemma (200, 21 055 rows), and ssh on :2223 showing the
gn4ai service started. Also adds the ai-memory store for this repo.
| -rw-r--r-- | .gitignore | 5 | ||||
| -rw-r--r-- | gn4ai.scm | 170 |
2 files changed, 175 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index eab80be..682b407 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,8 @@ genenetwork/services/test/logs/ *.log __pycache__/ + +# ai-memory store +ai-memory.sqlite +ai-memory.sqlite-wal +ai-memory.sqlite-shm diff --git a/gn4ai.scm b/gn4ai.scm new file mode 100644 index 0000000..78c6f1c --- /dev/null +++ b/gn4ai.scm @@ -0,0 +1,170 @@ +;;; gn4ai.scm -- a GN4AI (genenetwork4) system container +;;; +;;; A store-sharing container, run by the run-guix-container daemon, with the +;;; service on :3003 and ssh on :2223 (3000/3001 are the host's own instances, +;;; 8081 is the gn-auth stub, 2222 is another container's ssh, 3306 is MariaDB). +;;; +;;; MariaDB and gn-auth stay *outside*: `--network` shares the host's network +;;; namespace, so 127.0.0.1 inside the container is the host's loopback and +;;; SQL_URI still resolves. Nothing here reaches into the database. +;;; +;;; Build and start (MariaDB and the gn-auth stub must be up first): +;;; +;;; base=/home/wrk/tmp/ai-root/factory +;;; +;;; # the GN4 binary, from genenetwork4/guix.scm, pinned against GC +;;; cd $base/code/genenetwork/genenetwork4 +;;; guix build -f guix.scm --root=$base/gn4-root \ +;;; -L $base/code/guix-bioinformatics --cores=48 -M 8 +;;; +;;; cd $base/code/gn-machines +;;; guix system container -d --network \ +;;; -L $base/code/guix-bioinformatics -L $base/code/gn-machines \ +;;; --expose=$base/gn4-data=$base/gn4-data \ +;;; --expose=$base/gn4-index=$base/gn4-index \ +;;; --expose=$base/code=$base/code \ +;;; --expose=/home/wrk/.julia=/home/wrk/.julia \ +;;; --share=$base/gn4-container=$base/gn4-container \ +;;; gn4ai.scm # -> /gnu/store/...-run-container.drv +;;; guix build /gnu/store/...-run-container.drv +;;; $base/code/run-guix-container/bin/run-guix-container.rb \ +;;; --daemon 127.0.0.1:8989 --fingerprint <word> <store hash> +;;; +;;; Then, from the host: curl http://127.0.0.1:3003/version +;;; and over ssh: ssh -p 2223 -i ~/hello-container-key root@127.0.0.1 +;;; +;;; Paths: +;;; * read-only (`--expose`): the genotype files (42 GB), the Xapian index +;;; (97 GB), the code tree (for the scripts the API runs, the gn-bnw +;;; driver, run-guix-container), and the Julia depot; +;;; * read-write (`--share`): $base/gn4-container -- the env file, HOME, +;;; TMPDIR, the token registry, baskets, the Wikidata cache and every +;;; engine cache. A container's own root is ephemeral, so nothing that +;;; must survive a restart lives in it. +;;; +;;; `--expose`/`--share` drop a host path that does not exist *silently*, so +;;; every path above has to be created before START: `--share` of +;;; $base/gn4-container is the only one that must be writable, and the check +;;; is `ls` inside the container. +;;; +;;; Configuration is in $base/gn4-container/gn4.env (mode 0600, sourced by the +;;; wrapper below), not in this file: it carries SQL_URI's password, and store +;;; paths are world-readable. + +(use-modules (gnu) + (gnu services base) + (gnu services shepherd) + (gnu services sysctl) + (genenetwork services container-ssh) + (guix gexp)) +;; The service's runtime: python for the plotters, gemma-wrapper (and gemma +;; behind it) for /compute/gemma, R and the R packages the scan scripts load. +(use-package-modules base bash admin linux python cran statistics) +;; gemma-wrapper lives in (gn packages gemma) -- guix-bioinformatics, not the +;; guix channel -- which is why the build needs -L for that checkout. +(use-modules (gn packages gemma)) + +;; The GN4 binary as built above and pinned by --root, so a `guix gc` cannot +;; take it away underneath the container. A store-sharing container: the OS +;; here is minimal and every program it runs is a reference into the host +;; store, which is what makes rebuilds cheap and this file short. +;; The store path, *not* the GC-root symlink (`.../gn4-root/bin/genenetwork4`): +;; only the store and the listed paths are mounted inside the container, so a +;; symlink under `factory/` does not exist there. The `--root` from the build +;; above is what keeps this path alive across a `guix gc`. +(define %gn4-binary + "/gnu/store/y0drkwyhib43sg8micrnhd227mmhp1mf-genenetwork4-git-0.1.0/bin/genenetwork4") + +(define %gn4-env-file + "/home/wrk/tmp/ai-root/factory/gn4-container/gn4.env") + +(define %gn4-log-file + "/home/wrk/tmp/ai-root/factory/gn4-container/log/gn4ai.log") + +;; The wrapper: source the environment file, then exec. `set -a` exports +;; everything it defines, which is how a file of plain KEY=VALUE lines becomes +;; the service's environment without any of it being baked into the store. +(define %gn4-start + (program-file + "gn4ai-start" + #~(begin + (execl #$(file-append bash "/bin/bash") + "bash" "-c" + (string-append "set -eu; set -a; . " #$%gn4-env-file + "; set +a; exec " #$%gn4-binary))))) + +(define gn4ai-service + (shepherd-service + (provision '(gn4ai)) + ;; After the network: the service needs 127.0.0.1 (MariaDB, gn-auth). In a + ;; container the network is the host's namespace, up before shepherd runs. + (requirement '(user-processes)) + (start #~(make-forkexec-constructor + (list #$%gn4-start) + #:log-file #$%gn4-log-file)) + (stop #~(make-kill-destructor)) + ;; A crash should not leave the container "running" with a dead service; the + ;; log file above is where to look, and it is on the shared path. + (respawn? #t))) + +(operating-system + (host-name "gn4ai-container") + (timezone "Etc/UTC") + (locale "en_US.utf8") + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (targets '("/dev/sdX")))) + (file-systems (cons (file-system + (device (file-system-label "does-not-matter")) + (mount-point "/") + (type "ext4")) + %base-file-systems)) + + ;; The binary is invoked by absolute store path, but the *engines it shells + ;; out to* are looked up on PATH -- so this is not a package list, it is the + ;; service's runtime, and leaving one out turns a working endpoint into a 502 + ;; naming the missing program (measured: /compute/bnw answered "python3: No + ;; such file or directory", /compute/gemma "failed to run gemma-wrapper"). + ;; bash/coreutils/grep/procps/shadow are also what a person ssh-ing in + ;; expects; 'herd' arrives with the shepherd service. + (packages (list bash coreutils grep procps shadow + python ; /plot/*, /compute/bulklmm, the gn-bnw driver + gemma-wrapper ; /compute/gemma: gemma-wrapper, and gemma behind it + r ; Rscript: /compute/rqtl, /compute/qtl2, /compute/fitqtl + r-qtl r-qtl2 r-optparse r-stringr r-stringi r-digest r-jsonlite)) + + (services + (append + (list + ;; A plain shepherd-service, not a service-type: `simple-service` is how + ;; one is added to the shepherd root (the same shape the sysctl/udev + ;; no-ops below use). + (simple-service 'gn4ai shepherd-root-service-type (list gn4ai-service))) + + ;; SSH on 2223: password-less root login with hello-container-key and the + ;; pinned ECDSA host key, shared with the other containers. This procedure + ;; returns a *list* of services, so it is `append`ed, not wrapped in one. + (container-ssh-service #:port-number 2223) + + (list + ;; In a container sysctl (writes /proc/sys) and udev (coldplug on the + ;; static /dev the runtime provides) hang the boot: user-processes waits + ;; for urandom-seed, which waits for udev. No-ops instead. + (simple-service 'container-sysctl + shepherd-root-service-type + (list (shepherd-service + (provision '(sysctl)) + (one-shot? #t) + (start #~(const #t))))) + (simple-service 'container-udev + shepherd-root-service-type + (list (shepherd-service + (provision '(udev)) + (one-shot? #t) + (start #~(const #t)))))) + (modify-services %base-services + ;; The guix service runs `guix archive --generate-key' at every boot, + ;; which stalls a container, and a minimal container needs no daemon. + (delete guix-service-type) + (delete sysctl-service-type) + (delete udev-service-type))))) |
