rake-compiler / rake-compiler-dock

Easy to use and reliable cross compiler environment for building Windows, Linux, Mac and JRuby binary gems.
MIT License
78 stars 30 forks source link

[wishlist] Being able to override `pwd` from an environment variable. #11

Closed nicolasnoble closed 8 years ago

nicolasnoble commented 8 years ago

In some situations (think docker-within-docker), the sub-mapping of pwd can be a bit irregular. It'd be desirable to be able to override it with an environment variable.

More specifically, this snipplet:

        cmd = ["docker", "run",
            "-v", "#{pwd}:#{make_valid_path(pwd)}",
            "-e", "UID=#{uid}",

Could become something along the lines of:

        map = ENV["RAKE_COMPILER_PWD"] or pwd
        cmd = ["docker", "run",
            "-v", "#{map}:#{make_valid_path(pwd)}",
            "-e", "UID=#{uid}",

Note that only the left hand of the : should be overridable for this to work.

larskanis commented 8 years ago

Although I don't have a strong opinion regarding this change, I would like to understand the rationale behind it. Why does a docker-within-docker scenario require to set a different pwd?

nicolasnoble commented 8 years ago

The rationale is that if you want to run docker-within-docker, you need to map from the outside world, not from the docker instance. Aka, the inner docker need to use -v with a path from outside the outer docker, not with a path from inside the outer docker. I hope I'm being clear ;-)

So if we want to be able to traverse this, we need to be able to tell the inner docker (aka, rake-compiler-dock in that case) what is the actual external mount to use, instead of the inner "pwd" which is probably wrong.

nicolasnoble commented 8 years ago

And a practical example is automated building of artifacts for a given project. The typical way is to use Jenkins which will git clone the code to compile and distribute, spawn a docker container with all the necessary toolchains, mapping the cloned source into it from, for example, $JENKINS_HOME/$BUILD_ID into /var/jenkins/build, and start building. Except that when we hit rake gem:windows, it fails, because rake-compiler-dock is trying to map /var/jenkins/build instead of $JENKINS_HOME/$BUILD_ID, and no source is found.

We can make it work by setting something before calling rake gem:windows, except there's no mapping override in rake-compiler-dock, hence that wishlist issue :-)