fgrehm / vagrant-cachier

Caffeine reducer
http://fgrehm.viewdocs.io/vagrant-cachier
MIT License
1.08k stars 111 forks source link

support for chroot #59

Closed typekpb closed 10 years ago

typekpb commented 10 years ago

It would be nice, if caching would work for chrooted (https://en.wikipedia.org/wiki/Chroot) environments as well.

Well, possibly the most flexible solution would be to enable all types of cache buckets detection on this.

The very basic source of information is the dir:

/etc/schroot/chroot.d/

that holds all the *.conf files which contain all the environments configured.

As an example such a config file:

cat /etc/schroot/chroot.d/precise_i386.conf [precise_i386] description=Ubuntu 12.04 Precise for i386 location=/srv/chroot/precise_i386 personality=linux32 root-users=joechroot type=directory users=joechroot

To enable chrooting following packages seem to be required for installation:

sudo apt-get install debootstrap schroot

afterwards, for example, once such a chrooted env is available, apt would cache to:

/srv/chroot/precise_i386/var/cache/apt/archives

so just modified root. The similar should be true for other buckets as well.

typekpb commented 10 years ago

The tricky part is however, that the chroot-ed system runs in "jail" so has normally no access to filesystem of the hosting system. Mounting would be probably required for that. The question is if it can be automatic, or has to be done by user manually.

fgrehm commented 10 years ago

Thanks for sharing your thoughts but I think this is out of scope for this plugin basically because chroot-ed envs are not Vagrant VMs :)

I'd look into a PR for it but for now I'm going to close the issue. If you want to continue the discussion feel free to do so, I'll still get notified :-)

typekpb commented 10 years ago

@fgrehm thanks for checking this one. I was doing chroot within vagrant box, so considered it a valid vase. still, the solution seems to be on the other side (in chroot env setup, rather than vagrant setup itself).

So for me was the key to mount the dirs that are cached by vagrant-cachier within the chrooted env.

For others facing similar issue, let me just document what I ended up with: the bash script referred from my Vagrantfile via shell provisioner having:

sudo tee -a /etc/fstab <<EOF > /dev/null
/vagrant /chroot/vagrant none bind 0 0
/var/cache/apt/archives /chroot/var/cache/apt/archives none bind 0 0
EOF

sudo mkdir -p /chroot/vagrant
sudo mkdir -p /chroot/var/cache/apt/archives/partial
sudo mount -a 

where my chroot-ed system's root was the /chroot dir.

Please note, the only caching I was interested in was the apt one.

fgrehm commented 10 years ago

@typekpb no worries! thanks for sharing :) I hope someday we can make the codebase less messy so that implementing something like that would be painless :-P