1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
;;; GeneCup system container for the run-guix-container daemon.
#!
The GeneCup services (genecup-service-type, genecup-nginx-service-type)
live in (genenetwork services genecup) and are shared with a GeneCup
VM; the genecup-gemini package definition lives in
guix-bioinformatics/gn/packages/genecup.scm, pinned to commits of
https://git.genenetwork.org/genecup.
Build it with the three checkouts on the load path. Their layout
varies per host, so pick BASE and FORGE first; -L must point at the
directory that *contains* the module trees (forge/, gn/, genenetwork/):
# checkouts side by side, guix-forge as a sub-checkout (factory)
base=$HOME/guix; forge=$base/contrib/guix-forge/guix
# ... or the same checkouts flat in one directory (e.g. balg01,
# ~/services/genecup-service/{genecup,gn-machines,
# guix-bioinformatics,guix-forge})
# base=$HOME/services/genecup-service; forge=$base/guix-forge/guix
guix system container --network \
-L $base/guix-bioinformatics \
-L $base/gn-machines \
-L $forge \
$base/gn-machines/genenetwork/containers/genecup-container.scm
A wrong -L does not say so: (genenetwork services genecup) fails to
compile (its own (forge anubis) import is missing), the module then
loads empty and guix reports only
error: genecup-service-type: unbound variable
so verify the paths before blaming the definition. With the right
paths these must print the service types:
guix repl -L $base/guix-bioinformatics -L $base/gn-machines -L $forge <<'EOF'
(use-modules (genenetwork services genecup))
(display (list genecup-service-type genecup-nginx-service-type))
EOF
Preferred on hosts running the run-guix-system-container daemon
(listening on 127.0.0.1:8900, or 8989 on the reduced AI box): start the
built container with
run-guix-container.rb --daemon 127.0.0.1:8989 <HASH>
run-guix-container.rb --daemon 127.0.0.1:8989 --log <HASH>
Inspect over ssh on port 2223 with the pinned ~/hello-container-key,
or check the web server on port 4201 (nginx,
proxying to the Flask app on 127.0.0.1:4202). The web UI can be
protected by the Anubis AI-bot firewall (anubis? #t on the
genecup-nginx-configuration).
The Flask app keeps its writable state (userspub.sqlite, per-user
folders) in /var/lib/genecup. Optional local PubMed archive: add
--share=/export3/PubMed=/export3/PubMed
to the 'guix system container' invocation and set the pubmed-archive
field to "/export3/PubMed/Source" -- otherwise edirect queries NCBI
over the network.
The Gemini API key is read by the app from
~/.config/gemini/credentials of the 'genecup' user, i.e.
/var/lib/genecup/.config/gemini/credentials, mode 0400 (the app exits
when the mode is anything else). Expose the host's key read-only and
let the genecup activation copy it into place with the right owner and
mode -- a secret must not go into the store:
--expose=$HOME/.config/gemini/credentials=/run/secrets/gemini-credentials
Without it GeneCup still runs; only the LLM synthesis features are
disabled. Either way the one-shot 'gemini-check' shepherd service
reports at boot whether the key is present and whether the API accepts
it ("Gemini classification available"/"... not available: <reason>")
to the boot log and /var/log/gemini-check.log.
!#
(define-module (genenetwork containers genecup-container)
#:use-module (gnu)
#:use-module (genenetwork services genecup)
#:use-module (genenetwork packages)
#:use-module (genenetwork services nginx)
#:use-module (gnu services web)
#:use-module (genenetwork services container-ssh)
#:use-module (guix gexp)
#:use-module (guix build utils)
#:use-module (gnu services base)
#:use-module (gnu services shepherd)
#:use-module (gnu services sysctl))
(use-package-modules base bash admin linux)
;; The pinned SSH keys live in the building user's $HOME and are
;; fetched from there at build time; container-ssh-service (shared
;; with the other containers) wires them into sshd. See the Keys
;; section of genenetwork/containers/cgit-container.scm.
;; What this container is, said once. A store path is a hash and a pid says
;; nothing; this string is the OS's issue field and the ssh banner, and the
;; shared container-ssh-service also prints it as the first line of the boot log.
(define %genecup-banner
"genecup-container -- GeneNetwork genecup (web :4201, ssh :2223)\nThis is a container, not the host. Exit the shell and you are back on the\nhost; the definition is gn-machines/genenetwork/containers/genecup-container.scm.\n")
(operating-system
(host-name "genecup-container")
(issue %genecup-banner)
(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))
;; Run PID 1 with the self-pipe signal variant: see
;; shepherd-for-containers in (genenetwork packages). Everything
;; else about the system's shepherd is the stock one.
(essential-services
(modify-services (operating-system-default-essential-services
this-operating-system)
(shepherd-root-service-type config =>
(shepherd-configuration
(inherit config)
(shepherd shepherd-for-containers)))))
;; Minimal package set: the genecup package (with its Python
;; closure, edirect and minipubmed) comes in through the services,
;; ssh tools through the openssh service and 'herd' through the
;; essential shepherd service.
(packages (list bash coreutils shadow grep procps))
(services
(append
(list
;; The stock nginx front-end; genecup-nginx-service-type below
;; contributes its nginx-server-configuration sites to it.
;; Larger searches post sizeable ontologies; stay safe.
(service nginx-service-type
(nginx-configuration
(extra-content (list (client-max-body-size "32m")))))
(service genecup-service-type
(genecup-configuration
;; Exposed read-only by the launcher (see the --expose
;; flag in the header); the activation copies it to
;; /var/lib/genecup/.config/gemini/credentials (0400).
(gemini-credentials "/run/secrets/gemini-credentials")))
(service genecup-nginx-service-type
(genecup-nginx-configuration
(port "4201")
(app-port "4202")
;; Production runs behind a TLS-terminating proxy and
;; keeps Secure cookies; set to #f for plain-HTTP test
;; deployments (see bnw-container.scm).
(anubis? #t)
(anubis-cookie-secure? #f)))) ; TEMP test
;; SSH on port 2223 (BNW uses 2222, cgit 2224): password-less root
;; login with hello-container-key, the pinned ECDSA host key (not
;; generated at boot) and the /var/empty fix -- all shared with the
;; other containers via container-ssh-service.
(container-ssh-service #:port-number 2223 #:banner %genecup-banner)
(list
;; In a container sysctl (writes /proc/sys) and udev (coldplug on
;; the static /dev the container runtime sets up) are useless and
;; their start-up hangs the whole boot: urandom-seed requires
;; udev, user-processes requires urandom-seed, and ssh-daemon
;; requires user-processes. Provide 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
;; Drop the guix service: its activation runs 'guix archive
;; --generate-key' at every boot, which stalls the container
;; boot; a minimal container does not need guix-daemon anyway.
(delete guix-service-type)
(delete sysctl-service-type)
(delete udev-service-type)))))
|