Subject: [bug#30572] [PATCH 5/7] docker: Allow the addition of extra files into the image.

From: Chris Marusich <[email-masked]>
Date: Mon, 26 Feb 2018 17:25:21 +0100

Danny Milosavljevic <[email-masked]> writes:

>> +                      (zero? (apply system* "tar" "-C" extra-items-dir
>> +                                    "-rf" "layer.tar"
>> +                                    (append %tar-determinism-options
>> +                                            '("."))))))))
>
> -C is order-sensitive.  Apparently it still doesn't cause layer.tar
> to be created inside extra-items-dir (huh...), but for clarity, I'd prefer:
>
> tar -rf layer.tar -C extra-items-dir .

I didn't realize this was the case.  I agree it would be best to reverse
the order here.  I've attached a patch which does this.  How does it
look?

-- 
Chris
From 5a889e7d8dc6847c2d9a8ae526df7c974688a947 Mon Sep 17 00:00:00 2001
From: Chris Marusich <[email-masked]>
Date: Mon, 19 Feb 2018 05:53:16 +0100
Subject: [PATCH 5/8] docker: Allow the addition of extra files into the image.

* guix/docker.scm (build-docker-image): Add #:extra-items-dir keyword
  argument.
---
 guix/docker.scm | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/guix/docker.scm b/guix/docker.scm
index 305e8273b..ef92714e0 100644
--- a/guix/docker.scm
+++ b/guix/docker.scm
@@ -107,7 +107,8 @@ return \"a\"."
                              (symlinks '())
                              (system (utsname:machine (uname)))
                              (creation-time (current-time time-utc))
-                             (tmpdir "/tmp/docker-image"))
+                             (tmpdir "/tmp/docker-image")
+                             extra-items-dir)
   "Write to IMAGE a Docker image archive from the given store PATH.  The image
 contains the closure of PATH, as specified in CLOSURE (a file produced by
 #:references-graphs).  SYMLINKS must be a list of (SOURCE -> TARGET) tuples
@@ -121,7 +122,12 @@ CREATION-TIME, a SRFI-19 time-utc object, as the creation time in metadata.
 TMPDIR is the name of the temporary working directory to use.  This can be
 useful if you need to use a specific temporary directory, for example because
 the default temporary directory lies on a file system with insufficient
-space."
+space.
+
+EXTRA-ITEMS-DIR is the name of a directory containing extra files to add to
+the image; the entire directory tree rooted at EXTRA-ITEMS-DIR will be copied
+into the root directory of the image, so a file EXTRA-ITEMS-DIR/foo will wind
+up at /foo in the final Docker image."
   (let ((closure (canonicalize-path closure))
         (id (docker-id path))
         (time (date->string (time-utc->date creation-time) "~4"))
@@ -166,7 +172,12 @@ space."
                                           (map symlink-source symlinks))))
                     (for-each delete-file-recursively
                               (map (compose topmost-component symlink-source)
-                                   symlinks)))))
+                                   symlinks))
+                    extra-items-dir
+                    (zero? (apply system* "tar" "-rf" "layer.tar"
+                                  "-C" extra-items-dir
+                                  (append %tar-determinism-options
+                                          '(".")))))))
 
            (with-output-to-file "config.json"
              (lambda ()
-- 
2.15.1