gnu: docker: Allow setting host environment variables in oci-container-configuration.
* gnu/services/docker.scm (oci-container-configuration) [host-environment]: New field; (oci-sanitize-host-environment): sanitize it; (oci-container-shepherd-service): use it. * doc/guix.texi: Document it. Change-Id: I4d54d37736cf09f042a71cb0b6e673abc0948d9c Signed-off-by: Ludovic Courtès <ludo@gnu.org>master
parent
003c89a85c
commit
e68c1af4f4
|
@ -40580,6 +40580,23 @@ Overwrite the default command (@code{CMD}) of the image.
|
||||||
@item @code{entrypoint} (default: @code{""}) (type: string)
|
@item @code{entrypoint} (default: @code{""}) (type: string)
|
||||||
Overwrite the default entrypoint (@code{ENTRYPOINT}) of the image.
|
Overwrite the default entrypoint (@code{ENTRYPOINT}) of the image.
|
||||||
|
|
||||||
|
@item @code{host-environment} (default: @code{'()}) (type: list)
|
||||||
|
Set environment variables in the host environment where @command{docker
|
||||||
|
run} is invoked. This is especially useful to pass secrets from the
|
||||||
|
host to the container without having them on the @command{docker run}'s
|
||||||
|
command line: by setting the @code{MYSQL_PASSWORD} on the host and by passing
|
||||||
|
@code{--env MYSQL_PASSWORD} through the @code{extra-arguments} field, it is
|
||||||
|
possible to securely set values in the container environment. This field's
|
||||||
|
value can be a list of pairs or strings, even mixed:
|
||||||
|
|
||||||
|
@lisp
|
||||||
|
(list '(\"LANGUAGE\" . \"eo:ca:eu\")
|
||||||
|
\"JAVA_HOME=/opt/java\")
|
||||||
|
@end lisp
|
||||||
|
|
||||||
|
Pair members can be strings, gexps or file-like objects. Strings are passed
|
||||||
|
directly to @code{make-forkexec-constructor}.
|
||||||
|
|
||||||
@item @code{environment} (default: @code{'()}) (type: list)
|
@item @code{environment} (default: @code{'()}) (type: list)
|
||||||
Set environment variables. This can be a list of pairs or strings, even mixed:
|
Set environment variables. This can be a list of pairs or strings, even mixed:
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
|
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
|
||||||
;;; Copyright © 2020 Jesse Dowell <jessedowell@gmail.com>
|
;;; Copyright © 2020 Jesse Dowell <jessedowell@gmail.com>
|
||||||
;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
|
;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
|
||||||
;;; Copyright © 2023 Giacomo Leidi <goodoldpaul@autistici.org>
|
;;; Copyright © 2023, 2024 Giacomo Leidi <goodoldpaul@autistici.org>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -285,6 +285,11 @@ found!")
|
||||||
name el)))))
|
name el)))))
|
||||||
value))
|
value))
|
||||||
|
|
||||||
|
(define (oci-sanitize-host-environment value)
|
||||||
|
;; Expected spec format:
|
||||||
|
;; '(("HOME" . "/home/nobody") "JAVA_HOME=/java")
|
||||||
|
(oci-sanitize-mixed-list "host-environment" value "="))
|
||||||
|
|
||||||
(define (oci-sanitize-environment value)
|
(define (oci-sanitize-environment value)
|
||||||
;; Expected spec format:
|
;; Expected spec format:
|
||||||
;; '(("HOME" . "/home/nobody") "JAVA_HOME=/java")
|
;; '(("HOME" . "/home/nobody") "JAVA_HOME=/java")
|
||||||
|
@ -330,6 +335,24 @@ but ~a was found") el))))
|
||||||
(entrypoint
|
(entrypoint
|
||||||
(maybe-string)
|
(maybe-string)
|
||||||
"Overwrite the default entrypoint (@code{ENTRYPOINT}) of the image.")
|
"Overwrite the default entrypoint (@code{ENTRYPOINT}) of the image.")
|
||||||
|
(host-environment
|
||||||
|
(list '())
|
||||||
|
"Set environment variables in the host environment where @command{docker run}
|
||||||
|
is invoked. This is especially useful to pass secrets from the host to the
|
||||||
|
container without having them on the @command{docker run}'s command line: by
|
||||||
|
setting the @code{MYSQL_PASSWORD} on the host and by passing
|
||||||
|
@code{--env MYSQL_PASSWORD} through the @code{extra-arguments} field, it is
|
||||||
|
possible to securely set values in the container environment. This field's
|
||||||
|
value can be a list of pairs or strings, even mixed:
|
||||||
|
|
||||||
|
@lisp
|
||||||
|
(list '(\"LANGUAGE\" . \"eo:ca:eu\")
|
||||||
|
\"JAVA_HOME=/opt/java\")
|
||||||
|
@end lisp
|
||||||
|
|
||||||
|
Pair members can be strings, gexps or file-like objects. Strings are passed
|
||||||
|
directly to @code{make-forkexec-constructor}."
|
||||||
|
(sanitizer oci-sanitize-host-environment))
|
||||||
(environment
|
(environment
|
||||||
(list '())
|
(list '())
|
||||||
"Set environment variables inside the container. This can be a list of pairs
|
"Set environment variables inside the container. This can be a list of pairs
|
||||||
|
@ -450,6 +473,8 @@ to the @command{docker run} invokation."
|
||||||
(let* ((docker-command (file-append docker-cli "/bin/docker"))
|
(let* ((docker-command (file-append docker-cli "/bin/docker"))
|
||||||
(user (oci-container-configuration-user config))
|
(user (oci-container-configuration-user config))
|
||||||
(group (oci-container-configuration-group config))
|
(group (oci-container-configuration-group config))
|
||||||
|
(host-environment
|
||||||
|
(oci-container-configuration-host-environment config))
|
||||||
(command (oci-container-configuration-command config))
|
(command (oci-container-configuration-command config))
|
||||||
(provision (oci-container-configuration-provision config))
|
(provision (oci-container-configuration-provision config))
|
||||||
(image (oci-container-configuration-image config))
|
(image (oci-container-configuration-image config))
|
||||||
|
@ -471,7 +496,9 @@ to the @command{docker run} invokation."
|
||||||
"--name" #$name
|
"--name" #$name
|
||||||
#$@options #$@extra-arguments #$image #$@command)
|
#$@options #$@extra-arguments #$image #$@command)
|
||||||
#:user #$user
|
#:user #$user
|
||||||
#:group #$group))
|
#:group #$group
|
||||||
|
#:environment-variables
|
||||||
|
(list #$@host-environment)))
|
||||||
(stop
|
(stop
|
||||||
#~(lambda _
|
#~(lambda _
|
||||||
(invoke #$docker-command "rm" "-f" #$name)))
|
(invoke #$docker-command "rm" "-f" #$name)))
|
||||||
|
|
Reference in New Issue