Setting up a vagrant with a digitalocean image

前端 未结 2 1843
情歌与酒
情歌与酒 2021-02-19 20:37

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 t

相关标签:
2条回答
  • 2021-02-19 21:09

    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.

    0 讨论(0)
  • 2021-02-19 21:10

    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

    0 讨论(0)
提交回复
热议问题