1 of 43

Getting your Python Development Environment ready with Vagrant

Mario García�(He/Him)

GitLab Hero

2 of 43

3 of 43

Copyright © 2020 HashiCorp

What is Vagrant?

4 of 43

Vagrant

  • Vagrant is a tool for building and managing virtual environments
  • It works with VirtualBox, Hyper-V, Docker, VMWare, as providers
  • Provisioning through shell scripts, Ansible, Chef, Puppet

5 of 43

Copyright © 2020 HashiCorp

Providers

6 of 43

Providers

  • VirtualBox
  • VMWare
  • Hyper-V
  • AWS
  • Docker

7 of 43

What is? - VirtualBox

  • One of the most popular virtualization software
  • It supports Windows, Mac OS, Linux, Oracle Solaris as host systems
  • It supports ISO and BOX images

8 of 43

On Linux - VirtualBox

  • Ubuntu 18.04 LTS, 19.03 & 19.10
  • Debian GNU/Linux 9 ("Stretch") & 10 ("Buster")
  • Oracle Linux 6, 7 & 8
  • Red Hat Enterprise Linux 6, 7 & 8
  • Fedora 30 & 31

9 of 43

On Linux - VirtualBox

  • Gentoo Linux
  • SUSE Linux Enterprise server 12 & 15
  • openSUSE Leap 15.1
  • Linux 2.6, 3.x, 4.x o 5.x

10 of 43

Installation - VirtualBox

  • Download from
    • virtualbox.org/wiki/Downloads
    • virtualbox.org/wiki/Linux_Downloads
  • Download from the repositories
    • Arch-based
    • Add official repositories (DEB & RPM)

11 of 43

Boxes - Vagrant

  • Boxes (.box) are the package format for Vagrant environments
  • Download boxes from:
    • app.vagrantup.com/boxes/search
    • vagrantbox.es

12 of 43

What is? - Docker

  • Docker Engine is an open source containerization technology for building and containerizing your applications

13 of 43

Installation - Docker

  • Install Docker Engine: https://docs.docker.com/engine/install/
    • CentOS
    • Debian
    • Fedora
    • Raspbian
    • Ubuntu

14 of 43

Post Installation - Docker

$ sudo groupadd docker

$ sudo usermod -aG docker $USER

$ newgrp docker

$ docker run hello-world

TERMINAL

15 of 43

Copyright © 2020 HashiCorp

Provisioners

16 of 43

Provisioners

  • Shell scripts
  • Ansible
  • Chef
  • Puppet

17 of 43

Copyright © 2020 HashiCorp

Installation

18 of 43

Installation

  • Download from vagrantup.com/downloads
  • Download from the repositories
    • Debian-based (DEB)
    • Fedora
    • Arch-based

19 of 43

Installation

  • Debian-based
    • sudo apt install vagrant
  • Fedora
    • sudo dnf install vagrant
  • Arch-based
    • sudo pacman -S vagrant

20 of 43

Installation

  • CentOS
    • sudo dnf install -y https://releases.hashicorp.com/vagrant/2.2.14/vagrant_2.2.14_x86_64.rpm

21 of 43

Copyright © 2020 HashiCorp

Basic commands

22 of 43

Basic commands

vagrant up

Start the virtual environment

vagrant init

Create the Vagrantfile file with the initial configuration of the environment

vagrant init --minimal

vagrant ssh

Establish a connection to the virtual environment through SSH

vagrant halt

Stop the virtual environment

vagrant destroy

Delete the virtual environment and configuration files

vagrant box

Manage the boxes used for configuring the virtual environment

23 of 43

Copyright © 2020 HashiCorp

Python Development Environment

24 of 43

Development Tools

  • Python
  • Git
  • pyenv
  • Poetry / pipenv
  • GitKraken
  • Atom
  • VSCode/Code-OSS/VSCodium

25 of 43

Copyright © 2020 HashiCorp

Configuring Development Environment

26 of 43

Vagrantfile

  • $ mkdir python-dev && cd python-dev
  • $ vagrant init debian/buster64

27 of 43

Provisioning

  • $ touch install.sh
  • $ nano install.sh

28 of 43

Running

  • $ nano Vagrantfile
  • $ vagrant up
  • $ vagrant ssh

29 of 43

Copyright © 2020 HashiCorp

Development Environment with Packer

30 of 43

Packer Configuration File

$ mkdir python-dev

$ cd python-dev

$ touch box-config.json

$ nano box-config.json

TERMINAL

31 of 43

32 of 43

Provisioning

  • Add vagrant user to /etc/sudoers
  • Add SSH key for authentication
  • Install pyenv and Poetry dependencies
  • Install pyenv and configure bashrc
  • Install Poetry

33 of 43

34 of 43

Running

$ packer build -var 'version=1.0' ubuntu.json

$ vagrant init python-dev

$ vagrant box add python-dev output-vagrant/package.box

$ vagrant up

$ vagrant ssh

TERMINAL

35 of 43

Copyright © 2020 HashiCorp

Development Environment with Docker

36 of 43

Vagrantfile

  • Docker Hub
  • Dockerfile

37 of 43

$ mkdir python-dev

$ cd python-dev

$ touch Dockerfile

$ nano Dockerfile

Dockerfile

TERMINAL

38 of 43

39 of 43

40 of 43

Vagrantfile

  • $ touch Vagrantfile
  • $ nano Vagrantfile

  • $ vagrant up
  • $ vagrant ssh

41 of 43

Resources

  • Virtual Dev Environment with Vagrant + VBox on Linux
    • https://dev.to/mattdark/virtual-dev-environment-with-vagrant-vbox-on-linux-gha
  • Using Docker as provider for Vagrant
    • https://dev.to/mattdark/using-docker-as-provider-for-vagrant-10me
  • Publish a Docker image to Docker Hub using GitLab
    • https://dev.to/mattdark/publish-a-docker-image-to-docker-hub-using-gitlab-2b9o

42 of 43

Resources

  • Python Development Environment
    • https://gitlab.com/mattdark/python-development-environment/

43 of 43

43

Thank You

hi@mariog.xyz

mariog.xyz

twitter.com/mariogmd