Skip to content

Commit

Permalink
Improving Vagrant docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmarceleza committed Jan 16, 2022
1 parent ad2bfa2 commit 15db45d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 81 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
70 changes: 24 additions & 46 deletions vagrant/README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,34 @@
# VAGRANT

The focus of these next sections is documenting the use of Vagrant along `libvirt` provider.

## Install Vagrant on Manjaro/Arch Linux

Instal the main package of Vagrant:

```bash
$ sudo pacman -S vagrant
```

## Basic commands
First, It is necessary to create a directory for you virtual machine (VM), where a configuration file (`Vagrantfile`) will be saved to manage the configurations.
```bash
$ mkdir [VM FOLDER NAME]
```
Move into your directory:
```bash
$ cd [VM FOLDER NAME]
```
Command to initialize and create a Vagrantfile to a specific VM, also called as BOX in the Vagrant terminology.
```bash
$ vagrant init [BOX NAME]
```
To find the correct name for boxes, search [Vagrant Cloud](https://app.vagrantup.com/boxes/search) for a complete list.
To install the plugin, make sure base-devel is installed and libvirtd.service has been started. Then run:

Optionally, you can download a box without creating a Vagrantfile. With the previous command the base image of the box is not download by default. This will happen only when you give the command to run or start the VM (`vagrant up`). If you to download to increase your library of boxes, simply use the following command:
```bash
$ vagrant box add [BOX NAME]
```
Command to run a VM:
```bash
$ vagrant up
```
You can check if the machine is running with this:
```bash
$ vagrant status
```
To access the VM, use ssh:
```bash
$ vagrant ssh
vagrant plugin install vagrant-libvirt
```
To stop the VM, use this:
```bash
$ vagrant halt
```
To destroy the machine:
```bash
$ vagrant destroy

## Using Vagrant

Copy some Vagrantfile example from this resitory and run the following commando in the same folder:

```
This last command do not remove the box, only the VM. In this case, if you want to remove the box, use the following command:
```bash
$ vagrant box remove [BOX NAME]
vagrant up --provider=libvirt
```
To configure port forwarding you need to modify the Vagrantfile with this line:
```bash
config.vm.network :forwarded_port, guest: 80, host: 4567

Alternatively you can tell Vagrant to permanently use libvirt as default provider by adding the following environment variable:

```
Reload the VM to take effect.
```bash
$ vagrant reload
export VAGRANT_DEFAULT_PROVIDER=libvirt
```
Once the machine is running again, load `http://127.0.0.1:4567` in your browser, where you will access your application.

## Documentation

Expand All @@ -65,6 +37,12 @@ Once the machine is running again, load `http://127.0.0.1:4567` in your browser,
## Useful links

- [How To Use Vagrant With Libvirt KVM Provider](https://ostechnix.com/how-to-use-vagrant-with-libvirt-kvm-provider/)

- [Base boxes built by benevolent robots](https://roboxes.org/)
- [vagrant-libvirt plugin](https://github.com/vagrant-libvirt/vagrant-libvirt)
- [Vagrant Arch Wiki](https://wiki.archlinux.org/title/Vagrant)
- [Libvirt Arch Wiki](https://wiki.archlinux.org/title/Libvirt)
- [KVM Arch Wiki](https://wiki.archlinux.org/title/KVM)
- [QEMU Arch Wiki](https://wiki.archlinux.org/title/QEMU)



100 changes: 65 additions & 35 deletions vagrant/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,74 @@
#--------------------------------------------------------------
# Vagrant file to run a simple VM along libvirt provider.
#
# Reference docs:
# 1 - https://github.com/vagrant-libvirt/vagrant-libvirt
# 2 - https://wiki.archlinux.org/title/Vagrant
# 3 - https://wiki.archlinux.org/title/Libvirt
# 4 - https://wiki.archlinux.org/title/KVM
# 5 - https://wiki.archlinux.org/title/QEMU
# 6 - https://roboxes.org
#--------------------------------------------------------------
Vagrant.configure("2") do |config|


#----------------------------------------------------------
# Configuration of the provider and its specs
config.vm.provider "virtualbox" do |v|
#----------------------------------------------------------
config.vm.provider "libvirt" do |v|
v.memory = 2048
v.cpus = 2
end

# Ubuntu 18.04 image
config.vm.box = "ubuntu/groovy64"
#----------------------------------------------------------
# Choosing ubuntu 18.04 as a VM
#----------------------------------------------------------
config.vm.box = "generic/ubuntu1804"

# Ubuntu 20.04 image
# config.vm.box = "ubuntu/focal64"

# Ubuntu 21.04 image
# config.vm.box = "ubuntu/hirsute64"

# Take ip from DHCP server
config.vm.network "public_network"

# Mount folder with the content of the Docker Compose
config.vm.synced_folder "~/getup/inceres/outros/mapnik-r-container/", "/data/"

# Mount folder with the content of SGI
# config.vm.synced_folder "../apps/sgi", "/vagrant_data/sgi"

# Install Docker on the first run
config.vm.provision "docker" do |d|
end
#----------------------------------------------------------
# Choosing ubuntu 20.04 as a VM
#----------------------------------------------------------
# config.vm.box = "generic/ubuntu2004"

#----------------------------------------------------------
# Network configuration
#----------------------------------------------------------
## Setting hostname
config.vm.hostname = "vagrant.local"

## Public network taking ip from DHCP server
## make sure to create the bridge interface
config.vm.define :machine do |machine|
machine.vm.network :public_network,
:dev => "nm-bridge",
:mode => "bridge",
:type => "bridge"
end

## Private network with DHCP
# config.vm.network "private_network", type: "dhcp"

## Private network with a static ip
# config.vm.network "private_network", ip: "192.168.50.4"

## Forward guest port to host
# config.vm.network "forwarded_port", guest: 80, host: 8080

#----------------------------------------------------------
# Mount configurations
#----------------------------------------------------------
## Mount local folder inside the VM
# config.vm.synced_folder "/local-path", "/vm-path"

#----------------------------------------------------------
# Provisioning
#----------------------------------------------------------
## Install Docker on the first run
# config.vm.provision "docker" do |d|
# end

# Install Docker Compose
config.vm.provision "shell", inline: <<-SHELL
apt-get update
# apt-get install -y docker-compose
# apt-get install -y apache2
# curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
# bash nodesource_setup.sh
# apt-get install -y nodejs
# npm install -g @angular/cli
cp -r /data/ /home/vagrant/inceres/
# cp -r /vagrant_data/docker/ docker
# ng build --prod
SHELL
## Run shell commands
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# # next command
# SHELL
end

0 comments on commit 15db45d

Please sign in to comment.