Last active
June 28, 2018 08:06
-
-
Save sayotte/8063837 to your computer and use it in GitHub Desktop.
Build LXC, then use it to create a container, and use that container to build Erlang. All starting from a clean Ubuntu-12.04.3 server install.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Prepare the host system | |
sudo sh -c "cat - >> /etc/apt/sources.list.d/ddebs.list" << EOF | |
deb http://ddebs.ubuntu.com precise main restricted universe multiverse | |
deb http://ddebs.ubuntu.com precise-updates main restricted universe multiverse | |
deb http://ddebs.ubuntu.com precise-security main restricted universe multiverse | |
EOF | |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01 | |
sudo apt-get update | |
sudo apt-get upgrade -y | |
sudo apt-get install -y linux-image-3.8.0-34-generic | |
sudo reboot | |
### Optionally, install the kernel debugging symbols | |
#wget http://ddebs.ubuntu.com/pool/main/l/linux-lts-raring/linux-image-3.8.0-34-generic-dbgsym_3.8.0-34.49~precise1_amd64.ddeb | |
## wait about 2hrs for the 85kB/s download to complete, grumble | |
#sudo dpkg -i linux-image-3.8.0-34-generic-dbgsym_3.8.0-34.49~precise1_amd64.ddeb | |
### Install FPM, which we'll later use to package the build | |
sudo apt-get install -y rubygems | |
sudo gem install fpm | |
### Build LXC | |
# Build-deps | |
sudo apt-get install -y automake autoconf gcc make python3-dev pkg-config libcap-dev | |
# Run-deps | |
sudo apt-get install python3 libcap2 libpython3.2 debootstrap bridge-utils cgroup-bin | |
wget https://github.com/lxc/lxc/archive/lxc-1.0.0.beta1.tar.gz | |
tar -zxf lxc-1.0.0.beta1.tar.gz | |
cd lxc-lxc-1.0.0.beta1 | |
./autogen.sh | |
./configure --prefix=/opt/lxc-1.0.0.beta1 --enable-rpath | |
make | |
sudo make install | |
### Fixup the system linker path | |
sudo sh -c "echo '/opt/lxc-1.0.0.beta1/lib' > /etc/ld.so.conf.d/lxc-1.0.0.beta1.conf" | |
OTHERS="/etc/ld.so.conf.d/lxc-1.0.0.beta1.conf" | |
### Fixup the python libraries required by several of the executables | |
for P in /opt/lxc-1.0.0.beta1/lib/python3/dist-packages/*; do | |
SYM="/usr/local/lib/python3.2/dist-packages/$(basename ${P})" | |
sudo ln -s ${P} ${SYM} | |
# Save a reference; we want to make these symlinks part of the package | |
OTHERS="$OTHERS $SYM" | |
done | |
### Force python to byte-compile the libs so we can capture the artifacts | |
sudo /opt/lxc-1.0.0.beta1/bin/lxc-start-ephemeral -h >/dev/null 2>&1 | |
### Package LXC | |
cd .. | |
cat - > after-install << EOF | |
#!/bin/sh | |
/sbin/ldconfig | |
EOF | |
cat - > after-remove << EOF | |
#!/bin/sh | |
/sbin/ldconfig | |
EOF | |
fpm -s dir -t deb -n "lxc" -v "1.0.0.beta1" -d "python3 >= 3.2" -d "libcap2" -d "libpython3.2" -d "debootstrap" -d "bridge-utils" -d "cgroup-bin" --after-install ./after-install --after-remove ./after-remove --directories /opt/lxc-1.0.0.beta1 /opt/lxc-1.0.0.beta1 $OTHERS | |
## Purge the temporary build artifacts to make room for the package to install | |
sudo rm -rf /opt/lxc-1.0.0.beta1 $OTHERS | |
rm after-install after-remove | |
### (optional) Purge the build-deps for LXC | |
sudo apt-get remove -y --purge automake autoconf gcc make python3-dev libcap-dev | |
sudo apt-get autoremove -y --purge | |
### Install LXC | |
sudo dpkg -i lxc_1.0.0.beta1_amd64.deb | |
### Fixup system paths so everyone can find the installed package | |
sudo sh -c "cat - >> /etc/bash.bashrc" << "EOF" | |
PATH=$PATH:/opt/lxc-1.0.0.beta1/bin | |
EOF | |
# Fixup sudo to actually *use* those paths, because Ubuntu's sudo config is *such* a PITA | |
cat - >> ~/.bashrc << "EOF" | |
alias sudo='sudo env PATH=$PATH' | |
EOF | |
### Configure the bridge for container networking (they default to "lxcbr0") | |
sudo sh -c "cat - >> /etc/network/interfaces" << EOF | |
auto lxcbr0 | |
iface lxcbr0 inet dhcp | |
bridge_ports eth1 | |
bridge_fd 0 | |
bridge_maxwait 0 | |
EOF | |
sudo ifup lxcbr0 | |
### Ensure that the cgconfig is running | |
# needed to ensure that the cgroups below /sys/fs/cgroup are in-place, which is a pre-req for starting a container | |
sudo start cgconfig | |
### Create a baseline Ubuntu container, which we will snapshot/clone | |
# this takes a while because it's doing a full debootstrap from the internet | |
sudo lxc-create -n ubuntu-base -t ubuntu -B lvm --vgname vg0 --fssize 1024M | |
### Create a clone, which we will use to build Erlang | |
# this goes *very* fast, since it's using an LVM snapshot for the clone | |
sudo lxc-clone -o ubuntu-base -n erlang-build -s | |
sudo lxc-start -d -n erlang-build | |
sudo lxc-wait -n erlang-build -s RUNNING | |
sudo lxc-attach -n erlang-build << EOF | |
# Build deps | |
apt-get install -y perl-modules libncurses5-dev libssl-dev systemtap systemtap-sdt-dev | |
# (OPTIONAL) Docbuild deps | |
apt-get install -y xsltproc fop | |
# Tools to test our build | |
apt-get install -y linux-headers-$(uname -r) man-db systemtap-runtime | |
# Tools for fetching/building packages | |
apt-get install -y wget rubygems | |
HOME=/tmp gem install fpm | |
### Build Erlang/OTP | |
cd /tmp | |
wget http://www.erlang.org/download/otp_src_R16B03.tar.gz | |
tar -zxf otp_src_R16B03.tar.gz | |
cd otp_src_R16B03 | |
./configure --prefix=/opt/R16B03 --with-dynamic-trace=systemtap | |
make | |
make install | |
### (OPTIONAL) Build the docs for Erlang/OTP (these can also be downloaded, pre-formatted, in a tarball) | |
# this actually takes quite a while to complete | |
#make docs | |
#make install-docs | |
### Test that the Erlang install appears to work | |
# dyntrace:available() should return 'true' | |
/opt/R16B03/bin/erl << EOFINNER | |
dyntrace:available(). | |
EOFINNER | |
fpm -s dir -t deb -n "erlang" -v "16.03" -d 'libssl1.0.0' -d 'libncurses5' --directories /opt/R16B03 /opt/R16B03 | |
EOF | |
sudo lxc-attach -n erlang-build -- cat /tmp/erlang_16.03_amd64.deb > erlang_16.03_amd64.deb | |
sudo lxc-stop -n erlang-build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment