From: "Ludovic Courtès" <ludo@gnu.org>
To: Oleg Pykhalov <go.wigust@gmail.com>
Cc: Greg Hogan <code@greghogan.com>, 62153@debbugs.gnu.org
Subject: [bug#62153] [PATCH v4 1/2] guix: docker: Build layered image.
Date: Fri, 22 Dec 2023 23:10:20 +0100 [thread overview]
Message-ID: <878r5l99df.fsf@gnu.org> (raw)
In-Reply-To: <457c813653a44117e296deaa49e79fc701b90791.1685819700.git.go.wigust@gmail.com> (Oleg Pykhalov's message of "Sat, 3 Jun 2023 22:14:59 +0300")
Oleg Pykhalov <go.wigust@gmail.com> skribis:
> * doc/guix.texi (Invoking guix pack): Document docker-layered format.
> (image Reference): Same.
> (image-type Reference): Document docker-layered-image-type.
> * gnu/image.scm
> (validate-image-format)[docker-layered]: New image format.
> * gnu/system/image.scm
> (docker-layered-image, docker-layered-image-type): New variables.
> (system-docker-image)[layered-image?]: New argument.
> (system-docker-layered-image): New procedure.
> (image->root-file-system)[docker-layered]: New image format.
> * gnu/tests/docker.scm (%test-docker-layered-system): New test.
> * guix/docker.scm (%docker-image-max-layers): New variable.
> (build-docker-image)[stream-layered-image, root-system]: New arguments.
> * guix/scripts/pack.scm (stream-layered-image.py): New variable.
> (docker-image)[layered-image?]: New argument.
> (docker-layered-image): New procedure.
> (%formats)[docker-layered]: New format.
> (show-formats): Document this.
> * guix/scripts/system.scm
> (system-derivation-for-action)[docker-layered-image]: New action.
> (show-help): Document this.
> (actions)[docker-layered-image]: New action.
> (process-action): Add this.
> * tests/pack.scm: Add "docker-layered-image + localstatedir" test.
[...]
> + #:use-module (guix diagnostics)
> + #:use-module (guix i18n)
(guix docker) shouldn’t need these.
> + #:use-module (ice-9 popen)
> + #:use-module (ice-9 rdelim)
> + #:use-module (ice-9 receive)
For consistency, I’d recommend (srfi srfi-71) instead of (ice-9
receive).
> +(define %docker-image-max-layers
> + 100)
I’d add a comment on the second line, like “;; Maximum number of layers
allowed in a Docker image according to …”.
> +(define (paths-split-sort paths)
> + "Split list of PATHS at %DOCKER-IMAGE-MAX-LAYERS and sort by disk usage."
Nitpick: maybe (define (size-sorted-store-items items) …)?
> + (let* ((paths-length (length paths))
> + (port (apply open-pipe* OPEN_READ
> + (append '("du" "--summarize") paths)))
> + (output (read-string port)))
> + (close-port port)
How about:
(map (lambda (item)
(cons item (file-size item)))
items)
?
See (guix build store-copy) for the definition of ‘file-size’.
That way we avoid the dependency on Coreutils and code that “parses” the
output of ‘du’.
> + (define layers-hashes
A short comment explaining what the inputs and outputs of this procedure
are would be great.
> + (match-lambda
> + (((head ...) (tail ...) id)
> + (create-empty-tar "image.tar")
> + (let* ((head-layers
> + (map
> + (lambda (file)
> + (invoke "tar" "cf" "layer.tar" file)
> + (let* ((file-hash (layer-diff-id "layer.tar"))
> + (file-name (string-append file-hash "/layer.tar")))
> + (mkdir file-hash)
> + (rename-file "layer.tar" file-name)
> + (invoke "tar" "-rf" "image.tar" file-name)
> + (delete-file file-name)
> + file-hash))
> + head))
> + (tail-layer
> + (begin
> + (create-empty-tar "layer.tar")
> + (for-each (lambda (file)
> + (invoke "tar" "-rf" "layer.tar" file))
> + tail)
> + (let* ((file-hash (layer-diff-id "layer.tar"))
> + (file-name (string-append file-hash "/layer.tar")))
> + (mkdir file-hash)
> + (rename-file "layer.tar" file-name)
> + (invoke "tar" "-rf" "image.tar" file-name)
> + (delete-file file-name)
> + file-hash)))
> + (customization-layer
> + (let* ((file-id (string-append id "/layer.tar"))
> + (file-hash (layer-diff-id file-id))
> + (file-name (string-append file-hash "/layer.tar")))
> + (mkdir file-hash)
> + (rename-file file-id file-name)
> + (invoke "tar" "-rf" "image.tar" file-name)
> + file-hash))
> + (all-layers
> + (append head-layers (list tail-layer customization-layer))))
Maybe this can be factorized a bit with:
(define (seal-layer)
;; Add 'layer.tar' to 'image.tar' under the right name. Return its hash.
(let* ((file-hash (layer-diff-id "layer.tar"))
(file-name (string-append file-hash "/layer.tar")))
(mkdir file-hash)
(rename-file "layer.tar" file-name)
(invoke "tar" "-rf" "image.tar" file-name)
(delete-file file-name)
file-hash)))
?
Apart from this stylistic issues, it looks great to me.
Thanks,
Ludo’.
next prev parent reply other threads:[~2023-12-22 22:11 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 0:30 [bug#62153] [PATCH 0/2] Add Docker layered image for pack and system Oleg Pykhalov
2023-03-13 0:33 ` [bug#62153] [PATCH 1/2] guix: docker: Build layered image Oleg Pykhalov
2023-03-13 0:33 ` [bug#62153] [PATCH 2/2] news: Add entry for the new 'docker-layered' distribution format Oleg Pykhalov
2023-03-13 21:09 ` pelzflorian (Florian Pelz)
2023-03-14 0:24 ` [bug#62153] [PATCH 0/2] Add Docker layered image for pack and system (v2) Oleg Pykhalov
2023-03-14 0:24 ` [bug#62153] [PATCH 1/2] guix: docker: Build layered image Oleg Pykhalov
2023-03-14 0:24 ` [bug#62153] [PATCH 2/2] news: Add entry for the new 'docker-layered' distribution format Oleg Pykhalov
2023-03-13 15:01 ` [bug#62153] [PATCH 1/2] guix: docker: Build layered image Simon Tournier
2023-03-13 21:10 ` Oleg Pykhalov
2023-03-14 8:19 ` Simon Tournier
2023-03-14 9:15 ` Ricardo Wurmus
2023-03-16 10:37 ` Ludovic Courtès
2023-03-20 6:38 ` Oleg Pykhalov
2023-03-20 16:51 ` [bug#62153] [PATCH 0/2] Disarchive vs Gash-Utils for docker-layered Oleg Pykhalov
2023-03-14 9:11 ` [bug#62153] [PATCH 1/2] guix: docker: Build layered image Christopher Baines
2023-03-13 0:43 ` [bug#62153] Cover lever typo in guix pack format example Oleg Pykhalov
2023-03-14 0:40 ` [bug#62153] Missing diff in cover lever for v2 patch Oleg Pykhalov
2023-05-31 8:45 ` [bug#62153] [PATCH] Add Docker layered image for pack and system (v3) Oleg Pykhalov
2023-05-31 8:47 ` [bug#62153] [PATCH] guix: docker: Build layered image Oleg Pykhalov
2023-05-31 8:47 ` [bug#62153] [PATCH] news: Add entry for the new 'docker-layered' distribution format Oleg Pykhalov
2023-05-31 12:53 ` [bug#62153] [PATCH] Add Docker layered image for pack and system (v3) Greg Hogan
2023-05-31 13:14 ` Oleg Pykhalov
2023-06-02 17:02 ` Greg Hogan
2023-06-03 19:10 ` [bug#62153] [PATCH 0/2] Add Docker layered image for pack and system Oleg Pykhalov
2023-06-03 19:14 ` [bug#62153] [PATCH v4 1/2] guix: docker: Build layered image Oleg Pykhalov
2023-12-22 22:10 ` Ludovic Courtès [this message]
2023-06-03 19:16 ` [bug#62153] [PATCH v4] news: Add entry for the new 'docker-layered' distribution format Oleg Pykhalov
2023-12-26 2:15 ` [bug#62153] [PATCH v5 0/5] Add Docker layered image for pack and system Oleg Pykhalov
2023-12-26 2:18 ` [bug#62153] [PATCH 1/5] guix: pack: Add '--entry-point-argument' option Oleg Pykhalov
2023-12-27 18:14 ` Mathieu Othacehe
2023-12-27 18:16 ` Mathieu Othacehe
2023-12-26 2:18 ` [bug#62153] [PATCH 2/5] tests: docker-system: Increase image size Oleg Pykhalov
2023-12-26 2:18 ` [bug#62153] [PATCH 3/5] guix: docker: Build layered images Oleg Pykhalov
2023-12-27 20:15 ` Mathieu Othacehe
2024-01-18 14:55 ` Ludovic Courtès
2023-12-26 2:18 ` [bug#62153] [PATCH 4/5] guix: pack: " Oleg Pykhalov
2023-12-27 20:25 ` Mathieu Othacehe
2023-12-26 2:18 ` [bug#62153] [PATCH 5/5] scripts: system: " Oleg Pykhalov
2023-12-27 20:29 ` Mathieu Othacehe
2024-01-08 16:49 ` Ludovic Courtès
2024-01-09 12:58 ` bug#62153: " Oleg Pykhalov
[not found] ` <878r9xb2e6.fsf@gmail.com>
[not found] ` <875y0p99c4.fsf@gnu.org>
2023-12-26 2:40 ` [bug#62153] Merging guix pack changes for Docker containers packaging Oleg Pykhalov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878r5l99df.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=62153@debbugs.gnu.org \
--cc=code@greghogan.com \
--cc=go.wigust@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).