Skip to content

A collection of Python scripts to manage Vagrant boxes in a private repository

License

Notifications You must be signed in to change notification settings

amontalban/vagrant-tools

Repository files navigation

vagrant-tools

A collection of Python scripts to manage Vagrant boxes in a private repository

DOCUMENTATION

Private repository configuration

The private repository can be configured with a NGINX server, ssh and a unprivileged user. Basically the server is configured to serve the metadata.json file located in the box folder so Vagrant can get box information like versions and URLs for them.

As shown below the boxes are stored in /usr/share/nginx/html/vagrant with the following details:

  • Box path: /usr/share/nginx/html/vagrant/boxname
  • Metadata path: /usr/share/nginx/html/vagrant/boxname/metadata.json
  • Boxes files: /usr/share/nginx/html/vagrant/boxname/boxes/*

Example of metadata.json

{
  "description": "This is a example.",
  "name": "amontalban/superbox",
  "versions": [
    {
      "providers": [
        {
          "checksum": "bf74bdbabada3751a91399ab3069d02ed7fa5d0b",
          "checksum_type": "sha1",
          "name": "virtualbox",
          "url": "http://devops.domain.com/vagrant/amontalban/superbox-1.0/boxes/superbox-1.0.box"
        }
      ],
      "version": "1.0"
    }
  ]
}

NGINX server configuration template

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index metadata.json;

    server_name devops.domain.com;

    # Match the box name in location and search for its catalog
    # e.g. http://www.example.com/vagrant/devops/ resolves to
    # /var/www/vagrant/devops/devops.json
    #
    location ~ ^/vagrant/([^\/]+)/$ {
        index metadata.json;
        try_files $uri $uri/ metadata.json =404;
        autoindex off;
    }

    location ~ ^/vagrant/([^\/]+)/boxes/$ {
        try_files $uri $uri/ =404;
        autoindex off;
    }

    # Serve json files with content type header application/json
    location ~ \.json$ {
        add_header Content-Type application/json;
    }

    # Serve box files with content type application/octet-stream
    location ~ \.box$ {
        add_header Content-Type application/octet-stream;
    }

    # Deny access to document root and the vagrant folder
    location ~ ^/(vagrant/)?$ {
        return 403;
    }

}

The other thing you will need is a user with SSH access to the server and write rights in the configured path (/usr/share/nginx/html in this case). It's recommended to use public keys for SSH so you don't have to use passwords. For more info check this guide.

vagrant-upload

For more information about this script please check the documentation.

vagrant-download

For more information about this script please check the documentation.

CHANGELOG

Check the CHANGELOG to know about recent changes.

RELATED LINKS

About

A collection of Python scripts to manage Vagrant boxes in a private repository

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages