You may want to keep your Vagrant boxes in your own repository instead of the global cloud structure.
This can often be quite important for internal policies. Moreover, it makes sense to keep the vagrant boxes you think are in a place where only you can access them.
For this and similar reasons, I tried to create my secret vagrant repository and I saw that they explained the way to do it on the internet only for RHEL.
And you know... Some people (like me) are just not used to RHEL.
For these reasons, I wanted to explain how we can do this on Ubuntu.
1. Apache Installation
As can be expected, we first start with installing the Apache.
sudo apt update
sudo apt install apache2
1.1. Creation of Necessary Directories
Before configuring Apache, we can create the necessary log directories.
sudo mkdir /var/log/apache2/vcloud
1.2. Apache Configuration
To configure Apache simply, create a configuration file named vcloud.conf under /etc/apache2/sites-available/. Then add the following configurations into this file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin zeki@acik.lab
ServerName vcloud.acik.lab
ServerAlias www.vcloud.acik.lab
DocumentRoot /var/www/html
<Directory "/var/www/html">
Options All Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/vcloud/error.log
CustomLog /var/log/apache2/vcloud/access.log combined
</VirtualHost>
ServerName is very important in this configuration. In the future we will need to create a host record to access it.
1.3. Activate Configuration
To activate the configuration follow the steps.
cd /etc/apache2/sites-available
sudo a2ensite vcloud.conf
1.4. Create Local Host Record
Create a record to reach the ServerName you gave in the configuration.
To do this, add a line /etc/hosts file like this.
10.20.30.78 vcloud.acik.lab
If you try to access the repository from Windows, the address of this file should be something like C:\Windows\System32\Drivers\etc\hosts
1.5. Create Directories for Vagrant Box
Create directories where we will put the Vagrant box. I choose the Pardus 21.0 distribution that I created myself.
sudo mkdir -p /var/www/html/vcloud/vagrant/pardus/21
2. Get Vagrant Box
That moment has come! Let's download the vagrant box. (If you feel lost, you should experience Pardus 21 with me.)
sudo wget -O /var/www/html/vcloud/vagrant/pardus/21/pardus-21-0.1.0.box https://app.vagrantup.com/zeki/boxes/pardus21/versions/0.1.0/providers/virtualbox.box
2.1. Create Metadata File
After the download is complete, create a metadata file named pardus-21.json
under /var/www/html/vcloud/vagrant/
. Don't mind the word metadata being so cool, it's just a json file and fill its content as below.
{
"name": "pardus/21",
"description": "Pardus 21.0 XFCE",
"versions": [
{
"version": "0.1.0",
"providers": [
{
"name": "virtualbox",
"url": "http://vcloud.acik.lab/vcloud/vagrant/pardus/21/pardus-21-0.1.0.box"
}
]
}
]
}
3. Restart Apache Services
After completing all these steps, we can activate Apache service.
sudo systemctl start apache2
sudo systemctl enable apache2
3.1. Accessibility Test
If all goes well you should see vagrant boxes at http://vcloud.acik.lab/vcloud/vagrant/
.
4. Testing
Create new Vagrant directory and Vagrantfile to test. (On the another server.)
mkdir pardus-21 && cd pardus-21
touch Vagrantfile
Insert the following lines into the Vagrantfile.
Vagrant.configure("2") do |config|
config.vm.box = "pardus/21"
config.vm.box_url = "http://vcloud.acik.lab/vcloud/vagrant/pardus-21.json"
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
end
LET'S VAGRANT UP!
cd ~/pardus-21
vagrant up
The output should look like this.
Congratulations!! You now have a secret vagrant repository!