all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Creating Docker containers in Scheme
@ 2017-11-02 15:15 Roel Janssen
  2017-11-08  8:44 ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Roel Janssen @ 2017-11-02 15:15 UTC (permalink / raw)
  To: guix-devel

Dear Guix,

I'd like to create a Docker container from Scheme.  Looking at
guix/scripts/pack.scm, I believe something like this should be possible:

  (docker-image "my-container"
    (profile-derivation
      (packages->manifest (list hello coreutils))))

Is this something we could add to the the public interface of a module?

Kind regards,
Roel Janssen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Creating Docker containers in Scheme
  2017-11-02 15:15 Creating Docker containers in Scheme Roel Janssen
@ 2017-11-08  8:44 ` Ludovic Courtès
  2017-11-08  9:38   ` Roel Janssen
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2017-11-08  8:44 UTC (permalink / raw)
  To: Roel Janssen; +Cc: guix-devel

Hi,

Roel Janssen <roel@gnu.org> skribis:

> I'd like to create a Docker container from Scheme.  Looking at
> guix/scripts/pack.scm, I believe something like this should be possible:
>
>   (docker-image "my-container"
>     (profile-derivation
>       (packages->manifest (list hello coreutils))))

Move precisely:

  (mlet %store-monad ((profile (profile-derivation …)))
    (docker-image "my-container" profile))

> Is this something we could add to the the public interface of a module?

Sure.  For now the easiest solution would be to export ‘docker-image’
from (guix scripts pack).

Longer-term, we could rename (guix docker) to (guix build docker) and
move ‘docker-image’ to a new (guix docker) module, but perhaps we’d also
need a (guix pack) modules containing tools that are shared between the
docker and tarball backends of ‘guix pack’.

WDYT?

Ludo’.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Creating Docker containers in Scheme
  2017-11-08  8:44 ` Ludovic Courtès
@ 2017-11-08  9:38   ` Roel Janssen
  2017-11-08 13:55     ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Roel Janssen @ 2017-11-08  9:38 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


Ludovic Courtès writes:

> Hi,
>
> Roel Janssen <roel@gnu.org> skribis:
>
>> I'd like to create a Docker container from Scheme.  Looking at
>> guix/scripts/pack.scm, I believe something like this should be possible:
>>
>>   (docker-image "my-container"
>>     (profile-derivation
>>       (packages->manifest (list hello coreutils))))
>
> Move precisely:
>
>   (mlet %store-monad ((profile (profile-derivation …)))
>     (docker-image "my-container" profile))
>

Oh, of course! :)

Unfortunately, I cannot seem to get it to work.
Here's what I do (mind the GWL process- stuff):

--8<---------------cut here---------------start------------->8---
(define* (process->docker-derivation proc #:key (guile (default-guile)))
  "Return a Docker container that can run the PROCEDURE described in PROC, with
PROCEDURE's imported modules in its search path."
  (let ((name (process-full-name proc))
        (exp (process-procedure proc))
        (out (process-output-path proc))
        (packages (process-package-inputs proc)))
    (let ((out-str (if out (format #f "(setenv \"out\" ~s)" out) "")))
      (mlet %store-monad ((set-load-path
                           (load-path-expression (gexp-modules exp)))
                          (container (docker-image
                                      (string-append (process-full-name proc)
                                                      "-docker")
                                      (profile-derivation
                                       (packages->manifest packages)))))
        (gexp->derivation
         name
         (gexp
          (call-with-output-file (ungexp output)
            (lambda (port)
              (format port "# Docker image: ~a~%" (ungexp container)))))
         #:graft? #f)))))
--8<---------------cut here---------------end--------------->8---

And the error I get is:
  wrong-type-arg: string-prefix?

Is there anything obviously wrong here?

>> Is this something we could add to the the public interface of a module?
>
> Sure.  For now the easiest solution would be to export ‘docker-image’
> from (guix scripts pack).
>
> Longer-term, we could rename (guix docker) to (guix build docker) and
> move ‘docker-image’ to a new (guix docker) module, but perhaps we’d also
> need a (guix pack) modules containing tools that are shared between the
> docker and tarball backends of ‘guix pack’.
>
> WDYT?

It'd be nice to keep the (guix scripts ...) small, and only do
command-line handling.  So I think a (guix build docker), and a (guix
pack) module would be good.

>
> Ludo’.

Thanks for your time!

Kind regards,
Roel Janssen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Creating Docker containers in Scheme
  2017-11-08  9:38   ` Roel Janssen
@ 2017-11-08 13:55     ` Ludovic Courtès
  0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2017-11-08 13:55 UTC (permalink / raw)
  To: Roel Janssen; +Cc: guix-devel

Roel Janssen <roel@gnu.org> skribis:

> Ludovic Courtès writes:

[...]

>> Move precisely:
>>
>>   (mlet %store-monad ((profile (profile-derivation …)))
>>     (docker-image "my-container" profile))
>>
>
> Oh, of course! :)
>
> Unfortunately, I cannot seem to get it to work.
> Here's what I do (mind the GWL process- stuff):
>
> (define* (process->docker-derivation proc #:key (guile (default-guile)))
>   "Return a Docker container that can run the PROCEDURE described in PROC, with
> PROCEDURE's imported modules in its search path."
>   (let ((name (process-full-name proc))
>         (exp (process-procedure proc))
>         (out (process-output-path proc))
>         (packages (process-package-inputs proc)))
>     (let ((out-str (if out (format #f "(setenv \"out\" ~s)" out) "")))
>       (mlet %store-monad ((set-load-path
>                            (load-path-expression (gexp-modules exp)))
>                           (container (docker-image
>                                       (string-append (process-full-name proc)
>                                                       "-docker")
>                                       (profile-derivation
>                                        (packages->manifest packages)))))
                                        ^^
See above.  :-)

>         (gexp->derivation
>          name
>          (gexp
>           (call-with-output-file (ungexp output)
>             (lambda (port)
>               (format port "# Docker image: ~a~%" (ungexp container)))))
>          #:graft? #f)))))
>
> And the error I get is:
>   wrong-type-arg: string-prefix?
>
> Is there anything obviously wrong here?

Hmm, we’d need to see the backtrace, but it might be the fact that
‘profile-derivation’ is not bound (in the sense of >>=).

>>> Is this something we could add to the the public interface of a module?
>>
>> Sure.  For now the easiest solution would be to export ‘docker-image’
>> from (guix scripts pack).
>>
>> Longer-term, we could rename (guix docker) to (guix build docker) and
>> move ‘docker-image’ to a new (guix docker) module, but perhaps we’d also
>> need a (guix pack) modules containing tools that are shared between the
>> docker and tarball backends of ‘guix pack’.
>>
>> WDYT?
>
> It'd be nice to keep the (guix scripts ...) small, and only do
> command-line handling.  So I think a (guix build docker), and a (guix
> pack) module would be good.

Yes, I agree that this is the right direction.

Ludo’.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-08 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-02 15:15 Creating Docker containers in Scheme Roel Janssen
2017-11-08  8:44 ` Ludovic Courtès
2017-11-08  9:38   ` Roel Janssen
2017-11-08 13:55     ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.