[Nix-dev] Question about dockerTools layering

Luca Bruno lethalman88 at gmail.com
Sun Sep 25 15:13:21 CEST 2016


You can keep the referencing image just like before. What matters is that
node_modules is both in the base and in the derived image. dockerTools will
take care of deduplication (there's a new PR about that for fixing it, but
that's the idea).

On Sun, Sep 25, 2016 at 11:58 AM, Tobias Pflug <tobias.pflug at gmx.net> wrote:

> I just realised that my initial mail was composed in html - sorry for that
> x__X
>
> Anyway, I want to quickly expand on my confusion: I don’t understand how to
> reference between the two images.
>
> What I have right now is a derivation that symlinks `assets` and
> `node_modules` and
> I create a docker image which contains just that. Now lets say I split out
> `node_modules`:
>
> nodeModulesImage = pkgs.dockerTools.buildImage {
>   name = “node_modules”;
>   contents = [ node_modules ];
>   # I guess I need to symlink the node_modules to some absolute path?
> };
>
> dockerImage = pkgs.dockerTools.buildImage {
>   name = “app-foo”;
>   fromImage = nodeModulesImage;
>   conents = [ app ];
>   config = { … };
> };
>
> app = stdenv.mkDerivation {
>>   installPhase = ‘’
>    # how do I reference the node_modules now ?
>   ‘';
> };
>
> How exactly should I go about this? How do I reference between those
> images?
> I am still lost ;) Maybe this email makes my problem a bit clearer.
>
> Thanks!
>
> br,
> Tobi
>
> > On 23 Sep 2016, at 22:01, Luca Bruno <lethalman88 at gmail.com> wrote:
> >
> > Yes, you can create an image with only node_modules and then layer on
> top of it another image with fromImage.
> >
> > You can make the node_modules symlink in the base image. Then only
> update assets in the upper image.
> >
> > On Fri, Sep 23, 2016 at 8:38 PM, Tobias Pflug <Tobias.Pflug at gmx.net>
> wrote:
> > Hi,
> >
> > I recently started using dockerTools.buildImage for a nodejs based
> project. It's working
> > fine but I am hitting a mental block trying to introduce layers - I
> don't want to always push
> > around node_modules.
> >
> > My current setup is something like the following:
> >
> > # default.nix
> > dockerImage = with pkgs; dockerTools.buildImage {
> >   name = "foo";
> >   contents = [ nodejsApp ];
> >   config = {
> >     Cmd = [ "${nodejs-6_x}/bin/node" "${nodejsApp}/index.js" ];
> >     WorkingDir = "${nodejsApp}"
> >   };
> > };
> >
> > # nodejsApp.nix
> > stdenv.mkDerivation {
> >   name = "nodejsApp";
> >   src = ...
> >   buildInputs = [ assets nodeModules ];
> >   installPhase = ''
> >     mkdir -p $out
> >     ln -s ${nodeModules}/node_modules $out/node_modules
> >     ln -s ${assets} $out/assets
> >     ...
> >   '';
> > }
> >
> > So basically I have a derivation for my app and I symlink in the
> node_modules. Now if I want to avoid pushing
> > the node_modules to my docker registry if they are unchanged I would
> have to create a docker image that contains
> > only the node_modules and specify that docker image as `fromImage`
> argument in my buildImage call I assume?
> >
> > I'm just not quite sure to make it all fit together. Maybe someone could
> help me out a bit?
> > Thanks in advance!
> >
> > best regards,
> > Tobi
> >
> > _______________________________________________
> > nix-dev mailing list
> > nix-dev at lists.science.uu.nl
> > http://lists.science.uu.nl/mailman/listinfo/nix-dev
> >
> >
> >
> >
> > --
> > NixOS Linux
>
>


-- 
NixOS Linux <http://nixos.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160925/675786f7/attachment-0001.html>


More information about the nix-dev mailing list