miholeus

dpl

Feb 22nd, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.37 KB | None | 0 0
  1. #!/bin/bash
  2. # Shell script to deploy site on server
  3. # Copy files from git repository and update site
  4. # It also applies database migrations based on zend framework tool
  5. # Last updated: Feb - 2012
  6. # @author miholeus
  7. # --------------------------------------------------------------------
  8.  
  9. # -------------------------------------------------------
  10. # General settings
  11. # -------------------------------------------------------
  12.  
  13. # General folder to create project's archives
  14. # DO NOT USE SLASH AT THE END!!
  15. ARCHIVE_DIR=/tmp/project
  16. # git arhive with project's sources
  17. # DO NOT USE SLASH AT THE END!!
  18. PROJECT_GIT_DIR=/var/git/project.git
  19. # project's current directory
  20. # DO NOT USE SLASH AT THE END!!
  21. PROJECT_DIR=/home/project/htdocs
  22.  
  23. # -------------------------------------------------------
  24. # These settings may be left as is
  25. # -------------------------------------------------------
  26.  
  27. # folder that will be created after unpacking an archive
  28. DESTINATION_FOLDER=$ARCHIVE_DIR/release_`date +"%Y_%m_%d_%H_%M_%S"`
  29. ZF_BIN=/usr/bin/zf
  30. NODE_BIN=/usr/local/bin/node
  31. # database migration command
  32.  
  33. # default branch name to deploy
  34. BRANCH=master
  35. APP_ENV=production
  36.  
  37. while getopts ":s:d:g:e:" optname
  38.   do
  39.     case "$optname" in
  40.       "s")
  41.         BRANCH="$OPTARG"
  42.         ;;
  43.       "d")
  44.         PROJECT_DIR=$OPTARG
  45.         ;;
  46.       "g")
  47.         PROJECT_GIT_DIR=$OPTARG
  48.         ;;
  49.       "e")
  50.         APP_ENV=$OPTARG
  51.         ;;
  52.     esac
  53.   done
  54.  
  55. MIGRATE_COMMAND="$ZF_BIN update database-schema $APP_ENV"
  56. BUILD_COMMAND="$NODE_BIN ./bin/tools/build.js deploy"
  57.  
  58. # rsync command, you may change it on your own
  59. SYNC_COMMAND="rsync -uthrO --delete $DESTINATION_FOLDER/ $PROJECT_DIR --exclude public/upload --exclude .gitignore --exclude data --exclude logs --exclude var --exclude public/phpmy"
  60.  
  61. #SYNC_COMMAND="cp -f -r -p $DESTINATION_FOLDER/* $PROJECT_DIR"
  62.  
  63. if [ ! -d "$PROJECT_DIR" ]; then
  64.   echo "::=> Project's directory doesn't exist :: $PROJECT_DIR"
  65.   exit 1
  66. fi
  67.  
  68. mkdir -p $DESTINATION_FOLDER
  69.  
  70. if [ ! -d "$DESTINATION_FOLDER" ]; then
  71.   echo "::=> Directory can't be created :: $DESTINATION_FOLDER"
  72.   exit 1
  73. fi
  74.  
  75. git archive --remote $PROJECT_GIT_DIR  $BRANCH | tar -x -C $DESTINATION_FOLDER
  76.  
  77. echo "Updating site..."
  78. $SYNC_COMMAND
  79.  
  80. cd $PROJECT_DIR
  81. echo "Applying migrations..."
  82. $MIGRATE_COMMAND
  83.  
  84. cd $PROJECT_DIR
  85. echo "Building js & css..."
  86. $BUILD_COMMAND
  87.  
  88. echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment