Skip to content

Instantly share code, notes, and snippets.

@mej
Last active January 13, 2020 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mej/dd0f9a7c5e6f1bab07ef708c29185781 to your computer and use it in GitHub Desktop.
Save mej/dd0f9a7c5e6f1bab07ef708c29185781 to your computer and use it in GitHub Desktop.
Vagrantfile for LANL Docker class
# -*- 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_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 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.provider "libvirt" do |lv|
lv.graphics_type = "none"
lv.memory = "1024"
end
config.vm.provision "bootstrap", type: "shell", privileged: true, run: "always", inline: <<-SHELL
echo 'export HTTP_PROXY="http://proxyout.lanl.gov:8080/" http_proxy="http://proxyout.lanl.gov:8080/" HTTPS_PROXY="http://proxyout.lanl.gov:8080/" https_proxy="http://proxyout.lanl.gov:8080/" NO_PROXY="localhost,127.0.0.1,.lanl.gov" no_proxy="localhost,127.0.0.1,.lanl.gov"' > /etc/profile.d/lanl-web-proxy.sh
source /etc/profile.d/lanl-web-proxy.sh
yum makecache fast
yum-config-manager --setopt=deltarpm=0 --save
yum-config-manager --setopt="proxy=http://proxyout.lanl.gov:8080/" --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
if [ ! -s /etc/systemd/system/docker.service.d/http-proxy.conf ]; then
mkdir -p -m 0755 /etc/systemd/system/docker.service.d && cat > /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://proxyout.lanl.gov:8080/" "http_proxy=http://proxyout.lanl.gov:8080/"
Environment="HTTPS_PROXY=http://proxyout.lanl.gov:8080/" "https_proxy=http://proxyout.lanl.gov:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,.lanl.gov" "no_proxy=localhost,127.0.0.1,.lanl.gov"
EOF
systemctl daemon-reload && systemctl restart docker.service
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