Skip to content

GeoPortal Build Process

John Paden edited this page Jun 3, 2016 · 12 revisions

Building the GeoPortal means creating a directory that includes a single JavaScript file that is minified and contains the complete application and library source. In addition an index HTML file and a resources directory are also created. The "build" files are what are put into the web directory on the server. An overview of the whole process is described in Geoportal Basics.


Introduction

Build Types

Script Details

Deploying a Build


Introduction

A python script has been created to simplify the building process. Currently the script only runs under Windows. To run it you must have the following installed on your local system:

Python 2.7.6+ (Not 3)

Sencha Cmd (Tested at 4.0.4). Make sure to enable all the extensions including "Compass". Compass is used to

Ruby and Ruby Gems are required to run Compass. Here is a more direct link to Ruby Installer for Windows. Under Linux, you can use yum install ruby and yum install rubygems.

PyCharm. PyCharm is a convenient IDE for running Python and editing the javascript.

To build the software in PyCharm:

  1. Open the project by choosing the OPS-GEOPORTAL directory/repository.
  2. Once your Javascript edits are completed, to create the minified .js file right click on opsBuildPortal.py and choose run.
  3. This should execute with no errors. The outputs are placed in OPS-GEOPORTAL\build\production\OPS.

Build Types

This script will do a complete build, there are two types of builds.

Testing Build A testing build compiles the source and creates the complete build directory but the resulting single JavaScript file is not minimized meaning it is still human readable. This is a good way to run the build process but still be able to debug errors is they occur. A testing build should be run on a development VM, never in production.

To create a testing build call the script like this:

python opsBuildPortal.py --testing=True

Production Build A production build is the complete compiled and minimized build which is suitable for placing on the production server. ONLY production builds should ever be committed to the OPS repo.

To create a production build call the script like this:

python opsBuildPortal.py

Script Details

import argparse,subprocess,os,getpass,datetime
from distutils.dir_util import copy_tree

# GET SOME INFORMATION
curUser = getpass.getuser()
curDate = str(datetime.datetime.now())

# SET THE CUSTOM OL DIRECTORY
olDir=os.getcwd()+'\\ol-custom\\ol'

This section imports the needed libraries, get the system user and the current time and creates a variable which stores the ol-custom library directory. You can specify your own ol-custom directory (you must if you run the script outside of the directory the script is in) by calling the function with --olDir='SOMEPATH'.

# PARSE INPUT ARGUMENTS
parser = argparse.ArgumentParser(description='CReSIS OpenPolarServer ExtJS Custom Build Script')
parser.add_argument('--testing',default=False,help='testing (boolean): should this be a test build (not minimized)')
parser.add_argument('--olDir',default=olDir,help='olDir (string): absolute path to CReSIS OpenLayers build')
inArgs = parser.parse_args()

This section takes the optional arguments and sets the defaults.

	subprocess.call('sencha app build testing', stdin=None, stdout=None, stderr=None, shell=False) # BUILD TESTING
	copy_tree(olDir,os.getcwd()+'\\build\\testing\\OPS\\resources\\ol') # COPY OL BUILD SOURCE
	indexFileObj = open(os.getcwd()+'\\build\\testing\\OPS\\index.html','w') # OPEN INDEX (CLEAR EXISTING CONTENTS)
	logStr = 'TESTING BUILD CREATED ON %s BY %s\n' % (curDate,curUser) # CREATE LOG ENTRY

This section creates the testing build. First the sencha build process is run sencha app build testing then the OpenLayers source is copied (it's not included in the sencha build) next the index.html is created (cleared of contents) and finally the build is logged in the file opsBuildPortal.log.

	subprocess.call('sencha app build', stdin=None, stdout=None, stderr=None, shell=False) # BUILD PRODUCTION
	copy_tree(olDir,os.getcwd()+'\\build\\production\\OPS\\resources\\ol') # COPY OL BUILD SOURCE
	indexFileObj = open(os.getcwd()+'\\build\\production\\OPS\\index.html','w') # OPEN INDEX (CLEAR EXISTING CONTENTS)
	logStr = 'PRODUCTION BUILD CREATED ON %s BY %s\n' % (curDate,curUser) # CREATE LOG ENTRY

This is the same as the previous section, but creates a production build by ommitting testing in the sencha call sencha app build.

# WRITE NEW INDEX.HTML
indexFileObj.write('''<!DOCTYPE HTML>
<html>
<head>
	<meta charset="UTF-8">
	<title>OpenPolarServer</title>
	<link rel="icon" href="resources/favicon.ico" type="image/x-icon"/>
	<link rel="shortcut icon" href="resources/favicon.ico" type="image/x-icon"/>
	<link rel="stylesheet" type="text/css" href="resources/ol/theme/default/style.css">
	<script type="text/javascript" src="resources/ol/OpenLayers.js"></script>
	<script type="text/javascript" src="resources/ol/proj4js/lib/proj4js-compressed.js"></script>
	<link rel="stylesheet" href="resources/OPS-all.css"/>
	<script type="text/javascript" src="app.js"></script>
	<style type="text/css"> .legend {padding-left: 50px;} </style>
</head>
<body></body>
</html>''')
indexFileObj.close()

This section writes the complete index HTML file.

# UPDATE LOG
logFileObj = open(os.getcwd()+'\\opsBuildPortal.log','a')
logFileObj.write(logStr)
logFileObj.close()

This section writes the log entry.

Deploying a Build

Once a build is complete it is located in OPS-GEOPORTAL/build/production/OPS/* Everything under the OPS/ directory is what you want to push into the /conf/geoportal/ directory of the OPS repository. However, since most files do not change (or at least should not change), you only need to copy, commit, and push the files that have changed. For most code changes this is app.js only. HTML changes are usually in index.html or resources/about.html. See GeoPortal Basics for the remaining steps.