mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-18 21:46:35 +01:00
scripts: system: Build layered images.
* guix/scripts/system.scm (show-help, %docker-format-options, %options, %default-options, show-docker-format-options, show-docker-format-options/detailed, process-action): Handle '--max-layers' option. * gnu/system/image.scm (system-docker-image): Same. * gnu/image.scm (<image>)[max-layers]: New record field. Change-Id: I2726655aefd6688b976057fd5a38e9972ebfc292
This commit is contained in:
parent
0cf75c9b2f
commit
519e1e3eb8
3 changed files with 61 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
||||||
;;; GNU Guix --- Functional package management for GNU
|
;;; GNU Guix --- Functional package management for GNU
|
||||||
;;; Copyright © 2020, 2022 Mathieu Othacehe <othacehe@gnu.org>
|
;;; Copyright © 2020, 2022 Mathieu Othacehe <othacehe@gnu.org>
|
||||||
|
;;; Copyright © 2023 Oleg Pykhalov <go.wigust@gmail.com>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -42,6 +43,7 @@ (define-module (gnu image)
|
||||||
image-format
|
image-format
|
||||||
image-platform
|
image-platform
|
||||||
image-size
|
image-size
|
||||||
|
image-max-layers
|
||||||
image-operating-system
|
image-operating-system
|
||||||
image-partition-table-type
|
image-partition-table-type
|
||||||
image-partitions
|
image-partitions
|
||||||
|
@ -170,6 +172,8 @@ (define-record-type* <image>
|
||||||
(size image-size ;size in bytes as integer
|
(size image-size ;size in bytes as integer
|
||||||
(default 'guess)
|
(default 'guess)
|
||||||
(sanitize validate-size))
|
(sanitize validate-size))
|
||||||
|
(max-layers image-max-layers ;number of layers as integer
|
||||||
|
(default #false))
|
||||||
(operating-system image-operating-system) ;<operating-system>
|
(operating-system image-operating-system) ;<operating-system>
|
||||||
(partition-table-type image-partition-table-type ; 'mbr or 'gpt
|
(partition-table-type image-partition-table-type ; 'mbr or 'gpt
|
||||||
(default 'mbr)
|
(default 'mbr)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
|
;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
|
||||||
;;; Copyright © 2022 Alex Griffin <a@ajgrf.com>
|
;;; Copyright © 2022 Alex Griffin <a@ajgrf.com>
|
||||||
;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
|
;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
|
||||||
|
;;; Copyright © 2023 Oleg Pykhalov <go.wigust@gmail.com>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -686,7 +687,8 @@ (define (image-with-label base-image label)
|
||||||
|
|
||||||
(define* (system-docker-image image
|
(define* (system-docker-image image
|
||||||
#:key
|
#:key
|
||||||
(name "docker-image"))
|
(name "docker-image")
|
||||||
|
(archiver tar))
|
||||||
"Build a docker image for IMAGE. NAME is the base name to use for the
|
"Build a docker image for IMAGE. NAME is the base name to use for the
|
||||||
output file."
|
output file."
|
||||||
(define boot-program
|
(define boot-program
|
||||||
|
@ -731,6 +733,7 @@ (define builder
|
||||||
(use-modules (guix docker)
|
(use-modules (guix docker)
|
||||||
(guix build utils)
|
(guix build utils)
|
||||||
(gnu build image)
|
(gnu build image)
|
||||||
|
(srfi srfi-1)
|
||||||
(srfi srfi-19)
|
(srfi srfi-19)
|
||||||
(guix build store-copy)
|
(guix build store-copy)
|
||||||
(guix store database))
|
(guix store database))
|
||||||
|
@ -754,18 +757,30 @@ (define builder
|
||||||
#:register-closures? #$register-closures?
|
#:register-closures? #$register-closures?
|
||||||
#:deduplicate? #f
|
#:deduplicate? #f
|
||||||
#:system-directory #$os)
|
#:system-directory #$os)
|
||||||
(build-docker-image
|
(when #$(image-max-layers image)
|
||||||
#$output
|
(setenv "PATH"
|
||||||
(cons* image-root
|
(string-join (list #+(file-append archiver "/bin")
|
||||||
(map store-info-item
|
#+(file-append gzip "/bin"))
|
||||||
(call-with-input-file #$graph
|
":")))
|
||||||
read-reference-graph)))
|
(apply build-docker-image
|
||||||
#$os
|
(append (list #$output
|
||||||
#:entry-point '(#$boot-program #$os)
|
(append (if #$(image-max-layers image)
|
||||||
#:compressor '(#+(file-append gzip "/bin/gzip") "-9n")
|
'()
|
||||||
#:creation-time (make-time time-utc 0 1)
|
(list image-root))
|
||||||
#:system #$image-target
|
(map store-info-item
|
||||||
#:transformations `((,image-root -> ""))))))))
|
(call-with-input-file #$graph
|
||||||
|
read-reference-graph)))
|
||||||
|
#$os
|
||||||
|
#:entry-point '(#$boot-program #$os)
|
||||||
|
#:compressor
|
||||||
|
'(#+(file-append gzip "/bin/gzip") "-9n")
|
||||||
|
#:creation-time (make-time time-utc 0 1)
|
||||||
|
#:system #$image-target
|
||||||
|
#:transformations `((,image-root -> "")))
|
||||||
|
(if #$(image-max-layers image)
|
||||||
|
(list #:root-system image-root
|
||||||
|
#:max-layers #$(image-max-layers image))
|
||||||
|
'()))))))))
|
||||||
|
|
||||||
(computed-file name builder
|
(computed-file name builder
|
||||||
;; Allow offloading so that this I/O-intensive process
|
;; Allow offloading so that this I/O-intensive process
|
||||||
|
|
|
@ -58,6 +58,7 @@ (define-module (guix scripts system)
|
||||||
#:use-module (guix scripts system reconfigure)
|
#:use-module (guix scripts system reconfigure)
|
||||||
#:use-module (guix build utils)
|
#:use-module (guix build utils)
|
||||||
#:use-module (guix progress)
|
#:use-module (guix progress)
|
||||||
|
#:use-module ((guix docker) #:select (%docker-image-max-layers))
|
||||||
#:use-module (gnu build image)
|
#:use-module (gnu build image)
|
||||||
#:use-module (gnu build install)
|
#:use-module (gnu build install)
|
||||||
#:autoload (gnu build file-systems)
|
#:autoload (gnu build file-systems)
|
||||||
|
@ -1053,6 +1054,8 @@ (define (show-help)
|
||||||
(newline)
|
(newline)
|
||||||
(show-native-build-options-help)
|
(show-native-build-options-help)
|
||||||
(newline)
|
(newline)
|
||||||
|
(show-docker-format-options)
|
||||||
|
(newline)
|
||||||
(display (G_ "
|
(display (G_ "
|
||||||
-h, --help display this help and exit"))
|
-h, --help display this help and exit"))
|
||||||
(display (G_ "
|
(display (G_ "
|
||||||
|
@ -1060,12 +1063,21 @@ (define (show-help)
|
||||||
(newline)
|
(newline)
|
||||||
(show-bug-report-information))
|
(show-bug-report-information))
|
||||||
|
|
||||||
|
(define %docker-format-options
|
||||||
|
(list (option '("max-layers") #t #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(alist-cons 'max-layers (string->number* arg)
|
||||||
|
result)))))
|
||||||
|
|
||||||
(define %options
|
(define %options
|
||||||
;; Specifications of the command-line options.
|
;; Specifications of the command-line options.
|
||||||
(cons* (option '(#\h "help") #f #f
|
(cons* (option '(#\h "help") #f #f
|
||||||
(lambda args
|
(lambda args
|
||||||
(leave-on-EPIPE (show-help))
|
(leave-on-EPIPE (show-help))
|
||||||
(exit 0)))
|
(exit 0)))
|
||||||
|
(option '("help-docker-format") #f #f
|
||||||
|
(lambda args
|
||||||
|
(show-docker-format-options/detailed)))
|
||||||
(option '(#\V "version") #f #f
|
(option '(#\V "version") #f #f
|
||||||
(lambda args
|
(lambda args
|
||||||
(show-version-and-exit "guix system")))
|
(show-version-and-exit "guix system")))
|
||||||
|
@ -1154,7 +1166,8 @@ (define %options
|
||||||
(alist-cons 'list-installed (or arg "") result)))
|
(alist-cons 'list-installed (or arg "") result)))
|
||||||
(append %standard-build-options
|
(append %standard-build-options
|
||||||
%standard-cross-build-options
|
%standard-cross-build-options
|
||||||
%standard-native-build-options)))
|
%standard-native-build-options
|
||||||
|
%docker-format-options)))
|
||||||
|
|
||||||
(define %default-options
|
(define %default-options
|
||||||
;; Alist of default option values.
|
;; Alist of default option values.
|
||||||
|
@ -1175,7 +1188,8 @@ (define %default-options
|
||||||
(label . #f)
|
(label . #f)
|
||||||
(volatile-image-root? . #f)
|
(volatile-image-root? . #f)
|
||||||
(volatile-vm-root? . #t)
|
(volatile-vm-root? . #t)
|
||||||
(graph-backend . "graphviz")))
|
(graph-backend . "graphviz")
|
||||||
|
(max-layers . ,%docker-image-max-layers)))
|
||||||
|
|
||||||
(define (verbosity-level opts)
|
(define (verbosity-level opts)
|
||||||
"Return the verbosity level based on OPTS, the alist of parsed options."
|
"Return the verbosity level based on OPTS, the alist of parsed options."
|
||||||
|
@ -1183,6 +1197,17 @@ (define (verbosity-level opts)
|
||||||
(if (eq? (assoc-ref opts 'action) 'build)
|
(if (eq? (assoc-ref opts 'action) 'build)
|
||||||
3 1)))
|
3 1)))
|
||||||
|
|
||||||
|
(define (show-docker-format-options)
|
||||||
|
(display (G_ "
|
||||||
|
--help-docker-format list options specific to the docker image type.")))
|
||||||
|
|
||||||
|
(define (show-docker-format-options/detailed)
|
||||||
|
(display (G_ "
|
||||||
|
--max-layers=N
|
||||||
|
Number of image layers"))
|
||||||
|
(newline)
|
||||||
|
(exit 0))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Entry point.
|
;;; Entry point.
|
||||||
|
@ -1245,6 +1270,7 @@ (define save-provenance?
|
||||||
((docker-image) docker-image-type)
|
((docker-image) docker-image-type)
|
||||||
(else image-type)))
|
(else image-type)))
|
||||||
(image-size (assoc-ref opts 'image-size))
|
(image-size (assoc-ref opts 'image-size))
|
||||||
|
(image-max-layers (assoc-ref opts 'max-layers))
|
||||||
(volatile?
|
(volatile?
|
||||||
(assoc-ref opts 'volatile-image-root?))
|
(assoc-ref opts 'volatile-image-root?))
|
||||||
(shared-network?
|
(shared-network?
|
||||||
|
@ -1258,6 +1284,7 @@ (define save-provenance?
|
||||||
(image-with-label base-image label)
|
(image-with-label base-image label)
|
||||||
base-image))
|
base-image))
|
||||||
(size image-size)
|
(size image-size)
|
||||||
|
(max-layers image-max-layers)
|
||||||
(volatile-root? volatile?)
|
(volatile-root? volatile?)
|
||||||
(shared-network? shared-network?))))
|
(shared-network? shared-network?))))
|
||||||
(os (or (image-operating-system image)
|
(os (or (image-operating-system image)
|
||||||
|
|
Loading…
Reference in a new issue