Dokku

by benturley
150 deployments · 50 still active · last rev. 2 years ago

THIS STACKSCRIPT IS NO LONGER MAINTAINED

Please use the official dokku StackScript:
https://www.linode.com/stackscripts/view/11348

************************************************

Installs Dokku (mini-Heroku server).

After booting, wait until the file "ready-for-kernel-change.txt" appears in your admin user's home directory. Follow the instructions in that file (you need to switch to the pv-grub kernel and reboot using the Linode dashboard).

Once you've rebooted with the pv-grub kernel and let the installer finish, your Dokku server will be ready for app deployment.


IMPORTANT: ufw (firewall) configuration has been removed from this script, so you'll probably need to configure a firewall yourself! Be careful as ufw often doesn't work with docker as you might expect (e.g., exposed ports from docker may still be accessible from the outside if you use a simple ufw "deny" rule for those ports). Proper firewall configuration with docker/dokku often requires custom iptables configuration, including custom rules for the FORWARD chain.


NOTE: Ubuntu 14.04 LTS support is experimental!

Source script: https://gist.github.com/turley/11088958

For more configuration details:
https://github.com/progrium/dokku#configuring

Compatible with: Ubuntu 12.04 LTS, Ubuntu 14.04 LTS
						#!/bin/bash
 
# <UDF name="hostname" label="The hostname for the new Linode" example="apps">
# <UDF name="fqdn" label="The new Linode's Fully Qualified Domain Name" example="apps.example.com">
# <UDF name="adminuser" label="Username for new admin user (cannot be dokku)">
# <UDF name="adminpass" label="Password for new admin user">
# <UDF name="adminkey" label="SSH public key authorized for admin user (password SSH auth will be disabled)">
# <UDF name="dokkukey" label="SSH public key authorized for dokku user (used when deploying apps)">
 
# Turn off password authentication and root login for SSH
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
service ssh restart
 
# Set up admin user
if [ -n "$ADMINUSER" ] && [ -n "$ADMINPASS" ]; then
  useradd $ADMINUSER -s /bin/bash -p `mkpasswd $ADMINPASS`
  usermod -a -G admin $ADMINUSER
  
  if [ -n "$ADMINKEY" ]; then
    mkdir -p /home/$ADMINUSER/.ssh
    chmod 700 /home/$ADMINUSER/.ssh
    echo "$ADMINKEY" > /home/$ADMINUSER/.ssh/authorized_keys
    chmod 600 /home/$ADMINUSER/.ssh/authorized_keys
    chown -R $ADMINUSER:$ADMINUSER /home/$ADMINUSER/.ssh
  fi
fi

# Workaround for apt-get IPv6 issue
[[ `lsb_release -sr` == "12.04" ]] && echo 'precedence ::ffff:0:0/96  100' >> /etc/gai.conf
 
# Update system and install some dependencies
apt-get update
apt-get -y upgrade
apt-get -y install ufw fail2ban lxc wget bsdtar git man
 
# Set up hostname
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://')
echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname
echo $IPADDR $FQDN $HOSTNAME >> /etc/hosts
 
# Prepare system for pv-grub kernel
DEBIAN_FRONTEND=noninteractive apt-get -y install linux-virtual
DEBIAN_FRONTEND=noninteractive apt-get -y purge grub2 grub-pc
DEBIAN_FRONTEND=noninteractive apt-get -y install grub
mkdir -p /boot/grub
update-grub -y
sed -i 's/kopt=root=UUID=.* ro/kopt=root=\/dev\/xvda console=hvc0 ro quiet/g' /boot/grub/menu.lst
sed -i 's/# groot=(hd0,0)/# groot=(hd0)/g' /boot/grub/menu.lst
update-grub
 
# Install dokku with a startup script on the next boot (after we've switched to the pv-grub kernel)
cat << EOF > /etc/init.d/install_dokku
#!/bin/bash
 
case "\$1" in
start)
  [ -n "$ADMINUSER" ] && rm -f /home/$ADMINUSER/ready-for-kernel-change.txt
  
  # Dokku dependencies
  apt-get update
  apt-get -y install lxc wget bsdtar linux-image-extra-\$(uname -r)
  modprobe aufs
  
  # Install dokku
  wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash
  
  # Installation on 14.04 seems to fail the first time, but succeed on a retry
  test -d dokku || wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash
  
  # Set up SSH access for dokku user
  [ -n "$DOKKUKEY" ] && echo "$DOKKUKEY" | /usr/local/bin/sshcommand acl-add dokku deploy
  echo "$FQDN" > /home/dokku/VHOST
  chown dokku:dokku /home/dokku/VHOST
  
  # Clean up this script so it only runs once
  update-rc.d -f install_dokku remove
  rm -f /etc/init.d/install_dokku
;;
 
stop)
;;
esac
EOF
 
chmod +x /etc/init.d/install_dokku
update-rc.d install_dokku defaults 97 03
 
# Indicate to admin user that we're ready for kernel change
# (Is there any way to do this automatically with StackScripts?)
[ -n "$ADMINUSER" ] && echo 'Change this Linode configuration to use the pv-grub kernel, disable the "Xenify distro" option, and reboot (from the Linode dashboard!) to finish installation.' > /home/$ADMINUSER/ready-for-kernel-change.txt