Zanby Product Wiki >> Developing environment setup (standalone)
Developing environment setup (standalone)¶
Abstract¶
This document describe process of setting up a standalone developing environment for Zanby-like implementation.
Assumed environment¶
Linux box (or vm), with running X-windows.
Some assumptions:- we want a completely standalone development environment -- no dependencies on outside machines. (except for source code repository, obviously)
- we want to be able to write code, debug code, and run code all on the same hardware.
- we are comfortable working in a linux development environment
- we need one or more instances of a working environment
There is a separate page for getting the [[Warecorp Internal:zanby dev machine setup|machine support set up for zanby development]].
Structure of the application¶
The application consists of two parts: core and implementation. core is a set of classes of third-party libraries (like Zend) and our models, helpers which used to access the data, manipulate it and etc. implementation is a part of the application which should do minimal business-logic, ideally it should only access data using models from core assign it to templates. If you are familiar with MVC approach in web-programming 'M' (Models) is core, 'V' (Views) and 'C' (Controllers) is implementation.
When several implementations using the same database for storing their data they have to use the same core codebase. core can have some customized code for a specific set of implementations. We call that context. Classes customized for specific context have a prefix with context name, e.g. CPP_User_Profile. Additionally, we have separate database migrations for that context, check db/<context>/migrate in the core work copy.
For fast switching between configuration settings configuration files is split on several sections. Production, staging and development sections is required. Other is optional. For setting current environment is required environment variable APPLICATION_ENV.
There are several ways for set variable for httpd and shell scripts:
- for shell scripts execute in shell
export APPLICATION_ENV=<user>
- for httpd add line into .htaccess or virtual host next line
SetEnv APPLICATION_ENV <user>
In this case all configuration parameters will be received from chosen section (section name "<user>"). For example: my user name is pianko. Shell command: export APPLICATION_ENV=pianko. Chosen section from cfg.site.xml is config -> pianko -> param.
Also there are several simplifications:
if required section is not exist in configuration file, default section is development. That rule works for all environments except production and staging. Also we have a list of configuration files where users section is mandatory: cfg.core.xml, cfg.instance.xml and cfg.baseImplementation.xml. More details about these files please find bellow.
Step by step instructions.¶
I am going to provide step by step instructions how to setup typical implementation:
- Prepare directory for your developing environment. I usually use the following scheme:
~/src/<context>/<implementation_name>
and~/src/<context>/core
- Make the directory:
% mkdir -p ~/src/<context>
- checkout trunk for core:
% svn co https://svn.warecorp.com/svn/zanby/sources/product/core/trunk core
- checkout trunk for <implementation-name>:
% svn co https://warecorp.com/svn/zanby/sources/implementations/<implementation-name>/trunk <implementation-name>
- change directory to core:
% cd core/
- configure _configs/cfg.baseImplementation.xml:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <config> 3 ... 4 <user> 5 <baseImplementation>/home/user/src/<context>/<implementation-name>/</baseImplementation> 6 </user> 7 </config> - change directory to implementation:
% cd /home/user/src/<context>/<implementation-name>
- configure configs/cfg.instance.xml, configs/cfg.creadentials.xml, configs/cfg.core.xml; add user section in config files (for example user name "user"):
<user extends="development"></user>
- configure configs/cfg.credentials.xml (add to user section):
1 ... 2 <db> 3 <database> 4 <use>true</use> 5 <type>PDO_MYSQL</type> 6 <host>localhost</host> 7 <username>someuser</username> 8 <password>somepassword</password> 9 <name>somedbname</name> 10 </database> 11 </db> 12 ... - configure configs/cfg.credentials.xml (add to user section):
1 ... 2 <messagedb> 3 <database> 4 <use>true</use> 5 <type>PDO_MYSQL</type> 6 <host>localhost</host> 7 <username>someuser</username> 8 <password>somepassword</password> 9 <name>somedbname_sub</name> 10 </database> 11 </messagedb> 12 ... - configure configs/cfg.core.xml (add to user section):
... <core> <path>/home/user/src/<context>/core</path> </core> ... - change directory to core:
% cd /home/user/src/<context>/core
- specify context for the core using CONTEXT environment variable (context is some specific set of core's classes and database migration; classes specific for context has a prefix upper-cased context name, migrations are always context specific: you can see available context by
ls db: MJM: I set this toCONTEXT=productfor my testing.% export CONTEXT=<context>
- specify APPLICATION_ENV for implementation and core. There are several ways:
- 1. execute in shell
export APPLICATION_ENV=<user>
- 2. Add to bash profile "export APPLICATION_ENV=<user>" line
- 3. Add APPLICATION_ENV directly in rake call
rake APPLICATION_ENV=<user> cache:clean
- 1. execute in shell
- create all databases, you can use rake for this task, it read configuration you provided:
% rake db:create subdb:create % rake db:grant_privileges subdb:grant_privileges
- migrate the databases:
% rake subdb:migrate db:migrate
- configure web-server, apache in our case; we should create a virtual host with desired name and allow override rewrite settings (there is htdocs/.htaccess with rules):
<VirtualHost *:80> ServerName <implementation-name>.<hostname> DocumentRoot /home/<user>/src/<context>/<implementation-name>/htdocs <Directory /home/<user>/src/<context>/<implementation-name>/htdocs> AllowOverride All Order allow,deny Allow from All </Directory> </VirtualHost> - configure _configs/cfg.instance.xml for implementation, here is the critical values you absolutely have to configure for current instance section:
...skip... <!-- SITE URLs CONFIGURATION base_http_host - base host for site without http://. e.g. zanby.com domain_for_email - domain for all emails that used on site from project side (administrators, feedback, support) domain_for_group_email - domain for project groups emails. e.g. if we have group 'group1' - it will be group1@{domain_for_group_email} --> <base_http_host><implementations-name>.<your-hostname></base_http_host> <domain_for_email><implementations-name>.<your-hostname></domain_for_email> <domain_for_group_email>groups.<implementations-name>.<your-hostname></domain_for_group_email> <serve_url><implementations-name>.<your-hostname>/upload/scriptCO</serve_url> ...skip... - fix permissions to give access to apache process for writing to cache directories, there is a rake task for this:
% rake files:fix_permissions
- you also should give apache access for htdocs/upload, this can be done by:
% chmod 777 -R htdocs/upload
- install main group family; there is an installer script in implementation:
% cd ./script/base/installer % cp install.settings.<context>.xml.sample install.settings.<context>.xml % php -f ./install.group.family.php done
This point required for EIA/Satellite implementations only. - next you have to configure sphinx server, open the file core/_configs/sphinx.conf and replace all /my/dir with /home/<user>/<context>/sphinx;
- configure MySQL access information for sphinx in the above of the sphinx.conf:
source appdb { type = mysql sql_host = myhost sql_user = myuser sql_pass = mypassword sql_db = mydb sql_port = 3306 # optional, default is 3306 sql_query_pre = SET NAMES utf8; .... listen = host:port } - configure _configs/cfg.instance.xml. Add host and port for sphinx:
<search> <host>host</host> <port>port</port> </search> - create directory for sphinx:
% mkdir /home/<user>/<context>/sphinx
- generate initial indexes:
% cd /home/<user>/<context>/core % indexer --all --config _configs/sphinx.conf
- start sphinx server:
% rake sphinx:start
or% searchd --config _configs/sphinx.conf
- now point your browser to http://<implementation-name>.<hostname> and have fun! ;]