Introduction

Scripts are available for managing MapFish projects more easily. They can help in the following tasks:

  • Fetching/Updating the project from SVN with its requirements (a given MapFish version, setting up a Python virtual env, ...)
  • Replacing variables in configuration files with host dependent settings

Setting up your project

You first need to create a file which contains the configuration parameters for your project. Copy the source:trunk/MapFish/deploy/deploy-sample.sh file into deploy-yourproject.sh file inside a deploy directory of your project:

cd yourproject
svn mkdir deploy
cd deploy
svn cat http://www.mapfish.org/svn/mapfish/trunk/MapFish/deploy/deploy-sample.sh > deploy-yourproject.sh
chmod +x deploy-yourproject.sh
svn add deploy-yourproject.sh
svn ci

Editing the deploy-yourproject.sh file

You should set at least your projet name, svn location an whether you are using Pylons.

Making your configuration environment neutral

Sometimes, you need to put information in your files which are environment dependent (server addresses, database location, ...).

The deploy script has a mechanism for handling such a situation. The script will copy files ending with .in to the name without the .in, and will replace varialbes defined like %MY_VARIABLE%.

For defining the variables to replace, you can create a directory "configs" in your projet with files named from your hostname or path where the project is run.

For instance, you can have

  myconfig.in
  configs/
    hostname1
    hostname2-var-www-myproject
    hostname2-home-bob-myproject

The deploy script will look at the file hostname1, on hostname hostname1. Or the file hostnam2-var-home-bob-myproject on the server hostname2, in the directory /home/bob/myproject

Configuration variables

  • GENERATED_WARNING: This variable should be put on top of every .in files, that will show a warning message on the generated files that they shouldn't be edited
  • PROJECT_DIR: The directory containing the project
  • PROJECT: name of the project
  • PASTE_CONFIG: name of the paste deployment file, set to $PROJECT_DIR/$PROJECT/$PROJECT.ini

All default configuration variables can be seen there: source:trunk/MapFish/deploy/config-defaults

Deploying/Updating a project

Once you your deploy script and configuration variables set up, you can deploy a project from scratch at different location.

For instance, you want to install the project in /var/www/myproject

mkdir /var/www/myproject
cd /var/www/myproject
svn co -N http://example.com/myproject/trunk/myproject/deploy .
# This fetches deploy-myproject.sh
./deploy-myproject.sh -i

This will fetch MapFish, your project and install a Python virtual env according to your configuration.

Using hooks

You can put functions in your config files to run at some times during a deploy. See source:trunk/MapFish/deploy/deploy.sh for the list of hooks.

Sample:

function post_fetch_project() {
        echo "Setting permissions in post_fetch_project hook..."
        DATA_DIR=$PROJECT_DIR/$PROJECT/data
        if ! test -d $DATA_DIR; then
                mkdir $DATA_DIR
        fi
        chmod 777 -R $DATA_DIR
}