Monthly Archives: August 2015

How to Setup a DigitalOcean Provider on Vagrant

If you haven’t done so, install Vagrant for your OS here.

Generate your key pairs. If using Windows, use puttygen. In Windows you’re going to have to use the OpenSSH key formats:

digitalocean-puttygen-private-key digitalocean-puttygen-public-key

Edit VagrantFile. Make sure the private key does not have an extension. The public key should have extension “.pub” with the same file name as the private key (e.g., “do.pub”).

Create your API V2 token from your DO control panel:

digitalocean-generate-new-token

Most of these lines are self-explanatory. To get a list of images and regions you could click on “Create Droplet” from your web account or you could run the following:

Here’s a sample list of regions and images:

Regions Images
  • nyc1
  • ams1
  • sfo1
  • nyc2
  • ams2
  • sgp1
  • lon1
  • nyc3
  • ams3
  • fra1″
  • centos-5-8-x64
  • debian-6-0-x64
  • fedora-21-x64
  • ubuntu-12-04-x64
  • debian-7-0-x64
  • ruby-on-rails
  • wordpress

Now just change into the Vagrant project folder and run “vagrant up”

rails console hangs

“rails c” hangs with no error messages and no response.

solution: stop spring using the following command
“spring stop” or “bin/spring stop”

spring will automatically start back up when you run the rails c command.

How to Expand a Boot Disk on a GCE Instance

Google now allows you specify the size of your boot disk larger than 10GB when you create your instance. In any case, if you need to resize your boot disk for any reason, these are the steps I followed.

Here I’ve attached a 250GB blank disk to the instance:

“pv” gives you a progress of the “dd” command. This will take some time. Once it’s finished:

Now we re-partition the disk:

fdisk-expand

Now you could run:

  1. Detach the disk,
  2. Clone the instance and choose this disk as the root disk.
  3. SSH and make sure everything looks good.
  4. Once it looks good, you could delete the original instance and create a new instance with this disk.

Google Cloud Services – How to Use Access Tokens Directly

For whatever reason you can’t use gsutil, gcloud, or a client library, you could request an access token directly. This example uses PHP 5.2 (the PHP client library only works  with PHP 5.3+). Please make sure your instance has access to the correct scopes and that a service account is enabled.
gce-project-access-scope

Related Resources:

  • https://cloud.google.com/compute/docs/metadata?hl=en
  • https://cloud.google.com/compute/docs/authentication

Example Usage of Ruby Client LIbrary for Google Cloud Storage

“But it Works on My Box” – A Case for Vagrant

When I need to quickly spin up a server to do testing, debugging, development, etc., I usually spin up VirtualBox and build a VM based off a cloud image file from scratch. It is a tedious process but I figured it’s easy and quick to just clone the VM afterwards. The problem arises when I want to share this environment with my contract workers or other members of my team. These images tend to be large as they include the OS, disks, hardware configuration, etc.

Enter Vagrant.

Vagrant isn’t exactly a competitor to VirtualBox but more of a wrapper. It’s basically a VM manager.

Benefits of Vagrant:

  • You could check in the Vagrant files into source control with your project (e.g., Git) and a user can have an identical environment by running a single command “vagrant up”
    • You don’t have to share a 500MB+ VM image file. You only need two small files (Vagrantfile & a provision script)
    • Keeps absolute parity between all collaborators on a project. All they have to do is pull the source code and “vagrant up”
    • You could integrate with several Configuration Management systems such as Chef, Ansible, and Puppet for provisioning.
    • You could have different Virtual Machines for different purposes
    • The configuration is in plain-text so you have an idea of what kind of hardware is required to run the application and which apps will be installed.
  • It could manage and spin up multiple VM instances
    • If you need multiple servers for load-balancing web servers, clustering databases, etc. All you have to do is add these servers to the Vagrantfile and “vagrant up”
    • Simplifies multi-VM networks
    • It makes setting up a distributed system development environment very easy.
    • Centralized configuration of all VMs
  • Faster to setup a VM
    • Much quicker to get a VM up and running than on VirtualBox
    • Networking is automated
  • Share the environment
    • You could easily have users connect directly to your host via http, ssh, and custom ports.
  • You could manage other types of machines with Providers
    • VirtualBox
    • VMWare
    • AWS
    • GCE
  • You don’t have to change your development environment
    • Vagrant makes the code files seamless from the host to the guest. You could use your own OS, editor, browser, and other development tools.

In the end, Vagrant saves a lot of time and it’s easy to get started with. Keep in mind VMs do require actual hardware allocations and there could be limitations on your machine. If you need to run a large number of VMs, use Docker.