1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu tests docker)
20 #:use-module (gnu tests)
21 #:use-module (gnu system)
22 #:use-module (gnu system file-systems)
23 #:use-module (gnu system vm)
24 #:use-module (gnu services)
25 #:use-module (gnu services dbus)
26 #:use-module (gnu services networking)
27 #:use-module (gnu services docker)
28 #:use-module (gnu services desktop)
29 #:use-module (gnu packages bootstrap) ; %bootstrap-guile
30 #:use-module (gnu packages docker)
31 #:use-module (guix gexp)
32 #:use-module (guix grafts)
33 #:use-module (guix monads)
34 #:use-module (guix packages)
35 #:use-module (guix profiles)
36 #:use-module (guix scripts pack)
37 #:use-module (guix store)
38 #:use-module (guix tests)
39 #:use-module (guix build-system trivial)
40 #:export (%test-docker))
43 (simple-operating-system
44 (service dhcp-client-service-type)
47 (service elogind-service-type)
48 (service docker-service-type)))
50 (define (run-docker-test docker-tarball)
51 "Load DOCKER-TARBALL as Docker image and run it in a Docker container,
54 (marionette-operating-system
56 #:imported-modules '((gnu services herd)
63 (disk-image-size (* 1500 (expt 2 20)))
64 (port-forwardings '())))
67 (with-imported-modules '((gnu build marionette))
69 (use-modules (srfi srfi-11) (srfi srfi-64)
70 (gnu build marionette))
73 (make-marionette (list #$vm)))
80 (test-assert "service running"
83 (use-modules (gnu services herd))
84 (match (start-service 'dockerd)
86 (('service response-parts ...)
87 (match (assq-ref response-parts 'running)
88 ((pid) (number? pid))))))
91 (test-eq "fetch version"
95 (system* ,(string-append #$docker-cli "/bin/docker")
99 (test-equal "Load docker image and run it"
105 (let* ((port (apply open-pipe* OPEN_READ args))
106 (output (read-line port))
107 (status (close-pipe port)))
109 (let* ((raw-line (slurp ,(string-append #$docker-cli
113 (repository&tag (string-drop raw-line
117 ,(string-append #$docker-cli "/bin/docker")
118 "run" "--entrypoint" "bin/Guile"
125 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
127 (gexp->derivation "docker-test" test))
129 (define (build-tarball&run-docker-test)
131 ((_ (set-grafting #f))
132 (guile (set-guile-for-build (default-guile)))
133 (guest-script-package ->
134 (dummy-package "guest-script"
135 (build-system trivial-build-system)
137 `(#:guile ,%bootstrap-guile
139 (let ((out (assoc-ref %outputs "out")))
141 (call-with-output-file (string-append out "/a.scm")
143 (display "(display \"hello world\n\")" port)))
145 (profile (profile-derivation (packages->manifest
146 (list %bootstrap-guile
147 guest-script-package))
150 (tarball (docker-image "docker-pack" profile
151 #:symlinks '(("/bin/Guile" -> "bin/guile")
152 ("aa.scm" -> "a.scm"))
153 #:localstatedir? #t)))
154 (run-docker-test tarball)))
159 (description "Test Docker container of Guix.")
160 (value (build-tarball&run-docker-test))))