about summary refs log tree commit diff
path: root/genenetwork/containers/bnw-container.scm
blob: 7999da23d0ffdb2092eff82f179fc9556e312625 (plain)
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
;;; BNW system container for the run-guix-container daemon.

#!
The BNW services (bnw-service-type, bnw-nginx-service-type with
the foreground-nginx fix) live in (genenetwork services bnw) and
are shared with the BNW VM (vms/bnw-vm.scm); the bnw package
definition stays in guix-bioinformatics/gn/packages/bnw.scm.
(This definition moved from guix-bioinformatics/gn/services.)

Build it with the channels on the load path:

  base=$HOME/guix
  guix system container --network \
    -L $base/guix-bioinformatics \
    -L $base/gn-machines \
    -L $base/contrib/guix-forge/guix \
    $base/gn-machines/genenetwork/containers/bnw-container.scm

See https://git.genenetwork.org/ for the guix repos.

Preferred on hosts running the run-guix-system-container daemon
(listening on 127.0.0.1:8900): start the built container with

  run-guix-container.rb --daemon 127.0.0.1:8900 <HASH>
  run-guix-container.rb --daemon 127.0.0.1:8900 --log <HASH>

Inspect over ssh on port 2222 with the pinned
~/hello-container-key, or check the web server on port 8881
(nginx in the foreground, php-fpm behind it).  The web UI is
protected by the Anubis AI-bot firewall (anubis? #t on the
bnw-nginx-configuration); the GeneNetwork server-to-server
endpoints (bn_genenet.php, executionprogress_default.php and
/bnw-data/) stay direct -- Anubis must not sit between GN2 and
BNW.

The legacy way (see the included bnw.service) starts the
container directly from systemd as root:

  $ guix pull
  $ cd guix-bioinformatics && git pull
  # systemctl enable --now bnw.service

for upgrades:

  $ guix pull
  $ cd guix-bioinformatics && git pull
  # systemctl restart bnw.service

The container tests live in genenetwork/services/test
(run_bnw_container_tests.sh drives the full build/start/test
cycle).
!#

(define-module (genenetwork containers bnw-container)
  #:use-module (gnu)
  #:use-module (genenetwork services bnw)
  #: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
;; 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 %bnw-banner
  "bnw-container -- GeneNetwork BNW (Bayesian network web app :8881, ssh :2222)\nThis is a container, not the host.  Exit the shell and you are back on the\nhost; the definition is gn-machines/genenetwork/containers/bnw-container.scm.\n")

(operating-system
  (host-name "bnw-container")
  (issue %bnw-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))

  ;; Minimal package set: nginx, php-fpm and bnw come in through the
  ;; services, ssh tools through the openssh service and 'herd'
  ;; through the essential shepherd service.  grep/procps are called by
  ;; php pages (e.g. home.php runs 'top|grep|cut'), graphviz 'dot' is
  ;; called by the network layout pages (see the /usr/bin/dot symlink
  ;; in the activation below).
  (packages (list bash coreutils shadow grep procps))

  (services
   (append
    (list
     (service bnw-service-type)
     (service bnw-nginx-service-type
              (bnw-nginx-configuration
               (anubis? #t))))

    ;; SSH on port 2222: 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 2222 #:banner %bnw-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)))))