Last active
February 20, 2018 21:52
-
-
Save mgoellnitz/1661e0b649ea698d7dab17cacd2c3167 to your computer and use it in GitHub Desktop.
Deploy DXP archive as single node environment from e.g. cron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Deploy provided chef-solo archive if available and delete it | |
# | |
# $1 - workspace directory - default ~/coremedia9 | |
# $2 - node descriptor - default cms-9-single | |
# | |
# Copyright (c) 2017-2018, Martin Goellnitz | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without modification, | |
# are permitted provided that the following conditions are met: | |
# | |
# 1. Redistributions of source code must retain the above copyright notice, | |
# this list of conditions and the following disclaimer. | |
# | |
# 2. Redistributions in binary form must reproduce the above copyright notice, | |
# this list of conditions and the following disclaimer in the documentation | |
# and/or other materials provided with the distribution. | |
# | |
# 3. Neither the name of the copyright holder nor the names of its contributors | |
# may be used to endorse or promote products derived from this software | |
# without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# | |
DIR=${1:-~/coremedia9} | |
NODE=${2:-cms-9-single} | |
INSTALL=${3:-/opt/install} | |
LOG=/var/log/cms-deploy.log | |
if [ ! -w $LOG ] ; then | |
LOG=/tmp/cms-deploy.log | |
fi | |
BUILDLOG=/var/log/cms-build.log | |
if [ ! -f $BUILDLOG ] ; then | |
BUILDLOG=/tmp/cms-build.log | |
fi | |
source /etc/profile | |
BUILDING=`grep 'Build done' $BUILDLOG` | |
if [ -z "$BUILDING" ] ; then | |
echo "Build in progress" >> $LOG | |
exit | |
fi | |
if [ -f $DIR/deployment/chef/target/deployment-archive.zip ] ; then | |
echo -n "Starting deployment. " > $LOG | |
date >> $LOG | |
if [ ! -d $INSTALL ] ; then | |
mkdir -p $INSTALL | |
fi | |
cd $INSTALL | |
rm -rf * | |
unzip -q $DIR/deployment/chef/target/deployment-archive.zip >> $LOG | |
rm -f $DIR/deployment/chef/target/deployment-archive.zip | |
# Handle maven-repo folder from the CoreMedia deploy script | |
# only if a local repository is used. Otherwise remove any local copy | |
# extracted from the archive - just to be sure. | |
LOCAL=$(cat chef-repo/nodes/$NODE.json |grep maven_repository_url|grep file) | |
if [ ! -z "$LOCAL" ] ; then | |
echo "Using machine local repository" >> $LOG | |
test -d /tmp/maven-repo || ln -s $INSTALL/maven-repo /tmp/maven-repo | |
else | |
rm -rf maven-repo | |
fi | |
test -f /tmp/content-users.zip || ln -s $INSTALL/content-users.zip /tmp/content-users.zip | |
service solr stop | |
# Convenience: remove old logs | |
rm /var/log/coremedia/*/*log*.txt | |
rm /var/log/coremedia/*/*.log | |
rm /var/log/coremedia/*/*.log.* | |
rm /var/log/coremedia/*/*.out | |
CMS_RELEASE=1-SNAPSHOT | |
if [ -d $INSTALL/maven-repo ] ; then | |
CMS_RELEASE=$(cd $INSTALL/maven-repo ; ls com/coremedia/blueprint/cae-live-webapp) | |
fi | |
# sed -i -e s/ENTER\ CONCRETE\ VERSION\ HERE/$CMS_RELEASE/g $INSTALL/chef-repo/cookbooks/blueprint/recipes/_staging.rb | |
# sed -i -e s/ENTER\ CONCRETE\ VERSION\ HERE/$CMS_RELEASE/g $INSTALL/chef-repo/cookbooks/blueprint/recipes/_production.rb | |
# chef-solo --config $INSTALL/chef-repo/.chef/solo.rb --environment staging --json-attributes $INSTALL/chef-repo/nodes/$NODE.json >> $LOG | |
sed -i -e s/LATEST/$CMS_RELEASE/g $INSTALL/chef-repo/cookbooks/blueprint/recipes/_development.rb | |
chef-solo --config $INSTALL/chef-repo/.chef/solo.rb --environment development --json-attributes $INSTALL/chef-repo/nodes/$NODE.json >> $LOG | |
echo -n "Deployment done. " >> $LOG | |
date >> $LOG | |
if [ ! -z "$LOCAL" ] ; then | |
rm -f /tmp/maven-repo /tmp/content-users.zip | |
fi | |
rm -f /tmp/content-users.zip | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment