From patchwork Mon Jun 19 15:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Graham James Addis X-Patchwork-Id: 51075 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 78CA827BBE9; Mon, 19 Jun 2023 16:41:14 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D5FA627BBE2 for ; Mon, 19 Jun 2023 16:41:12 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qBGzj-0000bs-Dx; Mon, 19 Jun 2023 11:40:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBGyB-0000JB-ML for guix-patches@gnu.org; Mon, 19 Jun 2023 11:39:07 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBGyB-000835-7I; Mon, 19 Jun 2023 11:39:07 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qBGy7-00032r-6b; Mon, 19 Jun 2023 11:39:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64173] [PATCH 1/1] guix: pack: docker add docker-entry-point options Resent-From: Graham James Addis Original-Sender: "Debbugs-submit" Resent-CC: mail@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Mon, 19 Jun 2023 15:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64173 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64173@debbugs.gnu.org Cc: Graham James Addis , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.168718911711644 (code B ref -1); Mon, 19 Jun 2023 15:39:02 +0000 Received: (at submit) by debbugs.gnu.org; 19 Jun 2023 15:38:37 +0000 Received: from localhost ([127.0.0.1]:57039 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBGxg-00031j-4x for submit@debbugs.gnu.org; Mon, 19 Jun 2023 11:38:36 -0400 Received: from lists.gnu.org ([209.51.188.17]:52422) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBGxd-00031a-2q for submit@debbugs.gnu.org; Mon, 19 Jun 2023 11:38:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBGxc-0000Fv-Rq for guix-patches@gnu.org; Mon, 19 Jun 2023 11:38:32 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBGxa-0007yS-PM for guix-patches@gnu.org; Mon, 19 Jun 2023 11:38:32 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f907f311ccso26055385e9.1 for ; Mon, 19 Jun 2023 08:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687189109; x=1689781109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/KBTE5bbZSlxHdWXXgpjYwi12ZxAJzPcpAPDN/T0Sao=; b=UqMPaV0fUq2XlwUVUo51k9dEQZb4vBKyNonRdmyyVqplfVlypD2tUER8YLeol40ly+ 9JuRcxX8QQ6TQA/1tCZAXv0S9vKkHesYG3qMeHutS9FRs+IRJHLXzrzAGLEzqhs89vwe 9nHZPx8d4PDJ8+e/WZqN/6w61gGtE0IPu6RVrLN3Mj5kcWWdDu3tmOPuVP+AStsOADlN AfLvcE8wSP5QNOVphf2tcHuWxU2h2Zw6XXX4uCfXjnJbV+Ha7Vx+1iw/vTS0v8//atSo wzxvrg3G0p98trDUr1a8JNTRE7lZ0Qz6KPUd2kwdvE0/KMSizgmInaH0IR1mu+VF7Azz nYPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687189109; x=1689781109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/KBTE5bbZSlxHdWXXgpjYwi12ZxAJzPcpAPDN/T0Sao=; b=gFk1rJQ5ZAom1Li+63zN3Q6r4vZLCFhMhYwv0yg1JTCK6VP+arSX4HehPYRV2eHal6 2mmZ211zBhW8sHAjFXyeypM05Z8eBKMGCzDDe2W2pJcyT70U9rz1MdxJrpsYuK3JRRPJ pzWuDUpqkntlkrzt3tdIL0zsLzZX7EGE54/lovc6FgLiWXfrXzRadTJu+1n7yFYIUQxv c3tB8MKiVarQTq16SlV4dsXacNGnRx0P4A4FebfCOEDRwWKyjiS92yIGQnRXYDfzA8Ak DiWuE0jLEOWcwHqUJjOLGjY+8uNFNFS9TY46k7m8+uBszujcGWm19UKpg+NJTEpOG3/s +Imw== X-Gm-Message-State: AC+VfDy7P2TjbMEdX0rVQN+s3eU5TokM4c9oAuV8bNHQSWHlSQkfvkdn 2ngR3KGj45m+hEDOBP3brJyN2Pav8Zk= X-Google-Smtp-Source: ACHHUZ7TsNAJFnL6yMqz+OFPrFvUGYWFEVVCsrik+jcFzLmcuHtHDQ41hMwX9PgdLhcoRqBev6H+Hg== X-Received: by 2002:a05:600c:290b:b0:3f8:d8f7:ce23 with SMTP id i11-20020a05600c290b00b003f8d8f7ce23mr8211101wmd.5.1687189108937; Mon, 19 Jun 2023 08:38:28 -0700 (PDT) Received: from guix-test.home ([2a00:23c7:59a9:c901:41c8:db68:b8b1:9808]) by smtp.gmail.com with ESMTPSA id y17-20020a1c4b11000000b003f7f249e7dfsm10306432wma.4.2023.06.19.08.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 08:38:28 -0700 (PDT) From: Graham James Addis X-Google-Original-From: Graham James Addis Date: Mon, 19 Jun 2023 16:38:01 +0100 Message-Id: <3c7d4e0a42d650f808882f8b425284809b077220.1687188729.git.graham@addis.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=grahamjamesaddis@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Mon, 19 Jun 2023 11:40:39 -0400 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/scripts/pack.scm: add support for parameters in entry-point (docker-entry-point-spec-option-parser): add function to parse --docker-entry-point (docker-image): Add function (form_entry_point) to handle --entry-point vs --docker-entry-point precedence (docker-image): change call to (build-docker-image) to use (form-entry-point) (%default-options): add dafault for --docker-entry-point option (%docker-format-options): parser for --docker-entry-point (show-docker-format-options): help for --docker-format-options (show-docker-format-options/detailed): detailed help for --docker-format-options (%options): add flag for --help-docker-format and add parser for --docker-format-options (extra-options): add extra options for docker (guix.texi): add documentation --- doc/guix.texi | 16 +++++- guix/scripts/pack.scm | 113 ++++++++++++++++++++++++++++++++---------- 2 files changed, 103 insertions(+), 26 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index c961f706ec..8d8044f73c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -116,6 +116,7 @@ Copyright @copyright{} 2023 Karl Hallsby@* Copyright @copyright{} 2023 Nathaniel Nicandro@* Copyright @copyright{} 2023 Tanguy Le Carrour@* +Copyright @copyright{} 2023 Graham James Addis@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -7346,7 +7347,7 @@ Invoking guix pack @env{GUIX_EXECUTION_ENGINE} environment variable accordingly. @end quotation -@cindex entry point, for Docker images +@cindex entry point, for Docker and Singularity images @item --entry-point=@var{command} Use @var{command} as the @dfn{entry point} of the resulting pack, if the pack format supports it---currently @code{docker} and @code{squashfs} (Singularity) @@ -7369,6 +7370,19 @@ Invoking guix pack docker run @var{image-id} @end example +@cindex entry point, for Docker images +@item --docker-entry-point=@var{command} +Use @var{command} as the @dfn{entry point} of the resulting pack. This option +overrides any value passed to @code{--entry-point} and can appear multiple +times on the command line. The first instance of @var{command} is used as th +@dfn{entry point} and subsequent values are used as the parameters. +@var{command} must be relative to the profile contained in the +pack. + +@example +guix pack -f docker --docker-entry-point=bin/guile --docker-entry-point="--help" guile +@end example + @item --expression=@var{expr} @itemx -e @var{expr} Consider the package @var{expr} evaluates to. diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index 0dc9979194..79739cb465 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2020, 2021, 2022, 2023 Maxim Cournoyer ;;; Copyright © 2020 Eric Bavier ;;; Copyright © 2022 Alex Griffin +;;; Copyright © 2023 Graham James Addis ;;; ;;; This file is part of GNU Guix. ;;; @@ -193,6 +194,16 @@ (define (symlink-spec-option-parser opt name arg result) (leave (G_ "~a: invalid symlink specification~%") arg)))) +(define (docker-entry-point-spec-option-parser opt name arg result) + "A SRFI-37 opion parser for the --docker-entry-point option. The spec +takes multiple occurances. The entries are used in the exec form for the +docker entry-point. The first is used as the command and subsequent values +are used as parameters." + (let ((docker-entry-point (assoc-ref result 'docker-entry-point))) + (alist-cons 'docker-entry-point + (append docker-entry-point (list arg)) + (alist-delete 'docker-entry-point result eq?)))) + (define (set-utf8-locale profile) "Configure the environment to use the \"en_US.utf8\" locale provided by the GLIBC-UT8-LOCALES package." @@ -626,6 +637,7 @@ (define* (docker-image name profile (guix build utils) (guix profiles) (guix search-paths) (srfi srfi-1) (srfi srfi-19) + (ice-9 optargs) (ice-9 match)) #$(procedure-source manifest->friendly-name) @@ -653,31 +665,50 @@ (define* (docker-image name profile `((directory "/tmp" ,(getuid) ,(getgid) #o1777) ,@(append-map symlink->directives '#$symlinks))) - (setenv "PATH" #+(file-append archiver "/bin")) - - (build-docker-image #$output - (map store-info-item - (call-with-input-file "profile" - read-reference-graph)) - #$profile - #:repository (manifest->friendly-name - (profile-manifest #$profile)) - #:database #+database - #:system (or #$target %host-type) - #:environment environment - #:entry-point - #$(and entry-point - #~(list (string-append #$profile "/" - #$entry-point))) - #:extra-files directives - #:compressor #+(compressor-command compressor) - #:creation-time (make-time time-utc 0 1)))))) - - (gexp->derivation (string-append name ".tar" - (compressor-extension compressor)) - build - #:target target - #:references-graphs `(("profile" ,profile)))) + (define (form-entry-point + docker-entry-point + prefix entry-point) + ;; construct entry-point parameter for build-docker-image + ;; overriding the legacy use of --entry-point from the command + ;; line when the --docker-entry-point options are used + (cond + ;; if CLI --docker-entry-point values are available use them + ((and docker-entry-point (not (null? docker-entry-point)) + (cons + (string-append prefix "/" (car docker-entry-point)) + (cdr docker-entry-point)))) + ;; legacy behaviour uses --entry-point and prefixes with #$profile + (entry-point (list (string-append prefix "/" entry-point))) + ('()))) ;empty list returned if no conditions are met + + (let-keywords '#$extra-options #f ((docker-entry-point #f)) + + (setenv "PATH" #+(file-append archiver "/bin")) + + (build-docker-image #$output + (map store-info-item + (call-with-input-file "profile" + read-reference-graph)) + #$profile + #:repository (manifest->friendly-name + (profile-manifest #$profile)) + #:database #+database + #:system (or #$target %host-type) + #:environment environment + #:entry-point (form-entry-point + docker-entry-point + #$profile + #$entry-point) + #:extra-files directives + #:compressor #+(compressor-command compressor) + #:creation-time (make-time time-utc 0 1)))))) + ) + + (gexp->derivation (string-append name ".tar" + (compressor-extension compressor)) + build + #:target target + #:references-graphs `(("profile" ,profile)))) ;;; @@ -1346,6 +1377,7 @@ (define %default-options (debug . 0) (verbosity . 1) (symlinks . ()) + (docker-entry-point . ()) (compressor . ,(first %compressors)))) (define %formats @@ -1428,6 +1460,29 @@ (define (show-rpm-format-options/detailed) (newline) (exit 0)) + +(define %docker-format-options + (list (option '("docker-entry-point") #t #f + docker-entry-point-spec-option-parser))) + +(define (show-docker-format-options) + (display (G_ " + --help-docker-format + list options specific to the DOCKER format"))) + +(define (show-docker-format-options/detailed) + (display (G_ " + --docker-entry-point=COMMAND/PARAMETER + Value(s) to use for the Docker EntryPoint field. + Multiple instances are accepted. The first use is + supplied as the COMMAND in the Docker EntryPoint, + subsequent uses are supplied as PARAMETERs in the + Docker EntryPoint. + This overrides any COMMAND provided in the + --entry-point option.")) + (newline) + (exit 0)) + (define %options ;; Specifications of the command-line options. (cons* (option '(#\h "help") #f #f @@ -1508,8 +1563,13 @@ (define %options (lambda args (show-rpm-format-options/detailed))) + (option '("help-docker-format") #f #f + (lambda args + (show-docker-format-options/detailed))) + (append %deb-format-options %rpm-format-options + %docker-format-options %transformation-options %standard-build-options %standard-cross-build-options @@ -1528,6 +1588,7 @@ (define (show-help) (newline) (show-deb-format-options) (show-rpm-format-options) + (show-docker-format-options) (newline) (display (G_ " -f, --format=FORMAT build a pack in the given FORMAT")) @@ -1696,6 +1757,8 @@ (define-command (guix-pack . args) (process-file-arg opts 'preun-file) #:postun-file (process-file-arg opts 'postun-file))) + ('docker + (list #:docker-entry-point (assoc-ref opts 'docker-entry-point))) (_ '()))) (target (assoc-ref opts 'target)) (bootstrap? (assoc-ref opts 'bootstrap?))