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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
;;; genenetwork-machines --- Guix configuration for genenetwork machines
;;; Copyright © 2026 The GeneNetwork team
;;;
;;; This file is part of genenetwork-machines.
;;;
;;; genenetwork-machines is free software: you can redistribute it
;;; and/or modify it under the terms of the GNU General Public License
;;; as published by the Free Software Foundation, either version 3 of
;;; the License, or (at your option) any later version.
;;;
;;; genenetwork-machines is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty
;;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with genenetwork-machines. If not, see
;;; <https://www.gnu.org/licenses/>.
;;; A throwaway Guix system container that serves the prebuilt JBrowse 2
;;; web app (`jbrowse-web' from guix-bioinformatics/gn/packages/jbrowse.scm)
;;; with nginx, plus sshd so it can be inspected.
;;;
;;; Build it with both checkouts on the load path
;;;
;;; guix system container --network \
;;; -L factory/code/guix-bioinformatics \
;;; -L factory/code/gn-machines \
;;; factory/code/gn-machines/specials/jbrowse2-container.scm
;;;
;;; then start it through the run-guix-system-container daemon (see
;;; ../../run-guix-container/README.md):
;;;
;;; run-guix-container.rb --daemon 127.0.0.1:8989 <HASH>
;;; ssh -p 2225 -i ~/hello-container-key root@127.0.0.1
;;;
;;; The app is on http://127.0.0.1:8080/ (container and host share the
;;; network namespace under `guix system container --network', so 8080
;;; must be free on the host). Out of the box it loads the config the
;;; upstream release ships (a remote hg19 demo); for a fully offline
;;; demo use the volvox data that comes with the package:
;;;
;;; http://127.0.0.1:8080/?config=test_data/volvox/config.json
;;;
;;; The served config.json is /srv/jbrowse/config.json -- editable in a
;;; running container, and shareable from the host with
;;; `--share=/export/jbrowse=/srv/jbrowse'. It is seeded at first boot
;;; from the release's own test_data/config.json and never overwritten.
;;;
;;; `herd status nginx' must show "running"; this container runs PID 1
;;; with shepherd-for-containers because the stock shepherd 1.0.9 hangs
;;; on nginx's `nginx -t' one-shot inside nested containers (see the
;;; comment in ../genenetwork/packages.scm).
(use-modules (guix)
(gnu)
(guix gexp)
(gnu services)
(gnu services base)
(gnu services shepherd)
(gnu services sysctl)
(gnu services web)
(gnu packages admin)
(gnu packages base)
(gnu packages bash)
(gnu packages curl)
(gnu packages ssh)
(gnu packages web)
(gn packages jbrowse)
(genenetwork packages)
(genenetwork services container-ssh)
(genenetwork services nginx))
(define %web-port "8080")
(define %jbrowse-nginx-server
(nginx-server-configuration
(listen (list %web-port))
;; The prebuilt app is a plain directory tree in the store.
(root #~(string-append #$jbrowse-web "/share/jbrowse-web"))
(index (list "index.html"))
;; Single-page app: unknown paths fall back to index.html, which
;; carries the router.
(server-tokens? #f)
(try-files (list "$uri" "$uri/" "/index.html"))
(locations
(list
;; JBrowse fetches "config.json" relative to index.html. Keep
;; that one file outside the read-only store so it can be edited
;; (or bind-mounted from the host).
(nginx-location-configuration
(uri "= /config.json")
(body (list "alias /srv/jbrowse/config.json;")))
;; The webpack bundles are content-hashed, so they can be cached
;; forever; a missing bundle must 404 rather than fall back to
;; index.html (that would hand out HTML where JS is expected).
(nginx-location-configuration
(uri "/static/")
(body (list "try_files $uri =404;"
;; One header only: 'expires' would add a second
;; Cache-Control next to the add_header below.
"add_header Cache-Control \"public, max-age=31536000, immutable\";")))
;; index.html itself must always be revalidated, otherwise a
;; rebuilt container keeps serving the old bundle references.
(nginx-location-configuration
(uri "= /index.html")
(body (list "add_header Cache-Control \"no-cache\";")))))
(raw-content
(list "gzip on;"
"gzip_types application/javascript text/css application/json;"
;; The app needs no server-side routing; nothing to rewrite.
"client_max_body_size 32m;"))))
;; 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 %jbrowse2-banner
"jbrowse2-container -- JBrowse 2 genome browser (:8080, ssh :2225)\nThis is a container, not the host. Exit the shell and you are back on the\nhost; the definition is gn-machines/specials/jbrowse2-container.scm.\n")
(operating-system
(host-name "jbrowse2-container")
(issue %jbrowse2-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). Without it the
;; stock nginx service never leaves "starting".
(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)))))
;; Users are mandatory in an OS declaration. Give root a password so
;; we can also fall back to password login ("jbrowse") when the key
;; does not work.
(users (cons (user-account
(name "root")
(uid 0)
(group "root")
(password (crypt "jbrowse" "$6$abc$0123456789abcdef$")))
%base-user-accounts))
;; %base-packages keeps the container usable for debugging (bash,
;; coreutils, grep, ...); jbrowse-web comes in through the nginx
;; configuration as well, but name it explicitly so the closure is
;; obvious. `curl' is for probing the app over ssh; drop it once
;; the container is known good.
(packages
(cons* jbrowse-web bash coreutils grep curl openssh %base-packages))
(services
(append
(list
;; The stock nginx front-end for the JBrowse app.
(service nginx-service-type
(nginx-configuration
(server-blocks (list %jbrowse-nginx-server))))
;; Seed /srv/jbrowse/config.json at first boot, from the release's
;; own demo config. Existing files are left alone, so a config
;; bind-mounted with --share survives reboots.
(simple-service 'jbrowse-config
activation-service-type
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
(mkdir-p "/srv/jbrowse")
(let ((config "/srv/jbrowse/config.json"))
(unless (file-exists? config)
(copy-file
#$(file-append
jbrowse-web
"/share/jbrowse-web/test_data/config.json")
config)
(chmod config #o644)))))))
;; SSH on port 2225 (BNW 2222, genecup 2223, cgit 2224):
;; password-less root login with the pinned client 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.
;; The keys are taken from run-guix-container/etc/ instead of $HOME
;; so the container can be built by anyone with the two checkouts:
;;
;; ssh -p 2225 -i factory/code/run-guix-container/etc/hello-container-key \
;; root@127.0.0.1
(container-ssh-service
#:port-number 2225
#:host-key (local-file "../../run-guix-container/etc/ssh-container-key"
"ssh_host_ecdsa_key")
#:host-key.pub (local-file "../../run-guix-container/etc/ssh-container-key.pub"
"ssh_host_ecdsa_key.pub")
#:authorized-key (local-file "../../run-guix-container/etc/hello-container-key.pub"
"authorized_keys")
#:banner %jbrowse2-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 stalled the container
;; boot; a minimal container does not need guix-daemon anyway.
(delete guix-service-type)
(delete sysctl-service-type)
(delete udev-service-type)))))
|