Mercurial > dive4elements > river
diff contrib/make_flys_release/make_release.sh @ 5251:8fa0c522bef3
Improve make_release script to optinally handle tagging and be more generic.
It can now be used to prepare a fully configured version of flys.
There are still some variables to set in the script or to be overwritten by
environment variables.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 12 Mar 2013 16:52:55 +0100 |
parents | 613d2f494728 |
children | a859691ec4a0 |
line wrap: on
line diff
--- a/contrib/make_flys_release/make_release.sh Tue Mar 12 16:50:47 2013 +0100 +++ b/contrib/make_flys_release/make_release.sh Tue Mar 12 16:52:55 2013 +0100 @@ -1,149 +1,303 @@ #!/bin/bash +# Release script for Flys +# +# Authors: +# Andre Heinecke <aheinecke@intevation.de> +# +# Copyright: +# Copyright (C) 2013 Intevation GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. set -e +DEFAULT_WD=/tmp/flys-release +DEVELOPER=aheinecke -echo "INFO: define required variables" ARTIFACTS_HG_REPO="http://wald.intevation.org/hg/dive4elements/artifacts" HTTPCLIIENT_HG_REPO="http://wald.intevation.org/hg/dive4elements/http-client" FLYS_HG_REPO="http://wald.intevation.org/hg/dive4elements/flys" -ARTIFACTS_HG="hg.artifacts" -HTTPCLIENT_HG="hg.http-client" -FLYS_HG="hg.flys" +REPOS="artifacts http-client flys" +# Do not use spaces in path +FLYS_SOURCE_DIR=/local-vol1/aheinecke/flys-release -PREFIX="flys-" -RELEASE=${RELEASE:-default} -RELEASE_DATE=`date +'%Y-%m-%d'` -DIRECTORY=$PREFIX$RELEASE-$RELEASE_DATE +SCRIPT_DIR=$(readlink -f `dirname $0`) +usage(){ + cat << EOF -ARTIFACT_PORT=${ARTIFACT_PORT:-9002} -TOMCAT_PORT=${TOMCAT_PORT:-8005} +usage: $0 [options] VERSION +Create a flys package + +OPTIONS: + -?, --help Show this message + -w The working directory to use. (do not use spaces in path) + Default: $DEFAULT_WD + -t Tag the current default branch as "VERSION" + -o, --oracle Release is for oracle. + VERSION must be in the format MAYOR.MINOR.PATCH +EOF +exit 0 +} +# --backend-db-url Url of database backend. Default: $BACKENDURL +# --backend-db-pass Backend db password. Default: $BACKENDPASS +# --backend-db-port Backend db port. Default: $BACKENDPORT +# --backend-db-user Backend db user. Default: $BACKENDUSER +# --backend-db-backend Backend db backend name. Default: $BACKENDBACK +# --seddb-url Sediment db url. Default: $SEDDBURL +# --seddb-port Sediment db port. Default: $SEDDBPORT +# --seddb-user Sediment db user. Default: $SEDDBUSER +# --seddb-pass Sediment db password. Default: $SEDDBPASS +# --seddb-back Sediment db backend. Default: $SEDDBBACK +TOMCAT_PORT=${TOMCAT_PORT:-8282} MAPSERVER_URL=${MAPSERVER_URL:-czech-republic.atlas.intevation.de} WIKI_URL=${WIKI_URL:-https://flys-intern.intevation.de/Flys-3.0} -echo "INFO: create server directories" -mkdir -p $DIRECTORY/server/bin/lib/own -mkdir $DIRECTORY/server/shapefiles -mkdir $DIRECTORY/client - -echo "INFO: checkout sources" -echo " ... checkout $ARTIFACTS_HG_REPO" - -rm -rf $ARTIFACTS_HG -hg clone $ARTIFACTS_HG_REPO $ARTIFACTS_HG -(cd $ARTIFACTS_HG && hg co $RELEASE) +# Seddb Configuration +SEDDBURL=${SEDDBURL:-czech-republic.atlas.intevation.de} +SEDDBPORT=${SEDDBPORT:-1521} +SEDDBBACK=${SEDDBBACK:-XE} +SEDDBUSER=${SEDDBUSER:-seddb} +SEDDBPASS=${SEDDBPASS:-seddbpass} -echo " ... checkout $HTTPCLIIENT_HG_REPO" -rm -rf $HTTPCLIENT_HG -hg clone $HTTPCLIIENT_HG_REPO $HTTPCLIENT_HG -(cd $HTTPCLIENT_HG && hg co $RELEASE) +# Backend configuration +BACKENDURL=${BACKENDURL:-czech-republic.atlas.intevation.de} +BACKENDPORT=${BACKENDPORT:-5432} +BACKENDBACK=${BACKENDBACK:-flys_2912} +BACKENDUSER=${BACKENDUSER:-flys_dami} +BACKENDPASS=${BACKENDPASS:-flys_dami} -echo " ... checkout $FLYS_HG_REPO" -rm -rf $FLYS_HG -hg clone $FLYS_HG_REPO $FLYS_HG -(cd $FLYS_HG && hg co $RELEASE) +OPTS=`getopt -o ?w:,t,o \ + -l help,oracle \ + -n $0 -- "$@"` -# adapt client configuration -echo "INFO: prepare configuration of web client" +if [ $? != 0 ] ; then usage; fi +eval set -- "$OPTS" +while true ; do + case "$1" in + "-?"|"--help") + usage;; + "--") + shift + break;; + "-w") + WORK_DIR=$2 + shift 2;; + "-o"|"--oracle") + BUILD_ORACLE="TRUE" + shift;; + "-t") + DO_TAG="TRUE" + shift;; + *) + echo "Unknown Option $1" + usage;; + esac +done +if [ $# != 1 ]; then + usage +fi + +VERSION=$1 +ARTIFACT_PORT=${ARTIFACT_PORT:-`echo 1$VERSION | sed 's/\.//g'`} + +if [ -z $WORK_DIR ]; then + WORK_DIR=$DEFAULT_WD +fi + +mkdir -p $WORK_DIR + +if [ ! -d $FLYS_SOURCE_DIR ]; then + mkdir -p $FLYS_SOURCE_DIR + echo "Cloning sources" + cd $FLYS_SOURCE_DIR + hg clone $ARTIFACTS_HG_REPO artifacts + hg clone $HTTPCLIIENT_HG_REPO http-client + hg clone $FLYS_HG_REPO flys +else + echo "Updating sources / Reverting changes" + cd $FLYS_SOURCE_DIR + for repo in $REPOS; do + cd $repo && hg pull && hg up && hg revert -a && cd $FLYS_SOURCE_DIR + done; +fi + +if [ "$DO_TAG" = "TRUE" ]; then + echo "Tagging version $VERSION" + for repo in $REPOS; do + cd $repo + CHANGESET=$(hg log -l1 |head -1 | awk -F: '{print $3}') + echo "" + echo "Do you really want to tag $repo rev: $CHANGESET as Version $VERSION?" + echo "press enter to continue or CTRL+C to abort." + echo "" + hg log -l1 + read + hg tag $VERSION -m "Added tag $VERSION for changeset $CHANGESET" + hg push ssh://$DEVELOPER@scm.wald.intevation.org/hg/dive4elements/$repo + cd $FLYS_SOURCE_DIR + done; +fi + +# Update to current version +for repo in $REPOS; do + cd $repo + hg up $VERSION + cd $FLYS_SOURCE_DIR +done + +rm -rf "$WORK_DIR/server" "$WORK_DIR/client" +cd $WORK_DIR +mkdir -p "$WORK_DIR/server/bin/lib/own" +mkdir "$WORK_DIR/server/shapefiles" +mkdir "$WORK_DIR/client" + +echo "[INFO]: Preparing configuration of web client" +echo "[INFO]: Tomcat Port: $TOMCAT_PORT" +echo "[INFO]: Artifact Port: $ARTIFACT_PORT" sed -i -e "s@http://localhost:8181@http://localhost:$ARTIFACT_PORT@g" \ -e "s@http://localhost:8888@http://localhost:$TOMCAT_PORT@g" \ - $FLYS_HG/flys-client/src/main/webapp/WEB-INF/web.xml + $FLYS_SOURCE_DIR/flys/flys-client/src/main/webapp/WEB-INF/web.xml -sed -i -e "s@/tmp/flys-client.log@/var/log/flys/client-${RELEASE}.log@g" \ - $FLYS_HG/flys-client/src/main/webapp/WEB-INF/log4j.properties +sed -i -e "s@/tmp/flys-client.log@/var/log/flys/client-${VERSION}.log@g" \ + $FLYS_SOURCE_DIR/flys/flys-client/src/main/webapp/WEB-INF/log4j.properties -# Fix the Wiki URLs -find $FLYS_HG/flys-artifacts/src/main/resources/ -name messages_\*.properties \ +find $FLYS_SOURCE_DIR/flys/flys-artifacts/src/main/resources/ -name messages_\*.properties \ -exec sed -i "s@https://flys-intern.intevation.de/Flys-3.0@${WIKI_URL}@g" {} \; -echo "INFO: download OpenLayers-2.11 for client" -curl -O http://openlayers.org/download/OpenLayers-2.11.tar.gz -tar xvfz OpenLayers-2.11.tar.gz -# TODO: Remove more superfluous OpenLayers stuff. -rm -rf OpenLayers-2.11/doc -rm -rf OpenLayers-2.11/tests -rm -rf OpenLayers-2.11/examples -mv OpenLayers-2.11 $FLYS_HG/flys-client/src/main/webapp/ +if [ ! -f $FLYS_SOURCE_DIR/OpenLayers-2.11.tar.gz ]; then + echo "INFO: download OpenLayers-2.11 for client" + cd $FLYS_SOURCE_DIR + curl -O http://openlayers.org/download/OpenLayers-2.11.tar.gz + tar xvfz OpenLayers-2.11.tar.gz + # TODO: Remove more superfluous OpenLayers stuff. + rm -rf OpenLayers-2.11/doc + rm -rf OpenLayers-2.11/tests + rm -rf OpenLayers-2.11/examples + cd $WORK_DIR +fi +cp -r $FLYS_SOURCE_DIR/OpenLayers-2.11 $FLYS_SOURCE_DIR/flys/flys-client/src/main/webapp/ -# compile and build our code stuff echo "INFO: compile and build sources" -mvn -f $ARTIFACTS_HG/pom.xml clean compile package install -mvn -f $FLYS_HG/flys-backend/pom.xml clean compile package install -mvn -f $FLYS_HG/flys-artifacts/pom.xml clean compile package dependency:copy-dependencies install -mvn -f $HTTPCLIENT_HG/pom.xml clean compile package install -mvn -f $FLYS_HG/flys-client/pom.xml clean compile package +mvn -f $FLYS_SOURCE_DIR/artifacts/pom.xml clean compile package install +mvn -f $FLYS_SOURCE_DIR/flys/flys-backend/pom.xml clean compile package install +mvn -f $FLYS_SOURCE_DIR/flys/flys-artifacts/pom.xml clean compile package dependency:copy-dependencies install +mvn -f $FLYS_SOURCE_DIR/http-client/pom.xml clean compile package install +mvn -f $FLYS_SOURCE_DIR/flys/flys-client/pom.xml clean compile package -## fetch the java stuff + echo "INFO: copy dependencies and libs" -cp $ARTIFACTS_HG/artifact-database/target/artifact-database-1.0-SNAPSHOT.jar $DIRECTORY/server/bin/lib/own/ -cp $ARTIFACTS_HG/artifacts/target/artifacts-1.0-SNAPSHOT.jar $DIRECTORY/server/bin/lib/own/ -cp $ARTIFACTS_HG/artifacts-common/target/artifacts-common-1.0-SNAPSHOT.jar $DIRECTORY/server/bin/lib/own/ -cp $FLYS_HG/flys-backend/target/flys-backend-1.0-SNAPSHOT.jar $DIRECTORY/server/bin/lib/own/ -cp $FLYS_HG/flys-artifacts/target/flys-artifacts-1.0-SNAPSHOT.jar $DIRECTORY/server/bin/lib/own/ -cp $FLYS_HG/flys-client/target/FLYS-1.0-SNAPSHOT.war $DIRECTORY/client/flys-${RELEASE}.war -cp $FLYS_HG/flys-artifacts/target/dependency/* $DIRECTORY/server/bin/lib/ +cp $FLYS_SOURCE_DIR/artifacts/artifact-database/target/artifact-database-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/ +cp $FLYS_SOURCE_DIR/artifacts/artifacts/target/artifacts-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/ +cp $FLYS_SOURCE_DIR/artifacts/artifacts-common/target/artifacts-common-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/ +cp $FLYS_SOURCE_DIR/flys/flys-backend/target/flys-backend-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/ +cp $FLYS_SOURCE_DIR/flys/flys-artifacts/target/flys-artifacts-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/ +cp $FLYS_SOURCE_DIR/flys/flys-client/target/FLYS-1.0-SNAPSHOT.war $WORK_DIR/client/flys-${VERSION}.war +cp $FLYS_SOURCE_DIR/flys/flys-artifacts/target/dependency/* $WORK_DIR/server/bin/lib/ echo "INFO: copy scripts and libraries to target destination" -cp bin/run.sh $DIRECTORY/server/bin/ -cp bin/wsplgen.exe $DIRECTORY/server/bin/ -cp libs/* $DIRECTORY/server/bin/lib/ +cp ${SCRIPT_DIR}/bin/run.sh $WORK_DIR/server/bin/ +cp ${SCRIPT_DIR}/bin/wsplgen.exe $WORK_DIR/server/bin/ +cp ${SCRIPT_DIR}/libs/* $WORK_DIR/server/bin/lib/ -#echo "INFO: remove PostgreSQL and PostGIS libraries" -#rm $DIRECTORY/server/bin/lib/postg* -#rm $DIRECTORY/server/bin/lib/hibernate-spatial-postgis* -echo "INFO: remove Oralce libraries" -rm -f $DIRECTORY/server/bin/lib/hibernate-spatial-oracle-1.1.jar -rm -f $DIRECTORY/server/bin/lib/ojdbc* +if [ "$BUILD_ORACLE" = "TRUE" ]; then + echo "INFO: remove PostgreSQL and PostGIS libraries" + rm $WORK_DIR/server/bin/lib/postg* + rm $WORK_DIR/server/bin/lib/hibernate-spatial-postgis* +else + echo "INFO: remove Oralce libraries" + rm -f $WORK_DIR/server/bin/lib/hibernate-spatial-oracle-1.1.jar + rm -f $WORK_DIR/server/bin/lib/ojdbc* +fi # fetch the configuration stuff echo "INFO: copy default configuration to target destination" -cp -R $FLYS_HG/flys-artifacts/doc/conf $DIRECTORY/server/ - -#cp confs/* $DIRECTORY/server/conf/ -mkdir -p $DIRECTORY/server/conf - -sed "s/8999/$ARTIFACT_PORT/g" \ - confs/rest-server.xml \ - > $DIRECTORY/server/conf/rest-server.xml - -sed -e "s@http://example.com/@http://${MAPSERVER_URL}/@g" \ - confs/floodmap.xml \ - > $DIRECTORY/server/conf/floodmap.xml +cp -R $FLYS_SOURCE_DIR/flys/flys-artifacts/doc/conf $WORK_DIR/server/ -sed -e "s@http://example.com/@http://${MAPSERVER_URL}/@g" \ - confs/rivermap.xml \ - > $DIRECTORY/server/conf/rivermap.xml - -sed "s@/tmp/flys-server-default.log@/var/log/flys/server-${RELEASE}.log@" \ - confs/log4j.properties \ - > $DIRECTORY/server/conf/log4j.properties +sed -i "s/8181/$ARTIFACT_PORT/g" \ + $WORK_DIR/server/conf/rest-server.xml -# TODO: Use templating here -cp confs/seddb-db.xml $DIRECTORY/server/conf/seddb-db.xml -cp confs/backend-db.xml $DIRECTORY/server/conf/backend-db.xml -cp confs/artifact-db.xml $DIRECTORY/server/conf/artifact-db.xml -cp confs/datacage-db.xml $DIRECTORY/server/conf/datacage-db.xml -cp confs/mapserver/fontset.txt $DIRECTORY/server/conf/mapserver/fontset.txt +sed -i -e "s@http://example.com/@http://${MAPSERVER_URL}/@g" \ + $WORK_DIR/server/conf/floodmap.xml -cp $ARTIFACTS_HG/artifact-database/doc/schema-h2.sql h2/artifacts-h2.sql -cp $FLYS_HG/flys-artifacts/doc/conf/datacage.sql h2/datacage.sql +sed -i -e "s@http://example.com/@http://${MAPSERVER_URL}/@g" \ + $WORK_DIR/server/conf/rivermap.xml + +sed "s@/tmp/flys-server-default.log@/var/log/flys/server-${VERSION}.log@" \ + $SCRIPT_DIR/confs/log4j.properties \ + > $WORK_DIR/server/conf/log4j.properties + +cat > $WORK_DIR/server/conf/seddb-db.xml << EOF +<?xml version="1.0" encoding="UTF-8" ?> +<seddb-database> + <!-- This is the default SedDB db configuration. --> + <user>$SEDDBUSER</user> + <password>$SEDDBPASS</password> + <dialect>org.hibernate.dialect.Oracle9iDialect</dialect> + <driver>oracle.jdbc.driver.OracleDriver</driver> + <url>jdbc:oracle:thin:@//$SEDDBURL:$SEDDBPORT/$SEDDBBACK </url> +</seddb-database> +EOF + +if [ "$BUILD_ORACLE" = "TRUE" ]; then + # Oracle backend configuration + cat > $WORK_DIR/server/conf/backend-db.xml << EOF +<?xml version="1.0" encoding="UTF-8" ?> +<backend-database> + <user>flys27</user> + <password>flys27</password> + <dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</dialect> + <driver>oracle.jdbc.driver.OracleDriver</driver> + <url>jdbc:oracle:thin:@//czech-republic.atlas.intevation.de:1521/XE</url> +</backend-database> +EOF +else + #Postgresql backend configuration + cat > $WORK_DIR/server/conf/backend-db.xml << EOF +<?xml version="1.0" encoding="UTF-8" ?> +<backend-database> + <user>$BACKENDUSER</user> + <password>$BACKENDPASS</password> + <dialect>org.hibernate.dialect.PostgreSQLDialect</dialect> + <driver>org.postgresql.Driver</driver> + <url>jdbc:postgresql://$BACKENDURL:$BACKENDPORT/$BACKENDBACK</url> +</backend-database> +EOF +fi + +mkdir $WORK_DIR/artifactsdb +mkdir $WORK_DIR/datacagedb + +cp $FLYS_SOURCE_DIR/artifacts/artifact-database/doc/schema-h2.sql $WORK_DIR/artifactsdb/artifacts-h2.sql +cp $FLYS_SOURCE_DIR/flys/flys-artifacts/doc/conf/datacage.sql $WORK_DIR/datacagedb/datacage.sql echo "INFO: create h2 database for artifacts and datacage" -h2/createArtifacts.sh -h2/createDatacage.sh +$SCRIPT_DIR/h2/createArtifacts.sh $WORK_DIR/artifactsdb/artifacts-h2.sql +$SCRIPT_DIR/h2/createDatacage.sh $WORK_DIR/datacagedb/datacage.sql -mv artifactsdb $DIRECTORY/server/ -mv datacagedb $DIRECTORY/server/ +mv $WORK_DIR/artifactsdb $WORK_DIR/server/ +mv $WORK_DIR/datacagedb $WORK_DIR/server/ echo "INFO: create tarball" -tar cvfz $DIRECTORY.tar.gz $DIRECTORY +mkdir $WORK_DIR/flys-$VERSION +mv $WORK_DIR/server $WORK_DIR/client $WORK_DIR/flys-$VERSION +cd $WORK_DIR +tar cfz flys-$VERSION.tar.gz flys-$VERSION +echo "INFO: cleanup" +#rm -r $WORK_DIR/flys-$VERSION -echo "INFO: remove temporary files and directories" -rm -rf $ARTIFACTS_HG -rm -rf $HTTPCLIENT_HG -rm -rf $FLYS_HG -rm -rf $DIRECTORY -rm -rf OpenLayers.2.11.tar.gz +echo "DONE: $WORK_DIR/flys-$VERSION.tar.gz"