caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Louis Gesbert <louis.gesbert@ocamlpro.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Create a deployable application unit from OPAM?
Date: Fri, 30 Mar 2018 16:11:49 +0200	[thread overview]
Message-ID: <4945274.q1Lr0Fu7B2@agaric> (raw)
In-Reply-To: <CALs4vDbJ+vjWhE3tNyz54wKyQwJ3HV_6N1=94dZs_vQzEK_MxQ@mail.gmail.com>

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

There is no perfect solution at the moment, as there are still some hiccups with relocation of quite a few opam packages, but there are a few options:

1. Not precisely what you were asking for, since it involves re-compiling, but opam-bundle¹ can generate an all-in-one package that can easily be deployed to a different system and will bootstrap OCaml, opam, the packages and their dependencies, and can put wrappers for the binaries to your PATH. This takes a while, but avoids any relocation problems and is quite reliable.
The bundle could also be used as base for a container, or even copied across similar hosts (to the same location), and just the wrappers reinstalled.

2. opam 2.0 has an `opam install --destdir` option, that you could use to copy the installed artefacts of the required packages to some prefix (be sure to reinstall all the dependencies, or start from an empty switch). You could then tar/gz that prefix, and copy it across hosts.

3. in a simpler way, you could just copy the opam switch across hosts. With opam 2, all metadata is gathered in <switch-prefix>/.opam-switch/, so omit that subdirectory and you just get a "normal" Linux prefix (i.e. with bin/, lib/, etc. subdirectories).

Of course, 2. and 3. can hit relocation issues, depending on what the packages you are interested in use (e.g. ocsigenserver seems to have specific needs). As Gerd mentionned, specifying `CAML_LD_LIBRARY_PATH` and `OCAMLPATH` (and maybe a few others²) may help.
And none of these reduce the end result to "just the binaries needed", although 2. might help a little by letting you choose which packages get into the dest-prefix. I am not aware of a way to do this automatically. A vast super-appoximation could be to just ignore opam build-dependencies: `opam reinstall --destdir SOME_TEMP_PREFIX $(opam list --installed --rec --required-by PACKAGES --nobuild --short)`, on the origin host, then package and ship SOME_TEMP_PREFIX, possibly with wrappers to set the required PATH variables.

These are just a few clues, but hope this helps!

Louis Gesbert — OCamlPro



¹ https://github.com/AltGr/opam-bundle
² https://github.com/ocaml/opam-repository/issues/10863#issuecomment-347174662

> - Hans Ole Rafaelsen, 29/03/2018 18:31 -
> 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
> 
> 

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2018-03-30 14:13 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
2018-03-30 14:11 ` Louis Gesbert [this message]
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=4945274.q1Lr0Fu7B2@agaric \
    --to=louis.gesbert@ocamlpro.com \
    --cc=caml-list@inria.fr \
    /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).