2019-01-10 02:44:20 +00:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2019-01-10 22:30:43 +00:00
|
|
|
|
;;; Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
2023-05-06 13:07:09 +00:00
|
|
|
|
;;; Copyright © 2019-2023 Ludovic Courtès <ludo@gnu.org>
|
2024-05-03 22:11:17 +00:00
|
|
|
|
;;; Copyright © 2024 Giacomo Leidi <goodoldpaul@autistici.org>
|
2019-01-10 02:44:20 +00:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix 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.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (gnu tests docker)
|
2021-12-16 12:37:10 +00:00
|
|
|
|
#:use-module (gnu image)
|
2019-01-10 02:44:20 +00:00
|
|
|
|
#:use-module (gnu tests)
|
|
|
|
|
#:use-module (gnu system)
|
|
|
|
|
#:use-module (gnu system file-systems)
|
2021-12-16 12:37:10 +00:00
|
|
|
|
#:use-module (gnu system image)
|
2019-01-10 02:44:20 +00:00
|
|
|
|
#:use-module (gnu system vm)
|
|
|
|
|
#:use-module (gnu services)
|
|
|
|
|
#:use-module (gnu services dbus)
|
|
|
|
|
#:use-module (gnu services networking)
|
|
|
|
|
#:use-module (gnu services docker)
|
2019-01-10 04:10:03 +00:00
|
|
|
|
#:use-module (gnu services desktop)
|
2024-05-03 22:11:17 +00:00
|
|
|
|
#:use-module (gnu packages)
|
2020-11-06 15:12:10 +00:00
|
|
|
|
#:use-module ((gnu packages base) #:select (glibc))
|
2019-05-12 10:21:48 +00:00
|
|
|
|
#:use-module (gnu packages guile)
|
2020-11-06 15:12:10 +00:00
|
|
|
|
#:use-module (gnu packages docker)
|
2019-01-10 02:44:20 +00:00
|
|
|
|
#:use-module (guix gexp)
|
2019-01-14 14:44:16 +00:00
|
|
|
|
#:use-module (guix grafts)
|
|
|
|
|
#:use-module (guix monads)
|
|
|
|
|
#:use-module (guix packages)
|
|
|
|
|
#:use-module (guix profiles)
|
2021-12-16 12:37:10 +00:00
|
|
|
|
#:use-module ((guix scripts pack) #:prefix pack:)
|
2019-01-10 02:44:20 +00:00
|
|
|
|
#:use-module (guix store)
|
2019-01-14 14:44:16 +00:00
|
|
|
|
#:use-module (guix tests)
|
|
|
|
|
#:use-module (guix build-system trivial)
|
2019-01-18 17:12:15 +00:00
|
|
|
|
#:use-module ((guix licenses) #:prefix license:)
|
2019-05-12 10:21:48 +00:00
|
|
|
|
#:export (%test-docker
|
2024-05-03 22:11:17 +00:00
|
|
|
|
%test-docker-system
|
|
|
|
|
%test-oci-container))
|
2019-01-10 02:44:20 +00:00
|
|
|
|
|
|
|
|
|
(define %docker-os
|
|
|
|
|
(simple-operating-system
|
|
|
|
|
(service dhcp-client-service-type)
|
2023-02-25 18:58:13 +00:00
|
|
|
|
(service dbus-root-service-type)
|
2023-02-25 18:58:04 +00:00
|
|
|
|
(service polkit-service-type)
|
2019-01-10 04:10:03 +00:00
|
|
|
|
(service elogind-service-type)
|
2024-06-02 06:15:54 +00:00
|
|
|
|
(service containerd-service-type)
|
2019-01-10 02:44:20 +00:00
|
|
|
|
(service docker-service-type)))
|
|
|
|
|
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(define (run-docker-test docker-tarball)
|
|
|
|
|
"Load DOCKER-TARBALL as Docker image and run it in a Docker container,
|
|
|
|
|
inside %DOCKER-OS."
|
2019-01-10 02:44:20 +00:00
|
|
|
|
(define os
|
|
|
|
|
(marionette-operating-system
|
2021-12-16 12:37:10 +00:00
|
|
|
|
(operating-system-with-gc-roots
|
|
|
|
|
%docker-os
|
|
|
|
|
(list docker-tarball))
|
2019-01-10 02:44:20 +00:00
|
|
|
|
#:imported-modules '((gnu services herd)
|
|
|
|
|
(guix combinators))))
|
|
|
|
|
|
|
|
|
|
(define vm
|
|
|
|
|
(virtual-machine
|
|
|
|
|
(operating-system os)
|
2021-12-16 12:37:10 +00:00
|
|
|
|
(volatile? #f)
|
|
|
|
|
(memory-size 1024)
|
|
|
|
|
(disk-image-size (* 3000 (expt 2 20)))
|
2019-01-10 02:44:20 +00:00
|
|
|
|
(port-forwardings '())))
|
|
|
|
|
|
|
|
|
|
(define test
|
|
|
|
|
(with-imported-modules '((gnu build marionette))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (srfi srfi-11) (srfi srfi-64)
|
|
|
|
|
(gnu build marionette))
|
|
|
|
|
|
|
|
|
|
(define marionette
|
2022-06-24 04:43:23 +00:00
|
|
|
|
;; Relax timeout to accommodate older systems.
|
|
|
|
|
(make-marionette (list #$vm) #:timeout 60))
|
2019-01-10 02:44:20 +00:00
|
|
|
|
|
tests: Reduce boilerplate for users of 'system-test-runner'.
* gnu/tests/audio.scm, gnu/tests/base.scm, gnu/tests/ci.scm,
gnu/tests/cups.scm, gnu/tests/databases.scm, gnu/tests/desktop.scm,
gnu/tests/dict.scm, gnu/tests/docker.scm, gnu/tests/file-sharing.scm,
gnu/tests/ganeti.scm, gnu/tests/guix.scm, gnu/tests/ldap.scm,
gnu/tests/linux-modules.scm,
gnu/tests/mail.scm, gnu/tests/messaging.scm, gnu/tests/monitoring.scm,
gnu/tests/networking.scm, gnu/tests/nfs.scm,
gnu/tests/package-management.scm, gnu/tests/reconfigure.scm,
gnu/tests/rsync.scm, gnu/tests/security-token.scm,
gnu/tests/singularity.scm, gnu/tests/ssh.scm, gnu/tests/telephony.scm,
gnu/tests/version-control.scm, gnu/tests/virtualization.scm,
gnu/tests/web.scm: Remove (mkdir #$output) (chdir #$output) and
pass #$output as argument to 'system-test-runner'.
2021-09-26 21:20:56 +00:00
|
|
|
|
(test-runner-current (system-test-runner #$output))
|
2019-01-10 02:44:20 +00:00
|
|
|
|
(test-begin "docker")
|
|
|
|
|
|
2024-06-02 06:15:54 +00:00
|
|
|
|
(test-assert "containerd service running"
|
|
|
|
|
(marionette-eval
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(match (start-service 'containerd)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(('service response-parts ...)
|
|
|
|
|
(match (assq-ref response-parts 'running)
|
|
|
|
|
((pid) (number? pid))))))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(test-assert "containerd PID file present"
|
|
|
|
|
(wait-for-file "/run/containerd/containerd.pid" marionette))
|
|
|
|
|
|
|
|
|
|
(test-assert "dockerd service running"
|
2019-01-10 02:44:20 +00:00
|
|
|
|
(marionette-eval
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(match (start-service 'dockerd)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(('service response-parts ...)
|
|
|
|
|
(match (assq-ref response-parts 'running)
|
|
|
|
|
((pid) (number? pid))))))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(test-eq "fetch version"
|
|
|
|
|
0
|
|
|
|
|
(marionette-eval
|
|
|
|
|
`(begin
|
|
|
|
|
(system* ,(string-append #$docker-cli "/bin/docker")
|
|
|
|
|
"version"))
|
|
|
|
|
marionette))
|
|
|
|
|
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(test-equal "Load docker image and run it"
|
2019-08-27 09:27:02 +00:00
|
|
|
|
'("hello world" "hi!" "JSON!" #o1777)
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(marionette-eval
|
|
|
|
|
`(begin
|
2023-05-06 13:07:09 +00:00
|
|
|
|
(use-modules (ice-9 popen)
|
|
|
|
|
(ice-9 rdelim))
|
|
|
|
|
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(define slurp
|
|
|
|
|
(lambda args
|
|
|
|
|
(let* ((port (apply open-pipe* OPEN_READ args))
|
|
|
|
|
(output (read-line port))
|
|
|
|
|
(status (close-pipe port)))
|
|
|
|
|
output)))
|
|
|
|
|
(let* ((raw-line (slurp ,(string-append #$docker-cli
|
|
|
|
|
"/bin/docker")
|
|
|
|
|
"load" "-i"
|
|
|
|
|
,#$docker-tarball))
|
|
|
|
|
(repository&tag (string-drop raw-line
|
|
|
|
|
(string-length
|
|
|
|
|
"Loaded image: ")))
|
2019-06-04 16:43:23 +00:00
|
|
|
|
(response1 (slurp
|
|
|
|
|
,(string-append #$docker-cli "/bin/docker")
|
|
|
|
|
"run" "--entrypoint" "bin/Guile"
|
|
|
|
|
repository&tag
|
|
|
|
|
"/aa.scm"))
|
|
|
|
|
(response2 (slurp ;default entry point
|
|
|
|
|
,(string-append #$docker-cli "/bin/docker")
|
|
|
|
|
"run" repository&tag
|
2019-07-02 07:19:48 +00:00
|
|
|
|
"-c" "(display \"hi!\")"))
|
|
|
|
|
|
|
|
|
|
;; Check whether (json) is in $GUILE_LOAD_PATH.
|
|
|
|
|
(response3 (slurp ;default entry point + environment
|
|
|
|
|
,(string-append #$docker-cli "/bin/docker")
|
|
|
|
|
"run" repository&tag
|
|
|
|
|
"-c" "(use-modules (json))
|
2019-08-27 09:27:02 +00:00
|
|
|
|
(display (json-string->scm (scm->json-string \"JSON!\")))"))
|
|
|
|
|
|
|
|
|
|
;; Check whether /tmp exists.
|
|
|
|
|
(response4 (slurp
|
|
|
|
|
,(string-append #$docker-cli "/bin/docker")
|
|
|
|
|
"run" repository&tag "-c"
|
|
|
|
|
"(display (stat:perms (lstat \"/tmp\")))")))
|
|
|
|
|
(list response1 response2 response3
|
|
|
|
|
(string->number response4))))
|
2019-01-14 14:44:16 +00:00
|
|
|
|
marionette))
|
|
|
|
|
|
tests: Adjust to SRFI-64 as found in Guile 3.0.7.
In Guile 3.0.7, 'test-runner-current' is set to #f upon 'test-end'.
Consequently, the previous strategy, where we'd call
'test-runner-current' after 'test-end', no longer works. Instead, set
the test runner in each test right before 'test-begin'.
* gnu/build/marionette.scm (system-test-runner): New procedure.
* gnu/tests/audio.scm (run-mpd-test): Replace (exit (= ...)) idiom
by (test-runner-current (system-test-runner)).
* gnu/tests/base.scm (run-basic-test)
(run-cleanup-test, run-mcron-test, run-nss-mdns-test): Likewise.
* gnu/tests/ci.scm (run-laminar-test): Likewise.
* gnu/tests/cups.scm (run-cups-test): Likewise.
* gnu/tests/databases.scm (run-memcached-test)
(run-postgresql-test, run-mysql-test): Likewise.
* gnu/tests/desktop.scm (run-elogind-test): Likewise.
* gnu/tests/dict.scm (run-dicod-test): Likewise.
* gnu/tests/docker.scm (run-docker-test): Likewise.
(run-docker-system-test): Likewise.
* gnu/tests/file-sharing.scm (run-transmission-daemon-test): Likewise.
* gnu/tests/ganeti.scm (run-ganeti-test): Likewise.
* gnu/tests/guix.scm (run-guix-build-coordinator-test): Likewise.
(run-guix-data-service-test): Likewise.
* gnu/tests/ldap.scm (run-ldap-test): Likewise.
* gnu/tests/linux-modules.scm (run-loadable-kernel-modules-test-base): Likewise.
* gnu/tests/mail.scm (run-opensmtpd-test)
(run-exim-test, run-dovecot-test, run-getmail-test): Likewise.
* gnu/tests/messaging.scm (run-xmpp-test)
(run-bitlbee-test, run-quassel-test): Likewise.
* gnu/tests/monitoring.scm (run-prometheus-node-exporter-server-test)
(run-zabbix-server-test): Likewise.
* gnu/tests/networking.scm (run-inetd-test, run-openvswitch-test)
(run-dhcpd-test, run-tor-test, run-iptables-test, run-ipfs-test): Likewise.
* gnu/tests/nfs.scm (run-nfs-test)
(run-nfs-server-test, run-nfs-root-fs-test): Likewise.
* gnu/tests/package-management.scm (run-nix-test): Likewise.
* gnu/tests/reconfigure.scm (run-switch-to-system-test)
(run-upgrade-services-test, run-install-bootloader-test): Likewise.
* gnu/tests/rsync.scm (run-rsync-test): Likewise.
* gnu/tests/security-token.scm (run-pcscd-test): Likewise.
* gnu/tests/singularity.scm (run-singularity-test): Likewise.
* gnu/tests/ssh.scm (run-ssh-test): Likewise.
* gnu/tests/telephony.scm (run-jami-test): Likewise.
* gnu/tests/version-control.scm (run-cgit-test): Likewise.
(run-git-http-test, run-gitolite-test, run-gitile-test): Likewise.
* gnu/tests/virtualization.scm (run-libvirt-test, run-childhurd-test): Likewise.
* gnu/tests/web.scm (run-webserver-test, run-php-fpm-test)
(run-hpcguix-web-server-test, run-tailon-test, run-patchwork-test): Likewise.
2021-09-25 16:36:04 +00:00
|
|
|
|
(test-end))))
|
2019-01-10 02:44:20 +00:00
|
|
|
|
|
|
|
|
|
(gexp->derivation "docker-test" test))
|
|
|
|
|
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(define (build-tarball&run-docker-test)
|
|
|
|
|
(mlet* %store-monad
|
|
|
|
|
((_ (set-grafting #f))
|
|
|
|
|
(guile (set-guile-for-build (default-guile)))
|
|
|
|
|
(guest-script-package ->
|
2019-01-18 17:12:15 +00:00
|
|
|
|
(package
|
|
|
|
|
(name "guest-script")
|
|
|
|
|
(version "0")
|
|
|
|
|
(source #f)
|
|
|
|
|
(build-system trivial-build-system)
|
2020-07-17 20:13:58 +00:00
|
|
|
|
(arguments `(#:guile ,guile-3.0
|
2019-01-18 17:12:15 +00:00
|
|
|
|
#:builder
|
|
|
|
|
(let ((out (assoc-ref %outputs "out")))
|
|
|
|
|
(mkdir out)
|
|
|
|
|
(call-with-output-file (string-append out "/a.scm")
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(display "(display \"hello world\n\")" port)))
|
|
|
|
|
#t)))
|
|
|
|
|
(synopsis "Display hello world using Guile")
|
|
|
|
|
(description "This package displays the text \"hello world\" on the
|
|
|
|
|
standard output device and then enters a new line.")
|
|
|
|
|
(home-page #f)
|
|
|
|
|
(license license:public-domain)))
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(profile (profile-derivation (packages->manifest
|
2020-07-17 20:13:58 +00:00
|
|
|
|
(list guile-3.0 guile-json-3
|
2019-01-14 14:44:16 +00:00
|
|
|
|
guest-script-package))
|
|
|
|
|
#:hooks '()
|
|
|
|
|
#:locales? #f))
|
2021-12-16 12:37:10 +00:00
|
|
|
|
(tarball (pack:docker-image
|
|
|
|
|
"docker-pack" profile
|
|
|
|
|
#:symlinks '(("/bin/Guile" -> "bin/guile")
|
|
|
|
|
("aa.scm" -> "a.scm"))
|
|
|
|
|
#:entry-point "bin/guile"
|
|
|
|
|
#:localstatedir? #t)))
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(run-docker-test tarball)))
|
|
|
|
|
|
2019-01-10 02:44:20 +00:00
|
|
|
|
(define %test-docker
|
|
|
|
|
(system-test
|
|
|
|
|
(name "docker")
|
2019-01-14 14:44:16 +00:00
|
|
|
|
(description "Test Docker container of Guix.")
|
|
|
|
|
(value (build-tarball&run-docker-test))))
|
2019-05-12 10:21:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (run-docker-system-test tarball)
|
|
|
|
|
"Load DOCKER-TARBALL as Docker image and run it in a Docker container,
|
|
|
|
|
inside %DOCKER-OS."
|
|
|
|
|
(define os
|
|
|
|
|
(marionette-operating-system
|
2021-12-16 12:37:10 +00:00
|
|
|
|
(operating-system-with-gc-roots
|
|
|
|
|
%docker-os
|
|
|
|
|
(list tarball))
|
2019-05-12 10:21:48 +00:00
|
|
|
|
#:imported-modules '((gnu services herd)
|
|
|
|
|
(guix combinators))))
|
|
|
|
|
|
|
|
|
|
(define vm
|
|
|
|
|
(virtual-machine
|
|
|
|
|
(operating-system os)
|
2021-12-16 12:37:10 +00:00
|
|
|
|
(volatile? #f)
|
2023-12-25 22:35:17 +00:00
|
|
|
|
(disk-image-size (* 6000 (expt 2 20)))
|
2021-12-16 12:37:10 +00:00
|
|
|
|
(memory-size 2048)
|
2019-05-12 10:21:48 +00:00
|
|
|
|
(port-forwardings '())))
|
|
|
|
|
|
|
|
|
|
(define test
|
|
|
|
|
(with-imported-modules '((gnu build marionette)
|
|
|
|
|
(guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (srfi srfi-11) (srfi srfi-64)
|
|
|
|
|
(gnu build marionette)
|
|
|
|
|
(guix build utils))
|
|
|
|
|
|
|
|
|
|
(define marionette
|
2022-06-24 04:43:23 +00:00
|
|
|
|
;; Relax timeout to accommodate older systems.
|
|
|
|
|
(make-marionette (list #$vm) #:timeout 60))
|
2019-05-12 10:21:48 +00:00
|
|
|
|
|
tests: Reduce boilerplate for users of 'system-test-runner'.
* gnu/tests/audio.scm, gnu/tests/base.scm, gnu/tests/ci.scm,
gnu/tests/cups.scm, gnu/tests/databases.scm, gnu/tests/desktop.scm,
gnu/tests/dict.scm, gnu/tests/docker.scm, gnu/tests/file-sharing.scm,
gnu/tests/ganeti.scm, gnu/tests/guix.scm, gnu/tests/ldap.scm,
gnu/tests/linux-modules.scm,
gnu/tests/mail.scm, gnu/tests/messaging.scm, gnu/tests/monitoring.scm,
gnu/tests/networking.scm, gnu/tests/nfs.scm,
gnu/tests/package-management.scm, gnu/tests/reconfigure.scm,
gnu/tests/rsync.scm, gnu/tests/security-token.scm,
gnu/tests/singularity.scm, gnu/tests/ssh.scm, gnu/tests/telephony.scm,
gnu/tests/version-control.scm, gnu/tests/virtualization.scm,
gnu/tests/web.scm: Remove (mkdir #$output) (chdir #$output) and
pass #$output as argument to 'system-test-runner'.
2021-09-26 21:20:56 +00:00
|
|
|
|
(test-runner-current (system-test-runner #$output))
|
2019-05-12 10:21:48 +00:00
|
|
|
|
(test-begin "docker")
|
|
|
|
|
|
2024-06-02 06:15:54 +00:00
|
|
|
|
(test-assert "containerd service running"
|
|
|
|
|
(marionette-eval
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(match (start-service 'containerd)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(('service response-parts ...)
|
|
|
|
|
(match (assq-ref response-parts 'running)
|
|
|
|
|
((pid) (number? pid))))))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(test-assert "containerd PID file present"
|
|
|
|
|
(wait-for-file "/run/containerd/containerd.pid" marionette))
|
|
|
|
|
|
2019-05-12 10:21:48 +00:00
|
|
|
|
(test-assert "service running"
|
|
|
|
|
(marionette-eval
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(match (start-service 'dockerd)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(('service response-parts ...)
|
|
|
|
|
(match (assq-ref response-parts 'running)
|
|
|
|
|
((pid) (number? pid))))))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(test-assert "load system image and run it"
|
|
|
|
|
(marionette-eval
|
|
|
|
|
`(begin
|
2023-05-06 13:07:09 +00:00
|
|
|
|
(use-modules (ice-9 popen)
|
2023-05-07 20:24:08 +00:00
|
|
|
|
(ice-9 rdelim)
|
|
|
|
|
(guix build utils))
|
2023-05-06 13:07:09 +00:00
|
|
|
|
|
2019-05-12 10:21:48 +00:00
|
|
|
|
(define (slurp command . args)
|
|
|
|
|
;; Return the output from COMMAND.
|
|
|
|
|
(let* ((port (apply open-pipe* OPEN_READ command args))
|
|
|
|
|
(output (read-line port))
|
|
|
|
|
(status (close-pipe port)))
|
|
|
|
|
output))
|
|
|
|
|
|
|
|
|
|
(define (docker-cli command . args)
|
|
|
|
|
;; Run the given Docker COMMAND.
|
|
|
|
|
(apply invoke #$(file-append docker-cli "/bin/docker")
|
|
|
|
|
command args))
|
|
|
|
|
|
|
|
|
|
(define (wait-for-container-file container file)
|
|
|
|
|
;; Wait for FILE to show up in CONTAINER.
|
|
|
|
|
(docker-cli "exec" container
|
2020-07-17 20:13:58 +00:00
|
|
|
|
#$(file-append guile-3.0 "/bin/guile")
|
2019-05-12 10:21:48 +00:00
|
|
|
|
"-c"
|
|
|
|
|
(object->string
|
|
|
|
|
`(let loop ((n 15))
|
|
|
|
|
(when (zero? n)
|
|
|
|
|
(error "file didn't show up" ,file))
|
|
|
|
|
(unless (file-exists? ,file)
|
|
|
|
|
(sleep 1)
|
|
|
|
|
(loop (- n 1)))))))
|
|
|
|
|
|
|
|
|
|
(let* ((line (slurp #$(file-append docker-cli "/bin/docker")
|
|
|
|
|
"load" "-i" #$tarball))
|
|
|
|
|
(repository&tag (string-drop line
|
|
|
|
|
(string-length
|
|
|
|
|
"Loaded image: ")))
|
|
|
|
|
(container (slurp
|
|
|
|
|
#$(file-append docker-cli "/bin/docker")
|
|
|
|
|
"create" repository&tag)))
|
|
|
|
|
(docker-cli "start" container)
|
|
|
|
|
|
|
|
|
|
;; Wait for shepherd to be ready.
|
|
|
|
|
(wait-for-container-file container
|
|
|
|
|
"/var/run/shepherd/socket")
|
|
|
|
|
|
|
|
|
|
(docker-cli "exec" container
|
|
|
|
|
"/run/current-system/profile/bin/herd"
|
|
|
|
|
"status")
|
|
|
|
|
(slurp #$(file-append docker-cli "/bin/docker")
|
|
|
|
|
"exec" container
|
|
|
|
|
"/run/current-system/profile/bin/herd"
|
|
|
|
|
"status" "guix-daemon")))
|
|
|
|
|
marionette))
|
|
|
|
|
|
tests: Adjust to SRFI-64 as found in Guile 3.0.7.
In Guile 3.0.7, 'test-runner-current' is set to #f upon 'test-end'.
Consequently, the previous strategy, where we'd call
'test-runner-current' after 'test-end', no longer works. Instead, set
the test runner in each test right before 'test-begin'.
* gnu/build/marionette.scm (system-test-runner): New procedure.
* gnu/tests/audio.scm (run-mpd-test): Replace (exit (= ...)) idiom
by (test-runner-current (system-test-runner)).
* gnu/tests/base.scm (run-basic-test)
(run-cleanup-test, run-mcron-test, run-nss-mdns-test): Likewise.
* gnu/tests/ci.scm (run-laminar-test): Likewise.
* gnu/tests/cups.scm (run-cups-test): Likewise.
* gnu/tests/databases.scm (run-memcached-test)
(run-postgresql-test, run-mysql-test): Likewise.
* gnu/tests/desktop.scm (run-elogind-test): Likewise.
* gnu/tests/dict.scm (run-dicod-test): Likewise.
* gnu/tests/docker.scm (run-docker-test): Likewise.
(run-docker-system-test): Likewise.
* gnu/tests/file-sharing.scm (run-transmission-daemon-test): Likewise.
* gnu/tests/ganeti.scm (run-ganeti-test): Likewise.
* gnu/tests/guix.scm (run-guix-build-coordinator-test): Likewise.
(run-guix-data-service-test): Likewise.
* gnu/tests/ldap.scm (run-ldap-test): Likewise.
* gnu/tests/linux-modules.scm (run-loadable-kernel-modules-test-base): Likewise.
* gnu/tests/mail.scm (run-opensmtpd-test)
(run-exim-test, run-dovecot-test, run-getmail-test): Likewise.
* gnu/tests/messaging.scm (run-xmpp-test)
(run-bitlbee-test, run-quassel-test): Likewise.
* gnu/tests/monitoring.scm (run-prometheus-node-exporter-server-test)
(run-zabbix-server-test): Likewise.
* gnu/tests/networking.scm (run-inetd-test, run-openvswitch-test)
(run-dhcpd-test, run-tor-test, run-iptables-test, run-ipfs-test): Likewise.
* gnu/tests/nfs.scm (run-nfs-test)
(run-nfs-server-test, run-nfs-root-fs-test): Likewise.
* gnu/tests/package-management.scm (run-nix-test): Likewise.
* gnu/tests/reconfigure.scm (run-switch-to-system-test)
(run-upgrade-services-test, run-install-bootloader-test): Likewise.
* gnu/tests/rsync.scm (run-rsync-test): Likewise.
* gnu/tests/security-token.scm (run-pcscd-test): Likewise.
* gnu/tests/singularity.scm (run-singularity-test): Likewise.
* gnu/tests/ssh.scm (run-ssh-test): Likewise.
* gnu/tests/telephony.scm (run-jami-test): Likewise.
* gnu/tests/version-control.scm (run-cgit-test): Likewise.
(run-git-http-test, run-gitolite-test, run-gitile-test): Likewise.
* gnu/tests/virtualization.scm (run-libvirt-test, run-childhurd-test): Likewise.
* gnu/tests/web.scm (run-webserver-test, run-php-fpm-test)
(run-hpcguix-web-server-test, run-tailon-test, run-patchwork-test): Likewise.
2021-09-25 16:36:04 +00:00
|
|
|
|
(test-end))))
|
2019-05-12 10:21:48 +00:00
|
|
|
|
|
|
|
|
|
(gexp->derivation "docker-system-test" test))
|
|
|
|
|
|
|
|
|
|
(define %test-docker-system
|
|
|
|
|
(system-test
|
|
|
|
|
(name "docker-system")
|
|
|
|
|
(description "Run a system image as produced by @command{guix system
|
|
|
|
|
docker-image} inside Docker.")
|
|
|
|
|
(value (with-monad %store-monad
|
2021-12-16 12:37:10 +00:00
|
|
|
|
(>>= (lower-object
|
|
|
|
|
(system-image (os->image
|
|
|
|
|
(operating-system
|
|
|
|
|
(inherit (simple-operating-system))
|
|
|
|
|
;; Use locales for a single libc to
|
|
|
|
|
;; reduce space requirements.
|
|
|
|
|
(locale-libcs (list glibc)))
|
|
|
|
|
#:type docker-image-type)))
|
2019-05-12 10:21:48 +00:00
|
|
|
|
run-docker-system-test)))))
|
2024-05-03 22:11:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define %oci-os
|
|
|
|
|
(simple-operating-system
|
|
|
|
|
(service dhcp-client-service-type)
|
|
|
|
|
(service dbus-root-service-type)
|
|
|
|
|
(service polkit-service-type)
|
|
|
|
|
(service elogind-service-type)
|
2024-06-02 06:15:54 +00:00
|
|
|
|
(service containerd-service-type)
|
2024-05-03 22:11:17 +00:00
|
|
|
|
(service docker-service-type)
|
|
|
|
|
(extra-special-file "/shared.txt"
|
|
|
|
|
(plain-file "shared.txt" "hello"))
|
|
|
|
|
(service oci-container-service-type
|
|
|
|
|
(list
|
|
|
|
|
(oci-container-configuration
|
|
|
|
|
(image
|
|
|
|
|
(oci-image
|
|
|
|
|
(repository "guile")
|
|
|
|
|
(value
|
|
|
|
|
(specifications->manifest '("guile")))
|
|
|
|
|
(pack-options
|
|
|
|
|
'(#:symlinks (("/bin" -> "bin"))))))
|
|
|
|
|
(entrypoint
|
|
|
|
|
"/bin/guile")
|
|
|
|
|
(command
|
|
|
|
|
'("-c" "(let l ((c 300))(display c)(sleep 1)(when(positive? c)(l (- c 1))))"))
|
|
|
|
|
(host-environment
|
|
|
|
|
'(("VARIABLE" . "value")))
|
|
|
|
|
(volumes
|
|
|
|
|
'(("/shared.txt" . "/shared.txt:ro")))
|
|
|
|
|
(extra-arguments
|
|
|
|
|
'("--env" "VARIABLE")))))))
|
|
|
|
|
|
|
|
|
|
(define (run-oci-container-test)
|
|
|
|
|
"Run IMAGE as an OCI backed Shepherd service, inside OS."
|
|
|
|
|
|
|
|
|
|
(define os
|
|
|
|
|
(marionette-operating-system
|
|
|
|
|
(operating-system-with-gc-roots
|
|
|
|
|
%oci-os
|
|
|
|
|
(list))
|
|
|
|
|
#:imported-modules '((gnu services herd)
|
|
|
|
|
(guix combinators))))
|
|
|
|
|
|
|
|
|
|
(define vm
|
|
|
|
|
(virtual-machine
|
|
|
|
|
(operating-system os)
|
|
|
|
|
(volatile? #f)
|
|
|
|
|
(memory-size 1024)
|
|
|
|
|
(disk-image-size (* 3000 (expt 2 20)))
|
|
|
|
|
(port-forwardings '())))
|
|
|
|
|
|
|
|
|
|
(define test
|
|
|
|
|
(with-imported-modules '((gnu build marionette))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (srfi srfi-11) (srfi srfi-64)
|
|
|
|
|
(gnu build marionette))
|
|
|
|
|
|
|
|
|
|
(define marionette
|
|
|
|
|
;; Relax timeout to accommodate older systems and
|
|
|
|
|
;; allow for pulling the image.
|
|
|
|
|
(make-marionette (list #$vm) #:timeout 60))
|
|
|
|
|
|
|
|
|
|
(test-runner-current (system-test-runner #$output))
|
|
|
|
|
(test-begin "oci-container")
|
|
|
|
|
|
2024-06-02 06:15:54 +00:00
|
|
|
|
(test-assert "containerd service running"
|
|
|
|
|
(marionette-eval
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(match (start-service 'containerd)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(('service response-parts ...)
|
|
|
|
|
(match (assq-ref response-parts 'running)
|
|
|
|
|
((pid) (number? pid))))))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(test-assert "containerd PID file present"
|
|
|
|
|
(wait-for-file "/run/containerd/containerd.pid" marionette))
|
|
|
|
|
|
2024-05-03 22:11:17 +00:00
|
|
|
|
(test-assert "dockerd running"
|
|
|
|
|
(marionette-eval
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(match (start-service 'dockerd)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(('service response-parts ...)
|
|
|
|
|
(match (assq-ref response-parts 'running)
|
|
|
|
|
((pid) (number? pid))))))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(sleep 10) ; let service start
|
|
|
|
|
|
|
|
|
|
(test-assert "docker-guile running"
|
|
|
|
|
(marionette-eval
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(match (start-service 'docker-guile)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(('service response-parts ...)
|
|
|
|
|
(match (assq-ref response-parts 'running)
|
|
|
|
|
((pid) (number? pid))))))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(test-equal "passing host environment variables and volumes"
|
|
|
|
|
'("value" "hello")
|
|
|
|
|
(marionette-eval
|
|
|
|
|
`(begin
|
|
|
|
|
(use-modules (ice-9 popen)
|
|
|
|
|
(ice-9 rdelim))
|
|
|
|
|
|
|
|
|
|
(define slurp
|
|
|
|
|
(lambda args
|
|
|
|
|
(let* ((port (apply open-pipe* OPEN_READ args))
|
|
|
|
|
(output (let ((line (read-line port)))
|
|
|
|
|
(if (eof-object? line)
|
|
|
|
|
""
|
|
|
|
|
line)))
|
|
|
|
|
(status (close-pipe port)))
|
|
|
|
|
output)))
|
|
|
|
|
(let* ((response1 (slurp
|
|
|
|
|
,(string-append #$docker-cli "/bin/docker")
|
|
|
|
|
"exec" "docker-guile"
|
|
|
|
|
"/bin/guile" "-c" "(display (getenv \"VARIABLE\"))"))
|
|
|
|
|
(response2 (slurp
|
|
|
|
|
,(string-append #$docker-cli "/bin/docker")
|
|
|
|
|
"exec" "docker-guile"
|
|
|
|
|
"/bin/guile" "-c" "(begin (use-modules (ice-9 popen) (ice-9 rdelim))
|
|
|
|
|
(display (call-with-input-file \"/shared.txt\" read-line)))")))
|
|
|
|
|
(list response1 response2)))
|
|
|
|
|
marionette))
|
|
|
|
|
|
|
|
|
|
(test-end))))
|
|
|
|
|
|
|
|
|
|
(gexp->derivation "oci-container-test" test))
|
|
|
|
|
|
|
|
|
|
(define %test-oci-container
|
|
|
|
|
(system-test
|
|
|
|
|
(name "oci-container")
|
|
|
|
|
(description "Test OCI backed Shepherd service.")
|
|
|
|
|
(value (run-oci-container-test))))
|