• Shopping Cart Shopping Cart
    0Shopping Cart
London App Developer
  • Courses
  • Consulting
  • Tutorials
  • About
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
Smartphone lying on a wood surface
Career advice, Django REST Framework, Ionic Framework, Linux, Python, Salt Stack, Ubuntu, Vagrant

How to Build an App Part 1: Setting up the Development Server with Vagrant, Ubuntu and Salt

Using a Mac? Click here to view the Mac OS X version of this walk-through.

After my previous post, Android Development for Beginners: 6 Steps to Building Your First App, I received some requests asking me to explain in more detail how to build an app, step-by-step. If you have any experience buildings apps you will know that it can be a complicated process and there are a number of different components that need to work together to have a fully functioning app. This includes creating a database, a REST API and the app front end.

How to Build an App Vagrant Ubuntu Salt
In the next series of posts, I will break down step-by-step these components to create a basic app. The app I’m going to make is called “Message in a Bottle”. It is inspired by the idea of bottling up a message and throwing it out to ocean, and a random person somewhere else in the world finds it and opens it. The problem is, not everyone lives near an ocean, so we are going to apply our technical minds and use technology bring the message in a bottle experience to anyone, anywhere.

The app will work like this…User A submits a message to the app (aka writes a message on a little scroll of paper, bottles it up, and throws it into the ocean). In return, she is permitted to take one existing bottle out of the ocean (just imagine her scouring the beach, and magically finding a bottle washed up on shore, with a message inside).

Once she reads the message, it then disappears from the app.

Along comes User B. He loads the app, and is prompted to submit a message of his own. Once he does this, he is then given the option to read a message. Like User A, once he reads the message, it then disappears from the app, never to be seen again.

Both User A and B are then permitted to submit another message if they choose. Upon doing so, they’ll be given the opportunity to receive another message in a bottle. And so on, and so on.

To make it more exciting and random, we will pre-load the database with a bunch of messages.

Message in a Bottle App Flow

The technologies we are going to use to build this masterpiece are some excellent open source frameworks:

  • Ubuntu
  • Vagrant
  • VirtualBox
  • Python3
  • Django
  • Django-REST-Framework
  • IonicFramework

Let’s start by setting up our development environment. For this, we will use Vagrant; an excellent application that allows you to easily create and configure lightweight, reproducible and portable development environments. This is what we’ll use to create our back-end infrastructure locally on our machines.

Vagrant relies on an underlying virtualisation platform. It offers support for VMWare, Hyper-V, Docker and VirtualBox (more details here: https://www.vagrantup.com/docs/providers/). For this walk through, we’ll use VirtualBox as it’s free and works on Windows, Linux and Mac.

Download and Install VirtualBox

If you don’t have it already, start by installing VirtualBox on your machine. Download the relevant package from: https://www.virtualbox.org/wiki/Downloads. If you are using Windows 10 (like me) the package will be “VirtualBox 5.0.16 for Windows hosts x86/amd64”.

VirtualBox Download Options

Once downloaded, double click the icon to load the installer:

VirtualBox Installer Icon

On the Welcome to Oracle VM VirtualBox 5.0.16 Setup Wizard screen, click Next.

VirtualBox Welcome to Oracle VM VirtualBox 5.0.16 Setup Wizard

On the Custom Setup screen, leave it all as default and click Next >.

VirtualBox Custom Setup Screen

On the Custom Setup screen, leave all the boxes checked and click Next >.

VirtualBox Custom Setup Install Screen

On the Warning: Network Interfaces screen, take note that your Better Call Saul Netflix Stream may be briefly interrupted, as your network will be temporarily disconnected and click Yes.

VirtualBox Warning: Network Interfaces Screen

On the Ready to Install screen, click Install.

VirtualBox Ready to Install Screen

VirtualBox will start to install…

VirtualBox Oracle VM VirtualBox Installing

On the User Account Control screen, click Yes.

Oracle Corporation - User Account Control

VirtualBox will do more installing…

VirtualBox Oracle VM VirtualBox 5.0.16 Validating Install

Uncheck the Start Oracle VM VirtualBox 5.0.16 after installation. We don’t need to use the VirtualBox interface as Vagrant will do that for us.

On the Oracle VM VirtualBox 5.0.16 installation is complete screen, uncheck the Start Oracle VM VirtualBox 5.0.16 after installation button and click Finish.

VirtualBox Oracle VM VirtualBox 5.0.16 installation is complete

Congratulations! VirtualBox is installed. Now let’s install Vagrant.

Download and Install Vagrant

Go to https://www.vagrantup.com/downloads.html and download the relevant version of vagrant for your operating system. As we are using Windows 10, I will choose the Windows Universal (32 and 64-bit) option.

Vagrant Download Windows Version option

Double click the installer to start the installation.

Vagrant Installer Icon

On the Welcome to the Vagrant Setup Wizard screen, click Next.

Vagrant Welcome to the Vagrant Setup Wizard

Arrange an off-site company event with your legal team and go through the End-User License Agreement. If it’s acceptable, check I accept the terms of the Licence Agreement and click Next.

VirtualBox End-User License Agreement

In the Destination Folder screen click Next.

Vagrant Destination Folder

On the Ready to install Vagrant screen click Install.

Vagrant Ready to install Vagrant

Vagrant will begin installing…

Vagrant Installing Vagrant

If the User Account Control screen appears, click Yes.

Vagrant HashiCorp User Account Control

Vagrant will do some more installing…

Vagrant Installing Vagrant

On the Completed the Vagrant Setup Wizard screen, click Finish.

Vagrant Completed the Vagrant Setup Wizard

When prompted to restart your computer, save all your other work and click Yes.

Vagrant Setup Restart Request

Now after your machine reboots, Vagrant should be installed. Let’s do a quick test. Go ahead and load up Command Prompt by click Start and typing “cmd”.

Windows 10 Command Prompt

When Command Prompt is loaded, type “vagrant” and hit Enter. You should see something like this:

Vagrant Command Prompt Vagrant

If you see this, then Vagrant is installed properly.

Create the Vagrant Box

Next we are going to create the development server using Vagrant. For simplicity my examples will be done from c:\workspace. Start by creating this folder in your C drive.

Now, create a folder within your workspace called “devenv” which stands for “Development Environment”. This will hold all of our project files.

For the following steps we will use Windows Command Line. I am using something called Cmder which is a great alternative to the not so attractive Windows Command Line. You can see more about this and how to get it here: https://londonappdeveloper.com/excellent-command-prompt-alternative/

So, let’s create the vagrant file. Type the following command to change to the correct directory:

cd c:\workspace\devenv

Next, create the Vagrant config by typing the following:

vagrant init

The “vagrant init” command will create a file called Vagrantfile which we will modify later.

Command Line Vagrant Init

If you go back to explorer you will see this file there:

Explorer workspace directory

Next, we are going to make some changes to this file to modify our development environment. Open the “devenv” directory using your favourite code editor. Personally, I like Atom.io so that’s what I’ll use for this demonstration.

You can open the directory in Atom by right clicking the “devenv” folder and clicking Open with Atom:

Explorer - Open with Atom

Now that you’ve opened the directory, let’s make our development environment. To do this, we will use the following technologies:

  • Vagrant – To manage our development environment.
  • Ubuntu – As our server operating system.
  • MySQL – For our Database Server.
  • Salt Stack – To configure our server and install relevant packages.

To get the most out of this guide, I recommend that you follow the step-by-step instructions below to fully understand how it works. However, if you just want to download the working version, you can find it here: https://github.com/LondonAppDev/miab-devenv.

Let’s start by creating our “Salt States”. Salt States are configuration files which describe what packages and directories we want to be on our server. An in-depth understanding of Salt isn’t required for this walk-through, however if you are interested in learning more, I’d recommend reading the official walk-through: https://docs.saltstack.com/en/latest/topics/tutorials/walkthrough.html.

Start by creating a directory to hold our Salt States. We will call this “salt”:

Atom Salt Directory

Inside the salt directory, create a file called “top.sls” and “dev.sls”.

The “top.sls” file is the first thing that Salt will load to check which other files to load. Our one is simple, as we only have one other file (“dev.sls”). Add the following contents to “top.sls”.

base:
  '*':
    - dev

Next, let’s populate the “dev.sls” file. This is where the real work happens. This configuration file will tell Salt to do the following on our server:

  • Install the packages: python3-dev and python-pip.
  • Install the pip package: virtualenvwrapper.
  • Create the directory /usr/local/virtualenvs (for our virtual environment).
  • Create the virtual environment /usr/local/virtualenvs/env (with Python3).
  • Configure “virtualenvwrapper” for the vagrant and root users.
  • Install MySQL server and set the root password to “password”.

I’ve added comments which are prefixed by “#” to explain what is happening. If you don’t fully understand, don’t worry, it can be a bit daunting if this is your first time using Salt, but with practise it will become clearer.

Here is the file:

# Install the packages "python3-dev" and "python-pip".
dev_packages:
  pkg.installed:
    - pkgs:
    - python3-dev
    - python-pip
    - libmysqlclient-dev

# Install "virtualenvwrapper" with pip.
dev_pip_packages:
  pip.installed:
    - pkgs:
    - virtualenvwrapper

# Create the directory for our virtual env.
/usr/local/virtualenvs:
  file.directory:
    - user: vagrant
    - group: vagrant

# Create the virtual environment.
/usr/local/virtualenvs/env:
  virtualenv.managed:
    - system_site_packages: False
    - python: python3.4
    - user: vagrant

# Setup virtualenvwrapper.
virtualenvwrapper_configuration:
  file.append:
    - name: /home/vagrant/.bashrc
    - text: |+
      WORKON_HOME=/usr/local/virtualenvs
      PROJECT_HOME=/project
      source /usr/local/bin/virtualenvwrapper.sh

# Setup virtualenvwrapper for root.
virtualenvwrapper_root_configuration:
  file.append:
    - name: /root/.bashrc
    - text: |+
      WORKON_HOME=/usr/local/virtualenvs
      PROJECT_HOME=/project
      source /usr/local/bin/virtualenvwrapper.sh

# Install the MySQL server using the root password of 'password'.
mysql_server_installed:
  debconf.set:
    - name: mysql-server
    - data:
      'mysql-server/root_password': {'type': 'string', 'value': 'password'}
      'mysql-server/root_password_again': {'type': 'string', 'value': 'password'}
  pkg.installed:
    - pkgs:
    - mysql-server

# Enable the service so MySQL starts when the server boots.
mysql_service_enabled:
  service.running:
    - name: mysql
    - enable: True

# Create a database in MySQL called 'miab_db'
create_database:
  mysql_database.present:
    - connection_user: root
    - connection_pass: 'password'
    - connection_charset: utf8
    - name: 'miab_db'

Now add the salt minion config. Create a file in the root of the devenv directory called “minion”. We want to tell Vagrant to load the local Salt States file when creating our server:

file_client: local

fileserver_backend:
  - roots

Now that we have added the salt config, let’s write the Vagrantfile, which will tell Vagrant to use our salt states to build our server (among other things). Edit the Vagrantfile and give it the following contents:

# Wrapper for the vagrant config.
Vagrant.configure(2) do |config|

  # Tell vagrant we want an Ubuntu Trusty64 server.
  config.vm.box = "ubuntu/trusty64"

  # Map our "salt" directory in this project to "/srv/salt" on the
  # server
  config.vm.synced_folder "salt", "/srv/salt"
  # Map our "project" directory in this project to "/project"
  config.vm.synced_folder "salt", "/srv/salt"

  # Create a public network so we can access the server from other devices
  # on our network.
  config.vm.network "public_network", type: "dhcp"

  # Configure our server to use "Salt"
  config.vm.provision :salt do |salt|

      # Run salt independently without requring a central management
      # "master" server.
      salt.masterless = true

      # Tell it to use our minion config file "minion".
      salt.minion_config = "minion"

      # After the server boots, run the salt states to defined in the
      # "salt" directory.
      salt.run_highstate = true

  end # End of Salt config.

end # End of Vagrant config.

As with the salt states, I’ve added comments on each line to explain what’s happening.

Finally, create an empty directory called “project” in the root of the devenv directory. This is where we are going to store our project files.

Now, go back to your command line and type “vagrant up” to load your vagrant box. This may take a while (depending on your internet connection) because Vagrant has to download the Ubuntu image.

After the vagrant box is loaded, type “vagrant ssh” to connect to the server.

Command Line Vagrant Up

OK, that’s it! The server and development environment is setup and the first part of this tutorial is complete. Now for the second part of the tutorial: How to Build an App Part 2/3: Creating the back-end with Django REST Framework.

If you haven’t done so yet now would be a good time to sign up to my newsletter. You’ll get notified right away when I publish the next post in this series.

Cheers,
Mark

Tags: Django, Django-REST-Framework, Ionicframework, Python3, Ubuntu, Vagrant, VirtualBox
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://i0.wp.com/londonappdeveloper.com/wp-content/uploads/2016/03/How-to-Build-an-App-Part-1.png?fit=1024%2C1024&ssl=1 1024 1024 mark https://londonappdeveloper.com/wp-content/uploads/2018/12/lon_website_logo-300x110.png mark2016-03-24 12:25:002021-04-11 20:18:29How to Build an App Part 1: Setting up the Development Server with Vagrant, Ubuntu and Salt
You might also like
Smartphone lying on a wood surface How to Build an App Part 1: Setting up the Development Server with Vagrant, Ubuntu and Salt (Mac OS X Version)
Smartphone lying on a wood surface How to Build an App Part 3: Using Ionic Framework
Docker and VSCode logos on an orange background Use Docker to create a new Django project in one line
Smartphone lying on a wood surface How to Build an App Part 2: Creating the back-end with Django REST Framework
Vagrant WordPress and Saltstack software logos bunched together Create a local WordPress dev box in minutes with Vagrant and Salt
Python programming language logo on a background of palm tree leaves Create a local development server for Python apps
Setting up PostgreSQL database with a Django Docker application
Linux penguin logo in front of the words 5 tools My Top 5 Linux Dev Tools for the Full-stack: Atom, Node JS, Vagrant, Virtualbox, and Oh my Zsh
1 reply
  1. Mohammed
    Mohammed says:
    March 24, 2016 at 3:53 pm

    Cool !! thanx mate 🙂

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pages

  • About
  • Consulting
  • Home
  • Tutorials

Categories

  • AI
  • Android
  • Android Studio
  • Angular
  • Aptana Studio
  • AWS
  • Bootstrap
  • Career advice
  • Celery
  • Databases
  • Deployment
  • DevOps
  • Django
  • Django REST Framework
  • Docker
  • Eclipse
  • Getting Help
  • Git
  • Git Bash
  • Git Flow
  • GitHub Actions
  • Google App Engine
  • IDE
  • Ionic Framework
  • iOS
  • JavaScript
  • Job Search
  • Links
  • Linux
  • Mac OS X
  • macOS
  • Node.JS
  • OpenAI
  • PGAdmin
  • Postgres
  • Productivity
  • Python
  • React
  • Salt Stack
  • Stack Overflow
  • Tools
  • Travis-CI
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Vagrant
  • VSCode
  • WebSockets
  • Windows 10
  • WordPress

London App Developer Ltd,

71-75 Shelton Street, Covent Garden, London, United Kingdom, WC2H 9JQ

Company registration number: 09718346

© London App Developer - London App Developer Ltd, Company Registration Number: 09718346, VAT: GB224061842
  • Link to X
  • Link to Youtube
  • Link to Facebook
  • Link to Reddit
Link to: Android Development for Beginners: 6 Steps to Building Your First App Link to: Android Development for Beginners: 6 Steps to Building Your First App Android Development for Beginners: 6 Steps to Building Your First AppAndroid alien in front of a beach image Link to: How to Build an App Part 1: Setting up the Development Server with Vagrant, Ubuntu and Salt (Mac OS X Version) Link to: How to Build an App Part 1: Setting up the Development Server with Vagrant, Ubuntu and Salt (Mac OS X Version) Smartphone lying on a wood surfaceHow to Build an App Part 1: Setting up the Development Server with Vagrant,...
Scroll to top Scroll to top Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OKLearn more

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy Policy
Accept settingsHide notification only