2015年5月25日 星期一

Setup VCS Using Redmine + Git

We all know that Git is a very good VCS, with redmine, like Bugzilla, we have even better control and graphical view on our repository, and this is undoubtedly aid development. The following is how to make the whole VCS system happens.

What we need
1) Git (of course!)
2) Redmine
3) Apache Server

Procedure
1) Install all the necessary components respectively
sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt-get install redmine-mysql
sudo apt-get install libapache2-mod-passenger
sudo apt-get install redmine
sudo apt-get install git-core

2) Set up soft link from redmine source to the Apache source
sudo ln -s /usr/share/redmine/public /var/www/redmine

3) mod passenger needs www-data to execute, add the following to /etc/apache2/mods-available/passenger.conf
vi /etc/apache2/mods-available/passenger.conf
PassengerDefaultUser www-data

 4) Add redmine's web directory to Apache2's sites-available/default

                RailsBaseURI /redmine
                PassengerAppRoot /usr/share/redmine
                RailsEnv production
                PassengerResolveSymlinksInDocumentRoot on
5) Setup plugin linkage
 ln -s /var/cache/redmine/default/plugin_assets /usr/share/redmine/public/

6) Create new repository (server side), note that the directory should be with owner "www-data"
cd /var/www
mkdir test-repo.git
cd test-repo.git
git --bare init
git update-server-info
chown -R www-data.www-data .

 7) Enable webDAV
a2enmod dav_fs
a2enmod dav

If high security is required, carry on, if not, restart apache and all services will be done

8) Create the following file
/etc/apache2/conf.d/git.conf

9) Configure the repository path for authentication
        DAV on
        AuthType Basic
        AuthName "Git"
        AuthUserFile /etc/apache2/passwd.git
        Require valid-user

10) Create user which can access the repository
 htpasswd -c /etc/apache2/passwd.git

11) Restart Apache service
/etc/init.d/apache2 restart

Done! You have made a git VCS with redmine geared!

Almost forgot, modifying the config file in .git directory is necessary for authentication when pushing
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://username:password@git.repository.url/repo.git

References:
- Linking git remote server to Apache
http://blog.bobbyallen.me/2012/07/23/installing-a-git-server-using-apache-webdav-on-ubuntu-server-12-04/

- Installing Apache + Git + Redmine
http://blog.chiichen.com/2014/05/raspberry-pi-redmine.html

- Git config fix on http/https authentication
http://stackoverflow.com/questions/5264949/cannot-push-git-to-remote-repository-with-http-https

- Others
https://randomthoughtsgr.wordpress.com/2011/10/17/redmine-sub-uri-and-apache-configuration/

2015年5月12日 星期二

cxfreeze Python program (Linux) - Wrapping the Python Program to Single Executable

I would like to note down here because Googling results frustrating with

  • Large amount of Windows environment Python application wrapping
  • Misleading and lack of example of cxfreeze API

But thanks for Stackoverflow, I finally get the solution despite various failure on different problems during the wrapping of my wxPython application.


Here is my situation
    I have written a wxpython program, and the program consist of not only .py files but with images and xml files, I want to 

  1. Wrap all these stuffs to one executable program in Ubuntu
  2. Deploy this program with deb installer

Solutions
  1. Download and install cxfreeze
  2. Please let me know but I cannot find relative commands on how to include external files, therefore I use the officially provided py script
    http://cx-freeze.readthedocs.org/en/latest/script.html
  3. Follow the below official guide and write the setup script to build the program
    http://cx-freeze.readthedocs.org/en/latest/distutils.html
  4. Run python setup.py build and your program will be built
  5. Follow the file structure to build the deb

  • mpstoolbox is the app name, name your own one
  • DEBIAN/control, DEBIAN/postinst is files to configure the deb package
  • usr/bin/..., this is the installed path, you should make your own path, all the files installed will follow this path structure
  • Finally, cd back to the folder (your app name), use dpkg -b yourAppName
  • A deb package will be generated
  • Use dpkg -i to install

Here comes the MOST important part, my problem

    It seems simple to follow the above to build the program, but indeed it doesn't, the guide does not teach you clearly on how to include the required modules to let you bring your program to other Linux machine to run, you need to follow the followings


  • binpathincludes parameter is important, please include all system library like /usr/lib, /usr/local/lib, or you may encounter this error libwx_gtk2u import error, ImportError: libwx_gtk2u_adv-2.8 etc. This is deal to the missing of wxPython library, you therefore need to include all required system library when building the app
  • About the setup.py, the api is not very clear in cxfreeze, follow stackoverflow's guide, thanks to the bro there, he also suffered from the lack of clearance of the api
    http://stackoverflow.com/questions/15486292/cx-freeze-doesnt-find-all-dependencies

    One thing here to pay attention to, the "include_files" attribute should be a list of tuples instead of single name only!! Your external files and other required images should also put it here.