Build Contrial Source Code

Reference

http://juniper.github.io/contrail-vnc/README.html

Hardware && Software

Vitualized machine which have 1G memory and 1 core.
Running 12.04:

# cat /etc/issue
Ubuntu 12.04.3 LTS \n \l

Packages

You should install following packages:

$ sudo add-apt-repository ppa:opencontrail/ppa
$ sudo vim /etc/apt/source.lists
deb http://ppa.launchpad.net/opencontrail/ppa/ubuntu precise main
deb-src http://ppa.launchpad.net/opencontrail/ppa/ubuntu precise main
$ sudo apt-get install  -y scons git python-lxml wget gcc patch make unzip flex bison g++ libssl-dev autoconf automake libtool pkg-config vim python-dev python-setuptools libprotobuf-dev protobuf-compiler libsnmp-python libgettextpo0 libxml2-utils debhelper python-sphinx ruby-ronn libipfix python-all libpcap-dev module-assistant libtbb-dev libboost-dev liblog4cplus-dev libghc-curl-dev
$ sudo apt-get install python-pip
$ sudo pip install gevent bottle netaddr 

Getting Source Code

Use repo for getting the source code:

$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ echo "export PATH=/usr/local/git/bin:$PATH">>~/.bashrc
$ source ~/.bashrc

Fetch the repository and sync it.

$ mkdir ~/Code/OpenContrail
$ cd ~/Code/OpenContrail
$ repo init -u git@github.com:Juniper/contrail-vnc
$ repo sync

Some of the packages will be blocked by GFW, be sure you use proxy for downloading them.
Fetch the third party packages:

$ python third_party/fetch_packages.py

Build the OpenContrail & Pakages

The build step is simply via scons, after a long wait, it will pass.
Generate packages via:

$ make -f packages.make

The default configuration will make all of the components in packages.make, or you could seperately build single component.

Build Specified Version Of OpenContrail

Since the default building of OpenContrail is master branch, while the installation deb file named like contrail-install-packages_1.21-74~havana_all.deb, this gap need to be filled via building.

View Different Branches

Repo hold all of the versions locally, simply view them via:

# pwd
/root/Code/OpenContrail/.repo/manifests
# git branch -a | cut -d / -f 3
* default
master -> origin
R1.04
R1.05
R1.06
R1.06c1
R1.10
R1.30
R2.0
R2.1
gh-pages
master
opserver
rajreddy_doc_update
rajreddy_doc_update2
rajreddy_webui_third

While these branches doesn’t contains 1.21, why?

Specify Different Tag

In git admined project, tag is frequently be used, thus we could fetch the code via specified tag.
Repo need to run following command to enable all of the sub-project syncs to specified tag, following I use v1.21 tag for syncing.

$ repo forall -c 'git checkout v1.21`
$ repo sync
$ python third_party/fetch_package.py && scons && make -f packages.make

Need a long time for checking the generated packages.
Problem:

dpkg-source: error: syntax error in contrail/debian/control at line 33: block
lacks the 'Package' field
dpkg-buildpackage: error: dpkg-source --before-build contrail gave error exit
status 25

when running make -f packages.make, it will failed, just remove the line before packages it will be OK.

Specify Different Branch

Specify the branch of:

repo init -b android-2.3_r1 ; repo sync
repo init -b R2.20


Play Docker(4)

Fig(Continue)

Met some problems in last article, so this part will continue to work on Fig, the correct configuration files are listed as following:

$ ls
app.py  Dockerfile  fig.yml  requirements.txt
$ cat Dockerfile 
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
$ cat fig.yml 
web:
  build: .
  command: python app.py
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: redis
$ cat requirements.txt 
flask
redis
$ cat app.py 
from flask import Flask
from redis import Redis
import os
app = Flask(__name__)
redis = Redis(host='redis', port=6379)

@app.route('/')
def hello():
    redis.incr('hits')
    return 'Hello World! I have been seen %s times.' % redis.get('hits')

if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)

via fig up you could quickly build this app and let it run.
When it running, you could use fig ps for viewing the running instance:

$ sudo fig ps
      Name             Command             State              Ports       
-------------------------------------------------------------------------
figtest_redis_1    /entrypoint.sh     Up                 6379/tcp         
                   redis-server                                           
figtest_web_1      python app.py      Up                 0.0.0.0:5000->50 
                                                         00/tcp    

Use sudo fig run web env you could view all of the variables of the running instance web, or change web into redis then displaying the variables of redis.
Use sudo fig stop to stop all of the running instance.

$ sudo fig stop
Stopping figtest_web_1...
Stopping figtest_redis_1...

Use sudo fig run web env for displaying all of the variables of running web.

Create Django

Configuration files:

$ cat Dockerfile 
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

$ cat fig.yml 
db:
  image: postgres
web:
  build: .
  command: python manage.py runserver 0.0.0.0:8000
  volumes:
    - .:/code
  ports:
    - "8000:8000"
  links:
    - db

$ cat requirements.txt 
Django
psycopg2


Via sudo fig run web django-admin.py startproject figexample .
This means, first fig will create the image, then use this image for running django-admin.py startproject figexample, Examine via different methods:

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
1abcafc5bd59        postgres:9          "/docker-entrypoint.   4 minutes ago       Up 3 minutes        5432/tcp            django_db_1         
741b0e375c73        postgres:9          "/docker-entrypoint.   4 minutes ago       Up 4 minutes        5432/tcp            Django_db_1         
[Trusty@DashCentOS django]$ sudo fig ps
   Name                  Command               State    Ports   
