caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Hans Ole Rafaelsen <hrafaelsen@gmail.com>,
	David Scott <scott.dj@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Create a deployable application unit from OPAM?
Date: Fri, 30 Mar 2018 00:44:58 +0200	[thread overview]
Message-ID: <d46345a2-0948-c41e-4f05-f2e970c10e58@gerd-stolpmann.de> (raw)
In-Reply-To: <CALs4vDbWKuSGj12WV_4A+KXVjJa+mK3Mk-ZN9gJSowHfpm81_w@mail.gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 5440 bytes --]

On 29.03.18 20:50, Hans Ole Rafaelsen wrote:

> Hi David,
>
> It helps a bit. But my biggest problem is that the Ocaml application
> (main.exe in your example) has dependencies to other Ocaml libraries
> built using OPAM. I need to find a way to find those dependencies and
> make sure that the paths are resolved correctly once libraries have
> have been copied to the image.
As long as the files are in the findlib tree (i.e. .opam/lib), you can
try to create a copy of the tree with the required files, and set a few
environment variables before running your code:

 - CAML_LD_LIBRARY_PATH: set this to the stublibs directory
 - OCAMLPATH set this to the root of the tree.

AFAIK ocsigen respects OCAMLPATH at runtime when dynamically loading
libraries. However, I've never tried.

The question is then which files you need. I guess at least:
 - the .cmi and .cmxs files from the subdirectories in .opam/lib

You definitely do not need:
 - any bytecode files (.cmo, cma, .so in stublibs)
 - .cmx, .cmxa

For figuring out the minimal set of ocaml packages for running, you
could look into: ocamlfind query -recursive

As you are mostly interested in deploying, and not necessarily
relocating, another strategy might be to keep the file tree at the place
where the build happens, and to just remove files you don't need. (Or
just pick the right files in your Dockerfile, and ensure that the files
end up at the same place in the image.)

These are just some wild ideas. Ocsigen is in particular complicated
because of the dynamic loading.

Gerd
>
> -- 
> Hans Ole
>
> On Thu, Mar 29, 2018 at 8:13 PM, David Scott <scott.dj@gmail.com
> <mailto:scott.dj@gmail.com>> wrote:
>
>     Hi,
>
>     I had a quick go at creating something with Docker: (and alpine
>     since I was more familiar with it, but I suspect a similar
>     technique would work with ubuntu)
>
>     https://github.com/djs55/experiments/pull/1
>     <https://github.com/djs55/experiments/pull/1>
>
>     It uses `opam` to build a simple OCaml example (taken from
>     cryptokit) which needs `libgmp` at runtime. The `Dockerfile` has a
>     slightly hacky attempt to detect the runtime dependency:
>
>     opam depext -n cryptokit | grep -v '#' | grep '\-dev' | while read
>     in; do basename "$in" -dev; done > needed-packages.txt
>
>     It assumes that
>
>     - all external C libraries have an alpine depext called foo-dev
>     - foo-dev has a corresponding runtime package called foo
>
>     and installs these `foo` in an output minimal alpine image (i.e.
>     one without the development tools or other unnecessary stuff)
>
>     Another approach would be to use `ldd` or `objdump` recursively to
>     find libraries and copy only those binaries into the output
>     (possibly using `FROM scratch`?)
>
>     I don't know if this will help -- I realise my test case is a bit
>     minimal :-)
>
>     Cheers,
>     Dave
>
>
>     On Thu, Mar 29, 2018 at 5:31 PM, Hans Ole Rafaelsen
>     <hrafaelsen@gmail.com <mailto:hrafaelsen@gmail.com>> wrote:
>
>         Hi,
>
>         I have small application written using Ocsigen. Ocaml and the
>         rest of the development environment is installed using OPAM.
>
>         Now I want to install this application on a few other nodes,
>         without having to bring bring along the whole development
>         process for deployment on each node. What I want to end up
>         with, is a single unit, e.g a tar-file, a docker container or
>         similar, that can be copied and deployed to the target nodes.
>         This unit should only contain the binaries needed to run the
>         application.
>
>         I have tried to ask on the Ocsigen mailing-list how do do this
>         for Ocsigen applications, but without success. But I guess the
>         problem is more related to how to deploy applications built
>         using OPAM. I did not find any way to do this with OPAM, but I
>         might have missed something. I have tried to copy all the
>         binary files (.so, .cmxa .cmxs, etc) from the OPAM directory
>         and setting the environment variables to point the this new
>         location, but without much success. When starting
>         ocsigenserver it was not able to solve all symbols. Looking
>         more into the problem, it looks like binaries such as
>         ocsigenserver has hard coded the location of the OPAM
>         development environment. Might be possible to override this
>         using environment variables, but I'm not sure how. So I gave
>         up on this track.
>
>
>         Is there a way to generate such a deployable unit from OPAM
>         development environment?
>
>         Do anyone have some tips / best practice on how to deploy
>         applications built using OPAM?
>
>         (I'm developing and want to deploy on Ubuntu 16.04.)
>
>         Regards,
>
>         Hans Ole Rafaelsen
>
>
>
>
>     -- 
>     Dave Scott
>
>

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #1.1.2: Type: text/html, Size: 11113 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2018-03-29 22:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29 16:31 Hans Ole Rafaelsen
2018-03-29 18:13 ` David Scott
2018-03-29 18:50   ` Hans Ole Rafaelsen
2018-03-29 22:44     ` Gerd Stolpmann [this message]
2018-03-30 14:11 ` Louis Gesbert
2018-04-02 18:17   ` Hans Ole Rafaelsen
2018-04-03  0:25   ` Francois BERENGER

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d46345a2-0948-c41e-4f05-f2e970c10e58@gerd-stolpmann.de \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@inria.fr \
    --cc=hrafaelsen@gmail.com \
    --cc=scott.dj@gmail.com \
    /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.
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 NNTP newsgroup(s).