Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up a vagrant with a digitalocean image

I dont know if this should be posted here or on another stack community so please let me know if its wrong posting it here.

How do I get a local (i.e. on my laptop) VM that is identical to my DO droplet (Ubuntu 14.04 - LAMP etc) running?

Does DO provide a provisioner for Vagrant that can replicate the setup of a DO droplet?

It's handy being able to develop on my machine, instead of on a Droplet in the cloud.

like image 989
matthew Avatar asked Aug 31 '15 06:08

matthew


2 Answers

I was hoping to run a DigitalOcean droplet in a VM recently while researching a project based on immutable server design.

I am planning on using Packer to build properly provisioned images for each of my servers. I would then utilize Vagrant to test my environment locally in VirtualBox prior to blessing the image for use in integration, stage, and production environments.

While reading the Packer - Getting Started for Vagrant Boxes tutorial I noticed this line:

If you followed along in the previous page and setup DigitalOcean, Packer can't currently make Vagrant boxes for DigitalOcean, but will be able to soon.

This appears to have been on the documentation for some time now so who knows when "soon" will be, but I haven't found any official information on this yet.

I later came across this blog post that discusses two possible ways to work around this limitation.

  1. Manually Convert a Digital Ocean Droplet to a VMware VM
  2. Settle for simply emulating a Digital Ocean environment and work from a similar base image

I read through the instructions for (1) and it does sound legitimate although it is a rather time consuming and error prone endeavor. It sounds like emulating the setup is the best bet for now.

If anyone is aware of any recent developments here please comment below.

EDIT:

I haven't tested it yet and the last update was from several years ago, but it sounds like this blog post and referenced git repo may be a good start. It still doesn't seem to be actually building the image from the DO image, but it is a pretty good example of (2) above by closely emulating.

Oddly enough the documentation for Packer's Vagrant post-processor seems to indicate that it CAN create a vagrant box from a DigitalOcean image. If this is true then a perfectly sane flow would be to use Packer to build a provisioned vagrant box from DO to test at the same time building a DO image to spin up (on integration/stage) after verification it works as advertised in VM locally. Then you can promote the DO image through the rest of your live environments.

like image 107
Matthew Sanders Avatar answered Oct 18 '22 13:10

Matthew Sanders


It should be possible, I never tried myself (as I switch to EC2) but I saw there was a digital ocean plugin, you can refer to the following page https://www.digitalocean.com/community/tutorials/how-to-use-digitalocean-as-your-provider-in-vagrant-on-an-ubuntu-12-10-vps

Basically you would need the following:

  1. install the plugin and download the base box

    vagrant plugin install vagrant-digitalocean
    vagrant box add digital_ocean https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box
    
  2. create the SSH keys needed for authentication with DigitalOcean. Run the following command to generate your SSH key pair:

    ssh-keygen -t rsa
    

    You can accept the defaults by pressing enter. This will place the SSH private and public keys to the path we will specify below in the Vagrantfile configuration.

  3. create your Vagrantfile with following minimal configuration

    config.vm.box = "digital_ocean"
    config.ssh.private_key_path = "~/.ssh/id_rsa"
    config.vm.provider :digital_ocean do |provider|
        provider.client_id = "YOUR CLIENT ID"
        provider.api_key = "YOUR API KEY"
        provider.image = "Ubuntu 12.10 x64"
        provider.region = "New York 2"
      end
    
  4. run vagrant

    vagrant up --provider=digital_ocean
    

You can refer to above link for additional parameters and fix for some issues you could face

like image 3
Frederic Henri Avatar answered Oct 18 '22 13:10

Frederic Henri