Skip to content

Instantly share code, notes, and snippets.

@mej mej/Vagrantfile
Last active Jun 21, 2018

Embed
What would you like to do?
Vagrantfile for Charliecloud VM
# -*- mode: ruby -*-
# vi: set ft=ruby :
#### Check https://goo.gl/9N7e3S for the latest version of this gist!
#
#### Installs Docker, Charliecloud, and Mezzanine by default during provisioning. Run:
#### $ vagrant up
#### To connect to the VM and play around with the above software, simply run:
#### $ vagrant ssh
#### Then, to build, convert, and test several example containers with Charliecloud, use:
#### $ vagrant provision --provision-with ctr-build,ctr-install,ch-test
####
# (DEPRECATED) Ensure that the vagrant-reload plugin is installed before proceeding:
# $ vagrant plugin install vagrant-reload
#Vagrant.require_plugin "vagrant-reload"
Vagrant.configure("2") do |config|
# https://docs.vagrantup.com.
config.vm.box = "centos/7"
# config.vm.box_check_update = true
config.vm.network "forwarded_port", guest: 8888, guest_ip: "127.0.0.1", host: 8888, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 6006, guest_ip: "127.0.0.1", host: 6006, host_ip: "127.0.0.1"
# config.vm.synced_folder "../data", "/vagrant_data"
#
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = "1024"
end
config.vm.provision "bootstrap", type: "shell", privileged: true, run: "always", inline: <<-SHELL
yum makecache fast
yum-config-manager --setopt=deltarpm=0 --save
if !(rpm -q docker-ce >/dev/null 2>&1); then
yum -y upgrade
yum -y install git gcc make binutils yum-utils device-mapper-persistent-data lvm2 screen wget curl
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum -y install docker-ce.x86_64
systemctl enable docker && systemctl start docker
fi
echo 1885 > /proc/sys/user/max_user_namespaces
echo "user.max_user_namespaces = 32767" > /etc/sysctl.d/51-userns.conf
fgrep -q unpriv_enable /proc/cmdline \
|| grubby --args="user_namespace.enable=1 namespace.unpriv_enable=1 user.max_user_namespaces=32767" --update-kernel=ALL
SHELL
# This will reload the VM during provisioning. Requires the "vagrant-reload" plugin.
config.vm.provision :reload
config.vm.provision "ch-install", type: "shell", privileged: false, run: "always", inline: <<-SHELL
test -d charliecloud/.git || git clone https://github.com/mej/charliecloud.git
if [ ! -x /usr/local/bin/ch-run ]; then
cd charliecloud
git checkout --track origin/fix/rhel7-build
make PREFIX=/usr/local all get-bats
: PATH=$PATH:$PWD/test/bats/bin make -C test test-build CH_TEST_TARDIR=/var/tmp/cctar CH_TEST_IMGDIR=/var/tmp/ccimg CH_TEST_PERMDIRS=skip
sudo make PREFIX=/usr/local install
fi
SHELL
config.vm.provision "ctr-build", type: "shell", privileged: false, run: "never", inline: <<-SHELL
export PATH=$PATH:/usr/local/bin
cd charliecloud
(cd test && sudo docker build -t debian9 -f Dockerfile.debian9 . && sudo docker build -t openmpi -f Dockerfile.openmpi .)
for EX in examples/serial/hello examples/mpi/mpihello examples/mpi/mpibench examples/mpi/lammps examples/other/spark ; do
echo Building Docker container $(basename $EX) in $EX
(cd $EX && ch-build -t $(basename $EX) ~/charliecloud)
done
sudo docker pull tensorflow/tensorflow
SHELL
config.vm.provision "ctr-install", type: "shell", privileged: false, run: "never", inline: <<-SHELL
export PATH=$PATH:/usr/local/bin CTRDIR=/var/tmp
for EX in hello mpihello mpibench lammps spark ; do
echo "Converting Docker container to Charliecloud: $EX -> $CTRDIR/$EX"
ch-docker2tar $EX $CTRDIR
ch-tar2dir $CTRDIR/$EX.tar.gz $CTRDIR
done
echo "Converting Docker container to Charliecloud: tensorflow/tensorflow -> $CTRDIR/tensorflow"
ch-docker2tar tensorflow/tensorflow $CTRDIR
ch-tar2dir $CTRDIR/tensorflow.tensorflow.tar.gz $CTRDIR
mv $CTRDIR/tensorflow.tensorflow $CTRDIR/tensorflow
SHELL
config.vm.provision "mzdevel", type: "shell", privileged: true, inline: <<-SHELL
yum -ty install git gcc\* make binutils yum-utils device-mapper-persistent-data lvm2 screen wget curl \
"perl(CPAN)" "perl(Class::Struct)" "perl(Cwd)" "perl(English)" "perl(Exporter)" "perl(File::Copy)" \
"perl(File::Find)" "perl(File::Listing)" "perl(File::stat)" "perl(Getopt::Long)" "perl(HTTP::Cookies)" \
"perl(HTTP::Request)" "perl(IPC::Open3)" "perl(LWP::UserAgent)" "perl(Net::FTP)" "perl(POSIX)" \
"perl(Sys::Hostname)" "perl(URI)" rpm-devel rpm-build glibc-devel autoconf automake libtool
cd /root
export MEZZANINE_PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin"
git clone https://github.com/mej/mezzanine.git
cd mezzanine
perl -I. ./pkgtool -b
rpm -Uvh mezzanine*4.rpm
cd /root
rm -rf mezzanine mezzanine*4.rpm
SHELL
config.vm.provision "ch-test", type: "shell", privileged: false, run: "never", inline: <<-SHELL
export PATH=$PATH:/usr/local/bin CTRDIR=/var/tmp
ch-run $CTRDIR/hello -- cat /etc/os-release
ch-run $CTRDIR/mpihello -- mpirun -np 4 /hello/hello
ch-run -b /run:/run $CTRDIR/tensorflow -- ./run_jupyter.sh </dev/null &
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.