Last year I wrote about how I created a seemless desktop using Vagrant, VirtualBox en MobaXterm.
This week I was busy creating a new box with Oracle Linux, later switching to CentOS and installing several IDE's in it. And Docker.
Next week a big change is due for me. And for that I'll be going to switch laptops. Also others will going to use my vagrant project. Up till now I used local file based boxes. So if you wanted to use my projects that I posted on GitHub, you had not only to have the install binaries in a certain folder structure, but also the particular box downloaded in the particular boxes folder.
This morning I decided to figure out how to publish them on the Vagrant cloud. And it is surprisingly easy, of course! Why I didn't do that before? Well, actually, I started with this by preparing a workshop for colleagues. And to simultaneously download the same box by every participant, did not seem a good idea. So I distributed the vagrant project with all the installers including the box on a stick.
But now, preparing for my laptop switch and distributing it for my colleagues, it seems a good idea.
I found this step by step article that guided me through the process. But let me go through the process my self.
First you'll need an account on the Vagrant Cloud. You can get there from the main page of vagrantup.com. And then click on the Find Boxes button:
Create a new account or login, if not already done that.
You'll land on the Search page:
There you can search for existing boxes. But to create and upload your own one, click on the Dashboard tab:
There click the "New Vagrant Box" button:
Here give the box a name and a short description. My first boxes had a version number in the name. But I found that a bit overdone, because later on you get to define a box versions. Click on the Create box button. I would urge you to provide a description that give some base, identifiable information on the box.
Provide a version, it's smart to start with 1 (it will check it), and possibly a description. Although I find a good base description important, I'm not sure what to write on a first version as a description. For subsequent versions, it seems a good to fill in as well. Like with GitHub/Subversion commit messages.
Within the version, I was looking for an upload button, but you first get to define a provider. So click on the provider button:
In the following page you get to define a provider. Provide virtualbox as a provider name. Vagrant need to be able to recognize and use that. But there is no poplist, so just a free text field.
I want to upload to the Vagrant Cloud, so the default will suffice. Click on the Continue to upload button:
Using the Browse button, browse to your Vagrant box and have it upload it.
Now, to be able to use the box, and others to discover your box, you'll need to release it. So go to the versions sub tab, and click on the Release button for the v1 version:
In the following page, click on the release button:
Now my boxes are searchable:
To use a box, you can create a Vagrant file with the following reference to the box:
Or create a new box in a new folder using a command like vagrant init makker/CO78SwGUI --box-version 1, continued by vagrant up:
d:\Projects\vagrant\co78>vagrant init makker/CO78SwGUI --box-version 1 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. d:\Projects\vagrant\co78>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'makker/CO78SwGUI' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: 1 ==> default: Loading metadata for box 'makker/CO78SwGUI' default: URL: https://vagrantcloud.com/makker/CO78SwGUI ==> default: Adding box 'makker/CO78SwGUI' (v1) for provider: virtualbox default: Downloading: https://vagrantcloud.com/makker/boxes/CO78SwGUI/versions/1/providers/virtualbox.box ==> default: Waiting for cleanup before exiting... Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com
You can list boxes with the (sub)command vagrant box list:
d:\Projects\vagrant\co78>vagrant box list CO77GUIv1.1 (virtualbox, 0) makker/ol77SwGUIv1.1 (virtualbox, 1)
Remove a box with vagrant box remove CO77GUIv1.1:
d:\Projects\vagrant\co78>vagrant box remove CO77GUIv1.1 Box 'CO77GUIv1.1' (v0) with provider 'virtualbox' appears to still be in use by at least one Vagrant environment. Removing the box could corrupt the environment. We recommend destroying these environments first: rhfuse (ID: ca219fa1fe0b4984bf77aa7807c0feb2) Are you sure you want to remove this box? [y/N] y Removing box 'CO77GUIv1.1' (v0) with provider 'virtualbox'...
But you can add the freshly created box also using the vagrant box add command:
d:\Projects\vagrant\co78>vagrant box add makker/CO78SwGUI --box-version 1 ==> box: Loading metadata for box 'makker/CO78SwGUI' box: URL: https://vagrantcloud.com/makker/CO78SwGUI ==> box: Adding box 'makker/CO78SwGUI' (v1) for provider: virtualbox box: Downloading: https://vagrantcloud.com/makker/boxes/CO78SwGUI/versions/1/providers/virtualbox.box ==> box: Box download is resuming from prior download progress Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com Progress: 3% (Rate: 10.5M/s, Estimated time remaining: 0:03:29)
As can be seen it mentions that it started the download earlier, but I broke it off. It apparently resumes the download.
My current Vagrantfiles have the following declaration of the vagrant box:
... BOX_NAME="CO78GUIv1.1" BOX_URL="file://../boxes/CO78SwGUIv1.0.box" VM_MEMORY = 12288 # 12*1024 MB ... Vagrant.configure("2") do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box=BOX_NAME config.vm.box_url=BOX_URL config.vm.hostname=VM_HOST_NAME config.vm.define VM_MACHINE config.vm.provider :virtualbox do |vb| vb.name=VM_NAME vb.gui=VM_GUI vb.memory=VM_MEMORY vb.cpus=VM_CPUS ...
Based on the suggestion of the Vagrant Cloud:
I adapted this as follows:
... BOX_NAME="makker/CO78SwGUI" BOX_VERSION = "1" #BOX_URL="file://../boxes/CO78SwGUIv1.0.box" VM_MEMORY = 12288 # 12*1024 MB ... Vagrant.configure("2") do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box = BOX_NAME config.vm.box_version = BOX_VERSION # config.vm.box_url=BOX_URL config.vm.hostname=VM_HOST_NAME config.vm.define VM_MACHINE config.vm.provider :virtualbox do |vb| vb.name=VM_NAME vb.gui=VM_GUI vb.memory=VM_MEMORY vb.cpus=VM_CPUS ...
I uncommented the BOX_URL variable with the config.vm.box_url lines. And added the BOX_VERSION and config.vm.box_version lines. Most importantly I changed the BOX_NAME variable to makker/CO78SwGUI.
These suggestions will download my Cloud boxes without me needing to distributed them separately.
Happy Upping!
No comments:
Post a Comment