---------------------------------------------------------------
django_db_1   /docker-entrypoint.sh postgres   Up      5432/tcp 

Change the configuration file of the django project:

$ sudo vim figexample/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'postgres',
        'USER': 'postgres',
        'HOST': 'db',
        'PORT': 5432,
    }
}

Save the file and run sudo fig up, this time your django project connects to the right postgresql server.
Examine the running containers:

$ sudo fig ps
      Name             Command             State              Ports       
-------------------------------------------------------------------------
django_db_1        /docker-           Up                 5432/tcp         
                   entrypoint.sh                                          
                   postgres                                               
django_web_1       python manage.py   Up                 0.0.0.0:8000->80 
                   runserver ...                         00/tcp           
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
d3c3c8bb6d0e        django_web:latest   "python manage.py ru   4 minutes ago       Up 4 minutes        0.0.0.0:8000->8000/tcp   django_web_1        
3f7b61fdd09e        postgres:9          "/docker-entrypoint.   4 minutes ago       Up 4 minutes        5432/tcp                 django_db_1        

Run ASP

Refers to:
http://dockerone.com/article/164
The steps are listed as:

$ git clone https://github.com/aspnet/Home.git
$ cd Home/
$ cd samples/HelloWeb/
$ vim Dockerfile
FROM microsoft/aspnet

COPY . /app
WORKDIR /app
RUN ["kpm", "restore"]

EXPOSE 5004
ENTRYPOINT ["k", "kestrel"]
$ sudo docker build -t myapp .
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
myapp               latest              6c0d622049ea        2 hours ago         492 MB
microsoft/aspnet    latest              1e67fe2f5a59        13 days ago         465.3 MB
$ sudo docker run -t -d -p 80:5004 myapp

Open your browser and visit http://xxx.xx.xx.xxx:80 and you could found the asp based app runs.

Play Docker(3)

Dockerfile

Dockerfile is like Vagrantfile, for define the configuration of the docker container.
The steps for creating the Dockerfile is listed as following:

$ mkdir -p ~/Code
$ cd ~/Code && vim Dockerfile 
FROM ubuntu:13.04
MAINTAINER examples@docker.com
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y openssh-server nginx  supervisor
RUN mkdir -p /var/run/sshd
RUN mkdir -p /var/log/supervisor
RUN echo "daemon off;">>/etc/nginx/nginx.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 22 80
CMD ["/usr/bin/supervisord"]
$ vim supervisord.conf 
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D

[program:nginx]
command=/usr/sbin/nginx
user=root
autostart=true

Now build the target image with following command:

$ sudo docker build -t test/supervisord .

After build, we could use sudo docker images for examing the generated images. And use following command for start the sshd and nginx service:

$ sudo docker run -p 2222:22 -p 8080:80 -t -i test/supervisord

Now change the root password and you could directly ssh root@127.0.0.1 -p 2222 or you could directly access http://1xx.xx.xx.xxx:8080 for nginx webpages.

Fig

Fig is used for swiftly build up a container. You only need to add a fig.yml and specify some simple content, then it could easily assit you building up a container.
Install fig via following command:

$ wget https://github.com/docker/fig/releases/download/1.0.1/fig-`uname -s`-`uname -m`
$ sudo mv fig-xxx-xxx /usr/bin/fig
$ sudo chmod 777 /usr/bin/fig

Touch the definition files under a specified directory and then use fig for building the whole container:

$ mkdir ~/fig
$ ls
app.py  Dockerfile  fig.yml  requirements.txt
$ cat Dockerfile 
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
$ cat fig.yml 
web:
  build: .
  command: python app.py
  links:
   - db
  ports:
   - "8000:8000"
db:
  image: redis
$ cat requirements.txt 
flask
redis
$ cat app.py 
from flask import Flask
from redis import Redis
import os
app = Flask(__name__)
redis = Redis(host='redis', port=6379)

@app.route('/')
def hello():
    redis.incr('hits')
    return 'Hello World! I have been seen %s times.' % redis.get('hits')

if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)

Now use sudo fig up then you could let this web service run.

Met some problems, will be do this at home.

Using Teamviewer

Installation

CentOS

Download the corresponding rpm files, install it via sudo yum install ******.rpm, this will automatically install the dependencies and also install the teamviewer for your centos system.

Ubuntu

Only working for 14.04:
First you have to add i686(i386) supporting:

$ dpkg --add-architecture i386
$ apt-get update

Then you have to downloaded the following packages rather than the offcial packages(x64 or i386):
http://download.teamviewer.com/download/teamviewer_linux.deb
Install this teamviewer_linux.deb, and you got teamviewer running on your system.
For 12.04, directly download the package from:
http://download.teamviewer.com/download/teamviewer_linux_x64.deb
Then install it via:

# dpkg -i teamviewer_linux_x64.deb
# apt-get install -f

Then teamviewer could be installed on your system.

Connect Back

First your server side will install the teamviewer and run is as the daemon mode.

Tips

Stop the teamviewerd via(On CentOS):

$ sudo teamviewer --daemon stop

While start it via:

$ sudo teamviewer --daemon start

Seems someone blocked the flow to this site…55555