Skip to content

Instantly share code, notes, and snippets.

@napcs
Created January 9, 2015 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save napcs/6e7e28e84cd7bacbf8b6 to your computer and use it in GitHub Desktop.
Save napcs/6e7e28e84cd7bacbf8b6 to your computer and use it in GitHub Desktop.
DigitalOcean Setup

Quickly build a DigitalOcean box

You can use Chef or Puppet to build out your infrastructure, but if you just need a quick and dirty box set up,

Installation

First, download Vagrant and install it.

After that, visit your DigitalOcean account and obtain your API key.

Then install the plugin for Vagrant.

$ vagrant plugin install vagrant-digitalocean

If you run into trouble, please see https://github.com/smdahlen/vagrant-digitalocean#install to understand the overall process for

Usage

Save the Vagrantfile to your project. Modify the line

    provider.token = 'YOUR API KEY'

with your DigitalOcean key which you obtained from your DigitalOcean account.

Change the box type if you wish, and the data center location.

Then modify setup.sh for your needs.

Running

Create the box with

$ vagrant up --provider=digital_ocean

Login as root with

$ vagrant ssh

Rebuild the box (completely removes the droplet and starts over.)

$ vagrant rebuild

Destroy it with

$ vagrant destroy
#!/bin/bash
# Installs and upgrades essential software on the machine and creates
# user accounts with randomized passwords.
# Sets up web directories in each folder and configures Apache mod
# to serve each one.
# add Erlang repository so Elixir and Erlang can be installed with apt-get
wget http://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
sudo dpkg -i erlang-solutions_1.0_all.deb
# refresh sources
apt-get update
# Upgrade anything on the box to the latest
apt-get ugrade -y
# Install the necessary bits
apt-get install -y vim whois build-essential git-core tmux wget curl
# Install Apache. Install other stuff you might need like PHP here too.
apt-get install apache2
a2enmod userdir
service apache2 restart
# elixir
apt-get install elixir -y
# array of users. Add each one you want to the list.
declare -a users=(homer bart deploy)
for user in "${users[@]}"
do
# generate password
pass=`cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c8`
useradd -m $user -d /home/$user -s /bin/bash -p `echo "$pass" | mkpasswd -s`
# remove the following comment to add user to sudoers
# usermod -aG sudo $user
# create public_html folder for user
mkdir /home/$user/public_html
chown $user:$user /home/$user/public_html
# store password in root user's home dir
echo "$user,$pass" >> passwords.txt
# display user, pass to screen
echo "Added $user,$pass" >&2
done
Vagrant.configure('2') do |config|
config.vm.provider :digital_ocean do |provider, override|
override.ssh.private_key_path = '~/.ssh/id_rsa'
override.vm.box = 'digital_ocean'
override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"
provider.token = 'YOUR_API_KEY'
provider.image = '14.04 x64'
provider.region = 'nyc2'
provider.size = '512mb'
end
config.vm.provision :shell, :path => "setup.sh"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment