Showing post with tag vagrant. Show all

vagrant 2


by Malik BOUGACHA, EBU on 03 Oct 2013

virtualenv

introduction

Last time, we discovered a problem inherant to the software world. Software change an d api to the software changes too. We also briefly talked about virtualenv in python. How does it work ?

Simple usage

You can specify a python virtualenv which is a set containing a python interpreter and a set of libraries. You can specify a version of each libary you want either by a specific version number or by a minimum version.
We define this set of libraries at the configuration time. Let's take a simple example :

mkdir mynewproject 
cd mynewproject 
touch pip_requirements.txt 

So now we will switch to the virtualenv

virtualenv . 
source bin/activate 

we can see that we have only a couple dependencies

pip freeze #this will list installed module that pip installed 

so let's add a couple of dependencies. To make it shorter and more easily manageable, we will put everything in the pip_requirements.txt.

http://example.com/baz-0.3.tar.gz #we can also specify a http or ftp tar containing a setup.py 
requests=0.10.0 #yes I love old version 

then we install them in the virtualenvironnement :

pip install -r pip_requirements.txt 

As you can see, this installed the module in the new virtualenv.

pip freeze 
```bash
Now that we installed new dependencies, we will leave the virtualenv. 

deactivate


we can check that we are outside of the virtualenv by doing  

pip freeze ```

python version

Now, imagine that you would like to test

System wide dependencies

Great now we can easily manage

  • python dependencies
  • python interepreter

What if we want to add system dependencies ? Say a mysql database and a memcache cache ? We could also want to test our system on multiple host configuration, some with mysql other with posgre, or even test it under different system, for example a BSD based system and a linux based one. both having their own library version or even software. We have another solution. Instead of a simple virtualenv, we will see how we can simply put all our environnement into a separated environnement.


python vagrant

vagrant 1


by Malik BOUGACHA, EBU on 14 Sep 2013

Developpement sandboxing

Vagrant is a way to sandbox the devloppement environement. I will take python as an example of sandbox and explain how we come from a simple os based devloppement environement and test to a vm env.

machine

Let's start with a simple machine environement

python server.py 

The server.py being a very simple flask server:

from Flask import Flask 

app = Flask() 

if __name__ == "__main__": 
    app.run() 

Great right ?
But what happens if we add more dependencies, for example requests, a python module for doing http request.

from Flask import Flask 
import requests 

app = Flask() 

@app.route("/") 
def main(): 
    return request.get("http://example.com/json").json() 

if __name__ == "__main__": 
    app.run() 

The example is pretty simple right ? What does happen when we want to deploy it ? It will crash depending on the version of the requests module we have. As we have a stable version of debian, we don't have the right version of the library and of course we don't want to install it at a system wide level But there is a solution for this in python: virtualenv.


dependencies python vagrant virtualenv