Commit 5526b49d authored by Daniele Santoro's avatar Daniele Santoro
Browse files

Release lab lesson 1

parents
.vagrant
*.log
application.yaml
\ No newline at end of file
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t broken-links:nil c:nil creator:nil
#+OPTIONS: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:nil
#+OPTIONS: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t
#+OPTIONS: timestamp:t title:t toc:t todo:t |:t
#+TITLE: Fog and Cloud Computing 2022 - Lab
#+AUTHOR: Daniele Santoro
#+EMAIL: dsantoro@fbk.eu
#+LANGUAGE: en
#+SELECT_TAGS: export
#+EXCLUDE_TAGS: noexport
#+CREATOR: Emacs 25.1.1 (Org mode 9.0.5)
* Lab Virtual Machine
** Vagrant on your laptop
In order to simplify the creation of a portable environment on
different Operating System and different hardware we leverage tools
like:
- [[https://www.vagrantup.com/][https://www.vagrantup.com/]]
- [[https://www.virtualbox.org/][https://www.virtualbox.org/]]
- [[https://www.ansible.com/]]
- Others
During first exercises you will learn howto create a portable
development environment, then a standard environment will be provided
by us distributing a =Vagrantfile= and a =provisioning script=.
* Lab01-20220318
- [[file:e01/][Exercise 01 - Install required tools]]
- [[file:e02/][Exercise 02 - Start and Check your 1st Environment]]
- [[file:e03/][Exercise 03 - Customise and Share the Environment]]
* Exercise 01 - Install required tools
- Time :: 20 minutes
- Try by yourself then Check, Verify, Ask
- Description :: Properly install all the mentioned tools or ensure to have an alternative on your machine. Required for all Operating Systems:
- Vagrant
- VirtualBox
* Solutions and Instructions
Suggestion: The following instructions are generic and not intended to be copied/pasted. You are not a robot: be smart and think what you are doing.
** Install VirtualBox
All
- Download and install VirtualBox for your platform from this link: [[https://www.virtualbox.org/]]
** Install a Terminal
Windows
- Download al install Cmder from this link: [[https://cmder.net]]. Choose the *Full* version not the Mini. For simplicity just extract the archive on your Desktop
Linux
- Use the terminal provided by your system
MacOS
- Use the terminal provided by your system or install [[https://iterm2.com/][iTerm2]]
** Install OpenSSH
Windows
- It is already included in Cmder, so no need to install manually
Linux
- It should be already provided in your system, otherwise use your package manager to install it.
Debian-based example
#+begin_src sh
apt search ssh # Search for ssh in available packages list
apt install ssh -y
#+end_src
Test with
#+begin_src sh
man ssh
#+end_src
MacOS
- It should be already provided in your system, otherwise use your package manager to install it.
Brew enabled system example
#+begin_src sh
brew search ssh # Search for ssh in available packages list
brew install openssh
#+end_src
Test with
#+begin_src sh
man ssh
#+end_src
** Install a Text editor
Windows
- Install [[https://notepad-plus-plus.org/downloads/][Notepad++]], [[https://www.sublimetext.com/3][Sublime Text]] o use your preferred one
Linux
- Install [[https://www.sublimetext.com/3][Sublime Text]] or use your preferred one
MacOS
Linux
- Install [[https://www.sublimetext.com/3][Sublime Text]] or use your preferred one
** Install git
Windows
- It is already included in Cmder, so no need to install manually
Linux
- Adapt /Install OpenSSH/ instructions above
MacOS
- Adapt /Install OpenSSH/ instructions above
** Install Vagrant
All
- Download and install Vagrant for your platform from this link: [[https://www.vagrantup.com/downloads]]
- In some cases you should reboot your system, follow instructions carefully
- Test with
#+begin_src sh
vagrant version
#+end_src
* Exercise 02 - Start and Check your 1st Environment
- Time :: 30 minutes
- Try by yourself then Check, Verify, Ask
- Description :: Start to provision a Virtual Machine using Vagrant. Look at the log file and follow steps specified in the provision script. Once ready connect with the Virtual Machine. Finally try using an external provisioning script and explore connection details.
* Solutions and Instructions
Suggestion: The following instructions are generic and not intended to be copied/pasted. You are not a robot: be smart and think what you are doing.
** Create and provision the virtual machine
Move to the =e02= folder of the repository
#+begin_src sh
cd e02
#+end_src
Tell Vagrant to bring up your environment
#+begin_src sh
vagrant up
#+end_src
Look carefully at the logs, open the =Vagrantfile= and try to understand steps in the provisioning script
** Connect to the virtual machine
#+begin_src sh
vagrant ssh
#+end_src
Check if the package =figlet= has been installed ;D
** Use external provisioning script (optional)
Vagrant, by default, will mount the direcotry where the =Vagrantfile= is present in the Virtual Machine under =/vagrant=.
This will allow us to use a dedicated rpovisioning script, see the =provision= [[file:provision][folder]] for details.
Of course you shoud be able to run =vagrant up= from this folder and get the very same result as before. Note: in some cases this will not work if =vbox guest addition= have not been installed in the VM. more info:
- https://www.vagrantup.com/docs/synced-folders
- https://www.virtualbox.org/manual/ch04.html
To manually mount a shared folder in the VM
#+begin_src sh
mkdir ~/shared
sudo mount -t vboxsf shared ~/shared
#+end_src
** Explore connection details
We can use =vagrant ssh= to connect to our VM without using a password and =Vagrant= + =VirtualBox= hide everything behind the scenes. Let's take a look at how things works.
Find out the SSH connection details
#+begin_src
vagrant ssh-config
#+end_src
Make them environment variables
#+begin_src sh
for i in `vagrant ssh-config | sed 's/ //g' | sed 's/ /=/g' | tail -n +2`; do
eval $i;
done
#+end_src
Manually connect to the Virtual Machine
#+begin_src sh
ssh $User@$HostName -p $Port -i $IdentityFile
#+end_src
VM settings are cached in the current folder, where =Vagrantfile= is.
#+begin_src sh
tree .vagrant/
#+end_src<
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
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 = "ubuntu/focal64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# Customize the amount of memory on the VM:
vb.memory = "2048"
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# Shared configuration
$script = <<-SHELL
DEBIAN_FRONTEND=noninteractive sudo apt-get -qqy update
DEBIAN_FRONTEND=noninteractive sudo apt-get dist-upgrade -y
DEBIAN_FRONTEND=noninteractive sudo apt-get install htop snapd figlet -y
grep -qxF 'figlet FCC Course' /home/vagrant/.bashrc || echo 'figlet FCC Course' >> /home/vagrant/.bashrc
sudo snap install yq
SHELL
config.vm.provision "shell",
inline: $script
end
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
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 = "ubuntu/focal64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# Customize the amount of memory on the VM:
vb.memory = "2048"
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# Shared configuration
config.vm.provision "shell",
inline: "/bin/bash /vagrant/provision.sh"
end
#!/bin/bash
DEBIAN_FRONTEND=noninteractive sudo apt-get -qqy update
DEBIAN_FRONTEND=noninteractive sudo apt-get dist-upgrade -y
DEBIAN_FRONTEND=noninteractive sudo apt-get install htop snapd figlet -y
grep -qxF 'figlet FCC Course' /home/vagrant/.bashrc || echo 'figlet FCC Course' >> /home/vagrant/.bashrc
sudo snap install yq
\ No newline at end of file
* Exercise 03 - Customise and Share the Environment
- Time :: 20 minutes
- Try by yourself then Check, Verify, Ask
- Description :: Destroy the previous Virtual Machine. Modify the provisioning script and create a customized new Virtual Machine. Share the environment with your teammate (different OS preferred) and test if the environment is portable as expected.
* Solutions and Instructions
** Modify the Virtual Machine
You can modify the =Vagrantfile= to customise the creation instructions, for example to reserve less RAM
#+begin_src yaml
vb.memory = "1024"
#+end_src
Or you can modify the provisioning instructions, and install new software
#+begin_src sh
DEBIAN_FRONTEND=noninteractive sudo apt-get install mysql-server -y
#+end_src
or add a new user
#+begin_src sh
sudo useradd -p $(openssl passwd -1 password) fcc
#+end_src
** Share the new VM
You just need to send the =Vagrantfile=. For more complex environments, containing more files, you can create an archive or even better save them in git and publish on a remote repository.
Your teammate need just to run
#+begin_src sh
vagrant up
#+end_src
** Test on your teammate laptop
Test in your teammate laptop using VirtualBox UI to check the modified RAM
Test on your teammate laptop if the =mysql-server= service is present
#+begin_src sh
vagrant ssh
systemctl status mysql.service
#+end_src
Test on your teammate laptop if the new use is present
#+begin_src sh
sudo -s
su fcc
whoami
#+end_src
*Anyone that want to share a modified Vagrantfile with me ??? See my email in the slides*
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
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 = "ubuntu/focal64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# Customize the amount of memory on the VM:
vb.memory = "2048"
#vb.memory = "1024"
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# Shared configuration
$script = <<-SHELL
DEBIAN_FRONTEND=noninteractive sudo apt-get -qqy update
DEBIAN_FRONTEND=noninteractive sudo apt-get dist-upgrade -y
DEBIAN_FRONTEND=noninteractive sudo apt-get install htop snapd figlet -y
grep -qxF 'figlet FCC Course' /home/vagrant/.bashrc || echo 'figlet FCC Course' >> /home/vagrant/.bashrc
sudo snap install yq
# DEBIAN_FRONTEND=noninteractive sudo apt-get install mysql-server -y
# sudo useradd -p $(openssl passwd -1 fcc) fcc
SHELL
config.vm.provision "shell",
inline: $script
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment