unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 49149@debbugs.gnu.org
Subject: [bug#49149] [PATCH 0/7] Add deb format for guix pack.
Date: Sat, 03 Jul 2021 23:21:05 -0400	[thread overview]
Message-ID: <87zgv2228u.fsf@gmail.com> (raw)
In-Reply-To: <87bl7mkvvu.fsf@gnu.org> ("Ludovic Courtès"'s message of "Thu, 01 Jul 2021 15:26:45 +0200")

[-- Attachment #1: Type: text/plain, Size: 2500 bytes --]

Hi!

Ludovic Courtès <ludo@gnu.org> writes:

> Hi,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> Ludovic Courtès <ludo@gnu.org> writes:
>>
>>> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>>>
>>>> Instead of just naming them by their pack type, add information from the
>>>> package(s) they contain to make it easier to differentiate them.
>>>>
>>>> * guix/scripts/pack.scm (define-with-source): New macro.
>>>> (manifest->friendly-name): Extract procedure from ...
>>>> (docker-image): ... here, now defined via the above macro.  Adjust REPOSITORY
>>>> argument value accordingly.
>>>> (guix-pack): Derive NAME using MANIFEST->FRIENDLY-NAME.
>>>
>>> [...]
>>>
>>>> -            (define tag
>>>> -              ;; Compute a meaningful "repository" name, which will show up in
>>>> -              ;; the output of "docker images".
>>>> -              (let ((manifest (profile-manifest #$profile)))
>>>> -                (let loop ((names (map manifest-entry-name
>>>> -                                       (manifest-entries manifest))))
>>>> -                  (define str (string-join names "-"))
>>>> -                  (if (< (string-length str) 40)
>>>> -                      str
>>>> -                      (match names
>>>> -                        ((_) str)
>>>> -                        ((names ... _) (loop names))))))) ;drop one entry
>>>
>>> I think this should not be factorized because the requirements are very
>>> Docker-dependent.  Once factorized, it becomes easy to overlook this.
>>
>> Hmm, I'm not a docker format expert, but my quick reading about it
>> turned no restrictions about what a docker image label should look like?
>> So perhaps it is not specially Docker-dependent.
>
> It’s a hack specifically written with Docker repository names in mind,
> and the 40-or-so character limit, for instance.

The actual name length requirement for a Docker repository name seems to
be that it must be between 2 and 255 characters [0]; the attached patch
ensure that this is respected.

> To me it’s a case where factorization isn’t beneficial.  Even if there’s
> a similar procedure used in a different context, it’s still a different
> context with different constraints.  My 2¢!

It seems to me that with the attached patch we get to share what used to
be a Docker-specific abstraction without any added risk (have our cake
and it eat to!).

What do you think?

Thanks,

Maxim


[-- Attachment #2: 0001-guix-docker-Ensure-repository-name-length-limits-are.patch --]
[-- Type: text/x-patch, Size: 2731 bytes --]

From f3dc90213423bf0a087245bd4bfc8c4a828d4df1 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sat, 3 Jul 2021 23:08:15 -0400
Subject: [PATCH] guix: docker: Ensure repository name length limits are met.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* guix/docker.scm (canonicalize-repository-name): Fix typo in doc.  Capture
repository name length limits and ensure they are met, by either truncating or
padding the normalized name.

Reported-by: Ludovic Courtès <ludo@gnu.org>
---
 guix/docker.scm | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/guix/docker.scm b/guix/docker.scm
index bd952e45ec..4239ccdf9c 100644
--- a/guix/docker.scm
+++ b/guix/docker.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2017, 2018, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
+;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -59,8 +60,13 @@
     (container_config . #nil)))
 
 (define (canonicalize-repository-name name)
-  "\"Repository\" names are restricted to roughtl [a-z0-9_.-].
+  "\"Repository\" names are restricted to roughly [a-z0-9_.-].
 Return a version of TAG that follows these rules."
+  ;; Refer to https://docs.docker.com/docker-hub/repos/.
+  (define min-length 2)
+  (define padding-character #\a)
+  (define max-length 255)
+
   (define ascii-letters
     (string->char-set "abcdefghijklmnopqrstuvwxyz"))
 
@@ -70,11 +76,21 @@ Return a version of TAG that follows these rules."
   (define repo-char-set
     (char-set-union char-set:digit ascii-letters separators))
 
-  (string-map (lambda (chr)
-                (if (char-set-contains? repo-char-set chr)
-                    chr
-                    #\.))
-              (string-trim (string-downcase name) separators)))
+  (define normalized-name
+    (string-map (lambda (chr)
+                  (if (char-set-contains? repo-char-set chr)
+                      chr
+                      #\.))
+                (string-trim (string-downcase name) separators)))
+
+  (let ((l (string-length normalized-name)))
+    (match l
+      ((? (cut > <> max-length))
+       (string-take normalized-name max-length))
+      ((? (cut < <> min-length ))
+       (string-append normalized-name
+                      (make-string (- min-length l) padding-character)))
+      (_ normalized-name))))
 
 (define* (manifest path id #:optional (tag "guix"))
   "Generate a simple image manifest."
-- 
2.32.0


  reply	other threads:[~2021-07-04  3:22 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21  6:10 [bug#49149] [PATCH 0/7] Add deb format for guix pack Maxim Cournoyer
2021-06-21  6:11 ` [bug#49149] [PATCH 1/7] pack: Extract builder code from self-contained-tarball Maxim Cournoyer
2021-06-21  6:11   ` [bug#49149] [PATCH] tentatively reuse rlib for cargo-build-system Maxim Cournoyer
2021-06-21 20:28     ` Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 2/7] pack: Factorize base tar options Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 3/7] pack: Fix typo Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 4/7] pack: Improve naming of the packs store file names Maxim Cournoyer
2021-06-21 18:11     ` Maxime Devos
2021-06-22 14:03       ` Maxim Cournoyer
2021-06-23 10:22         ` Maxime Devos
2021-06-24  4:40           ` [bug#49149] [PATCH v2 1/7] pack: Extract builder code from self-contained-tarball Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 2/7] pack: Factorize base tar options Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 3/7] pack: Fix typo Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 4/7] pack: Improve naming of the packs store file names Maxim Cournoyer
2021-06-26  5:03               ` [bug#49149] [PATCH 0/7] Add deb format for guix pack Maxim Cournoyer
2021-06-30 10:13               ` Ludovic Courtès
2021-06-30 18:36                 ` Maxim Cournoyer
2021-07-01 13:26                   ` Ludovic Courtès
2021-07-04  3:21                     ` Maxim Cournoyer [this message]
2021-07-05 16:14                       ` Ludovic Courtès
2021-07-05 20:42                         ` Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 5/7] pack: Prevent duplicate files in tar archives Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 6/7] tests: pack: Fix compressor extension Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 7/7] pack: Add support for the deb format Maxim Cournoyer
2021-06-26 16:58               ` Maxime Devos
2021-06-29 19:20                 ` bug#49149: [PATCH 0/7] Add deb format for guix pack Maxim Cournoyer
2021-06-30 10:10               ` [bug#49149] " Ludovic Courtès
2021-06-24  4:44           ` [bug#49149] [PATCH 4/7] pack: Improve naming of the packs store file names Maxim Cournoyer
2021-06-23 21:16       ` [bug#49149] [PATCH 0/7] Add deb format for guix pack Ludovic Courtès
2021-06-21  6:12   ` [bug#49149] [PATCH 5/7] pack: Prevent duplicate files in tar archives Maxim Cournoyer
2021-06-30 10:06     ` [bug#49149] [PATCH 0/7] Add deb format for guix pack Ludovic Courtès
2021-06-30 18:16       ` Maxim Cournoyer
2021-07-01 13:24         ` Ludovic Courtès
2021-06-21  6:12   ` [bug#49149] [PATCH 6/7] tests: pack: Fix compressor extension Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 7/7] pack: Add support for the deb format Maxim Cournoyer
2021-06-21 16:44 ` [bug#49149] Add deb format for guix pack jgart via Guix-patches via
2021-06-23 21:28 ` [bug#49149] [PATCH 0/7] " Ludovic Courtès
2021-06-29 17:49   ` Maxim Cournoyer
2021-06-30  9:15     ` Ludovic Courtès
2021-06-30 13:49       ` zimoun
2021-06-30 15:06         ` zimoun
2021-06-30 16:55           ` Maxim Cournoyer
2021-06-30 16:54         ` Maxim Cournoyer
2021-06-30 17:28         ` Maxim Cournoyer
2021-06-30 17:36           ` Maxim Cournoyer
2021-06-30 17:47           ` zimoun
2021-06-30 19:20             ` Maxim Cournoyer
2021-07-01 13:08               ` zimoun
2021-06-30 16:42       ` Maxim Cournoyer
2021-07-01 13:20         ` Ludovic Courtès
2021-07-01 13:52           ` zimoun
2021-07-05 16:17             ` Ludovic Courtès

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=87zgv2228u.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=49149@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /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).