Repository: allegro/ralph

Issue:
Ubuntu package
We should build ubuntu packages for ralph (without much of scan plugins) to be able to install easily if you're reluctant to use docker.
- all js and components integrated into the package
- /etc/ralph for system configuration
- only ubuntu supported



Discussion:
I finished my research and these are my lessons learned:

# Background

I researched two most used  solutions for building deb packages - `fpm` and `dh_virtualenv`, with two variants - Python 2.x and 3.x

# FPM

FPM has built-in solution for building deb packages from python packages. But the limitation is - one `deb` for one `python` package. 

Recently, I've found new target - virtualenv for fpm,  which package all virtualenv into single package. When i discovered, that it requires package to sit on pypi server, I created pull request for building from `pip install .` from local directory. It works fine on travis too - but unfortunatelly the process is limited to Python 2.x 

# dh_virtualenv

Works with python 2.x and 3.x (using venv or virtualenv). I managed to build single ralph-core.deb pacakge and install it in `/usr/share/python/ralph-core/`. 

I tried the Travis integration as well to build the package every single commit, but i've found many shortcomings:
- it requires full-stack vm machine instead of container - thus - setting sudo: true, which increases built time by factor of 4x
- it's required to install dh_virtualenv from sources - you have to make some `PATH` ninja tricks to work, and find out some env variables and patsh - for example home dir for sources is `/home/travis/build/$USER/$REPO/`, python binary is (undocumented) stored in `/opt/python/python3.4.2/bin/python`
- finally it builds the package, but package virtualenv is broken on ubuntu 14 - doesn't set paths correctly. Digging into the virtualenv - some paths are hardcoded for site-packages that doesn't exist in target system. Making fix for --relocatable does the trick, but is not recommended by dh_virtualenv

So the moral is: we can build packages for python3.x outside of Travis, and wait for 14.04 support.

# Storing deb package

We want to be able to install ralph with single command `apt-get install ralph-core`. How to do it ? 
1. http://packagecloud.io - nice but limited for open source projects 
2. http://bintray.com - we already utilise it with Allegrogroup, and it does the job with docker, rpm, maven and others. Looks like more mature solution - so i used it and it works great.

# Summary

For now we will stick to the developer-triggered  `make upload` command inside the vagrant environment.
For this to work it's required to set the BINTRAY_APIKEY environment variable.
In the meantime, we will wait for official Ubuntu14.04 support for travis.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ def read(fname):
 
 setup(
     name='ralph',
-    version='3.0.0',  # TODO: import from ralph
+    version=read('./VERSION').strip(),
     author='Grupa Allegro Sp. z o.o. and Contributors',
     author_email='pylabs@allegro.pl',
     description="Advanced Asset Management and DCIM system for data center and back office.",
@@ -21,13 +21,13 @@ def read(fname):
     keywords='',
     platforms=['any'],
     license='Apache Software License v2.0',
-    packages=find_packages('src'),  # TODO: remove src intermediate directory
+    packages=find_packages('src'),
     include_package_data=True,
     package_dir={'': 'src'},
     zip_safe=False,  # because templates are loaded from file path
     entry_points={
         'console_scripts': [
-            'ralph = ralph.__main__:main',
+            'ralph = ralph.__main__:prod',
             'dev_ralph = ralph.__main__:dev',
             'test_ralph = ralph.__main__:test',
         ],
diff --git a/src/ralph/__main__.py b/src/ralph/__main__.py
--- a/src/ralph/__main__.py
+++ b/src/ralph/__main__.py
@@ -19,5 +19,9 @@ def test():
     main('ralph.settings.test')
 
 
+def prod():
+    main('ralph.settings.prod')
+
+
 if __name__ == '__main__':
-    main()
+    main('ralph.settings.prod')
diff --git a/src/ralph/settings/prod.py b/src/ralph/settings/prod.py
--- a/src/ralph/settings/prod.py
+++ b/src/ralph/settings/prod.py
@@ -4,3 +4,7 @@
 STATIC_ROOT = os.path.join(BASE_DIR, 'var', 'static')
 
 LDAP_SERVER_OBJECT_USER_CLASS = 'user'  # possible values: "user, person
+
+# FIXME: when going for full production, change it to False
+
+DEBUG = True


Test patch: