User Tools

Site Tools


jenkins

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
jenkins [2014/09/12 15:21]
admin created
jenkins [2015/01/03 21:15] (current)
admin
Line 2: Line 2:
  
 <code bash> <code bash>
-#### 
-### production.config.sh 
-#### 
  
-####################### project depending config values ####################### +############### 
- +## Config BEGIN 
 +###############  
 ## ##
 # Server name or IP address where the code should be deployed # Server name or IP address where the code should be deployed
Line 13: Line 12:
 # Use public-key authentication! # Use public-key authentication!
 ## ##
-SERVER='188.40.71.216+SERVER='knallimall.org
 + 
 ## ##
 # User name for server # User name for server
Line 21: Line 20:
 ## ##
 USER='root' USER='root'
 + 
 ## ##
 # Remote directory where the code should be deployed # Remote directory where the code should be deployed
Line 27: Line 26:
 # Use public-key authentication! # Use public-key authentication!
 ## ##
-REMOTE_DESTINATION='/var/www/magento.tagwork-one.de+REMOTE_DESTINATION='/var/www/magento-live.knallimall.org/web
 + 
 ## ##
 # List of files and directories with relative paths to the git repository root which should # List of files and directories with relative paths to the git repository root which should
Line 47: Line 46:
   'production.config.inc.php config.inc.php'   'production.config.inc.php config.inc.php'
 ) )
 + 
 ## ##
 # List shell commands which should be executed afterwards # List shell commands which should be executed afterwards
Line 56: Line 55:
   "find ${REMOTE_DESTINATION}/. -iname \*.sh -print0 | xargs -0 chmod +x {} 2>/dev/null"   "find ${REMOTE_DESTINATION}/. -iname \*.sh -print0 | xargs -0 chmod +x {} 2>/dev/null"
 ) )
- 
-############################ general config values ############################ 
  
 ## ##
Line 63: Line 60:
 ## ##
 SHOW_MODIFIED=true SHOW_MODIFIED=true
 + 
 ## ##
 # Git hash file # Git hash file
Line 69: Line 66:
 HASH_FILE='t1_git_deployment_id' HASH_FILE='t1_git_deployment_id'
  
-## +##################################################### 
-Remote lock file +## Config END - NO NEED TO CHANGE ANYTHING BELOW HERE 
-## +##################################################### 
-LOCK_FILE='t1_git_deployment.lock' + 
- +
-### +
- THE MAGIC HAPPENS HERE ...  +
-### +
 echo -n "Store head commit hash to file in local git clone ... " echo -n "Store head commit hash to file in local git clone ... "
 CURRENT_HASH=`git log --format="%H" | head -n1` CURRENT_HASH=`git log --format="%H" | head -n1`
 echo ${CURRENT_HASH} > ${HASH_FILE} echo ${CURRENT_HASH} > ${HASH_FILE}
 + 
 echo -n "Getting remote commit hash ... " echo -n "Getting remote commit hash ... "
 REMOTE_HASH=`scp -q ${USER}@${SERVER}:${REMOTE_DESTINATION}/${HASH_FILE} /dev/stdout 2> /dev/null` REMOTE_HASH=`scp -q ${USER}@${SERVER}:${REMOTE_DESTINATION}/${HASH_FILE} /dev/stdout 2> /dev/null`
 +
 +
 +#######################
 +# Prepare file listings
 +#######################
  
 if test -z ${REMOTE_HASH}; then if test -z ${REMOTE_HASH}; then
     echo -n "Remote hash is empty, getting initial commit hash ... "     echo -n "Remote hash is empty, getting initial commit hash ... "
     INITIAL_HASH=`git log --format="%H" | tail -n1`     INITIAL_HASH=`git log --format="%H" | tail -n1`
 + 
     if [ "${SHOW_MODIFIED}" == true ]; then     if [ "${SHOW_MODIFIED}" == true ]; then
         echo -n "Getting list of files for initial commit ... "         echo -n "Getting list of files for initial commit ... "
Line 102: Line 99:
         exit 0         exit 0
     fi     fi
 + 
     echo -n "Getting files to delete from server ... "     echo -n "Getting files to delete from server ... "
     while IFS= read -r -d $'\0' file; do     while IFS= read -r -d $'\0' file; do
Line 114: Line 111:
     fi     fi
 fi fi
 +
 +##############################################################
 +# Housekeeping - delete/move files declared in RM_LIST/MV_LIST
 +##############################################################
  
 echo -n "Removing unnecessary files from local git clone ... " echo -n "Removing unnecessary files from local git clone ... "
Line 120: Line 121:
 done done
  
-#echo -n "Renaming files in local git clone ... " +if [[ -z "${MV_LIST-unset}" ]] 
-#for index in ${!MV_LIST[*]} ; do + echo -n "Renaming files in local git clone ... " 
-   mv ${MV_LIST[$index]} + for index in ${!MV_LIST[*]} ; do 
-#done +    mv ${MV_LIST[$index]} 
 + done 
 +fi 
 + 
 echo -n "Removing git specific files from local git clone ... " echo -n "Removing git specific files from local git clone ... "
 find . -name ".git*" -exec rm -fR {} \+ find . -name ".git*" -exec rm -fR {} \+
-echo "done"+ 
 +################################# 
 +# Check remote just before upload 
 +#################################
  
 echo -n "Check if deployment directory exists on server ... " echo -n "Check if deployment directory exists on server ... "
 if ssh ${USER}@${SERVER} "test -d ${REMOTE_DESTINATION}"; then if ssh ${USER}@${SERVER} "test -d ${REMOTE_DESTINATION}"; then
-    echo "done" 
     echo -n "Check if deployment directory is writeable on server ... "     echo -n "Check if deployment directory is writeable on server ... "
     if ssh ${USER}@${SERVER} "test -w ${REMOTE_DESTINATION}"; then     if ssh ${USER}@${SERVER} "test -w ${REMOTE_DESTINATION}"; then
         echo "done"         echo "done"
-        echo -n "Check if deployment is currently active on server ... " 
-        if ssh ${USER}@${SERVER} "test -f ${REMOTE_DESTINATION}/${LOCK_FILE}"; then 
-            echo "failed" 
-            echo "Deployment in ${REMOTE_DESTINATION} on server ${SERVER} possibly in process - exiting!" 
-            rm -fR ${WORKSPACE} 
-            exit 1 
-        else 
-            echo "done" 
-            ssh ${USER}@${SERVER} "touch ${REMOTE_DESTINATION}/${LOCK_FILE}" 
-        fi 
     else     else
         echo "failed"         echo "failed"
Line 152: Line 147:
     fi     fi
 else else
-    echo "done" 
     echo -n "Creating deployment directory on server ... "     echo -n "Creating deployment directory on server ... "
     ssh ${USER}@${SERVER} "mkdir -p ${REMOTE_DESTINATION}"     ssh ${USER}@${SERVER} "mkdir -p ${REMOTE_DESTINATION}"
Line 164: Line 158:
     fi     fi
 fi fi
 + 
 echo -n "Copy files to server ... " echo -n "Copy files to server ... "
-rsync --checksum --links --compress --recursive ${WORKSPACE}/ ${USER}@${SERVER}:${REMOTE_DESTINATION}/+rsync --checksum --links --compress --recursive -v ${WORKSPACE}/ ${USER}@${SERVER}:${REMOTE_DESTINATION}/
 echo "done" echo "done"
  
 +
 +###################################################
 +# Comparing hashes
 +# [if] Initial Upload
 +# [else] Delete files on remote according to git 
 +###################################################
 + 
 if test -z "${REMOTE_HASH}"; then if test -z "${REMOTE_HASH}"; then
     if [ "${SHOW_MODIFIED}" == true ]; then     if [ "${SHOW_MODIFIED}" == true ]; then
Line 182: Line 183:
     done     done
     echo "done"     echo "done"
 + 
     if [ "${SHOW_MODIFIED}" == true ]; then     if [ "${SHOW_MODIFIED}" == true ]; then
         echo "List modified files between ${REMOTE_HASH} and ${CURRENT_HASH}:"         echo "List modified files between ${REMOTE_HASH} and ${CURRENT_HASH}:"
Line 196: Line 197:
     fi     fi
 fi fi
 +
 +#######################################
 +# Some housekeeping on local and remote
 +#######################################
  
 echo -n "Running commands on server ... " echo -n "Running commands on server ... "
 for COMMAND in "${COMMAND_LIST[@]}"; do for COMMAND in "${COMMAND_LIST[@]}"; do
-        ssh ${USER}@${SERVER} ${COMMAND}+        ssh ${USER}@${SERVER} '${COMMAND}'
 done done
 + 
 echo -n "Remove local temporary directory ... " echo -n "Remove local temporary directory ... "
 rm -fR ${WORKSPACE} rm -fR ${WORKSPACE}
- + 
-echo -n "Remove lock file on server ... " +
-ssh ${USER}@${SERVER} "rm -f ${REMOTE_DESTINATION}/${LOCK_FILE}" +
 echo 'Danke DZI - und tschüss!' echo 'Danke DZI - und tschüss!'
- 
 </code> </code>
  
jenkins.1410528064.txt.gz · Last modified: 2014/09/12 15:21 by admin