Created
May 25, 2015 22:44
-
-
Save lorello/37f247e2fb75534f5dd4 to your computer and use it in GitHub Desktop.
GIT-Push Deploy scripts
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
| #!/usr/bin/env bash | |
| set -e | |
| OLDREV=$1 | |
| NEWREV=$2 | |
| run() { | |
| [ -x $1 ] && $1 $OLDREV $NEWREV | |
| } | |
| echo -e "\n==> Push received\n" | |
| echo files changed: $(git diff $OLDREV $NEWREV --diff-filter=ACDMR --name-only | wc -l) | |
| #umask 0002 | |
| if [ -f .gitmodules ]; then | |
| echo "Updading submodules, if needed" | |
| git submodule sync && git submodule update --init --recursive | |
| fi | |
| [ -f deploy/before_restart ] && run deploy/before_restart $OLDREV $NEWREV | |
| [ -f deploy/restart ] && run deploy/restart $OLDREV $NEWREV && [ -f deploy/after_restart ] && run deploy/after_restart $OLDREV $NEWREV |
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/sh | |
| # Post on Slack push results! | |
| curl -X POST --data-urlencode 'payload={"channel": "#MAGICAPP", "username": "webhookbot", "text": "Deployed a new version of My Magic APP.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/T03FE2F39/A9DH5NFH3/FJ03KNLAKNF209U013FN3V |
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
| #!/usr/bin/env bash | |
| set -e | |
| OLDREV=$1 | |
| NEWREV=$2 | |
| PUPPETFILE='setup/Puppetfile' | |
| PUPPET_MANIFEST='setup/manifests/default.pp' | |
| PUPPET_MODULES='setup/modules' | |
| NODE_PACKAGES='frontend/package.json' | |
| NODE_MODULES='frontend/node_modules' | |
| BOWER_PACKAGES='frontend/bower.json' | |
| BOWER_COMPONENTS='frontend/bower_components' | |
| GRUNT_TASKS='frontend/Gruntfile.js' | |
| APP_TIER=test # TODO: how to retrieve branch name? | |
| if [ -z "$OLDREV" ] || [ -z $NEWREV ]; then | |
| echo "ERROR: missing parameters <OLDREV> <NEWREV>" | |
| exit 1 | |
| fi | |
| ## | |
| # Check if a file or a shell patter has changes in the last commit | |
| # | |
| # returns 0 if true | |
| # returns 1 otherwise | |
| # | |
| function has_changes() { | |
| ITEM=$1 | |
| [ -z "$ITEM" ] && echo "ERROR: has_changes: missing argument" && return 1 | |
| CHANGES_NUM=$(git diff $OLDREV $NEWREV --diff-filter=AM --name-only $ITEM | wc -l) | |
| if [ $CHANGES_NUM -gt 0 ]; then | |
| # echo "has_changes: '$ITEM' has $CHANGES_NUM changes" | |
| return 0 | |
| fi | |
| return 1 | |
| } | |
| PUPPET_MODULES_UPDATED=false | |
| if [ -f $PUPPETFILE ]; then | |
| if [ ! -d $PUPPET_MODULES ] || has_changes $PUPPETFILE; then | |
| echo "--- Updating puppet dependencies with R10K ---------------" | |
| cd `dirname $PUPPETFILE` && r10k puppetfile install && cd - | |
| PUPPET_MODULES_UPDATED=true | |
| echo -e "\n" | |
| fi | |
| fi | |
| if [ -f $PUPPET_MANIFEST ]; then | |
| if [ "PUPPET_MODULES_UPDATED" -eq "true" ] || has_changes $PUPPET_MANIFEST; then | |
| echo "--- Running Puppet ---------------------------------------------------" | |
| /usr/local/bin/puppet-run | |
| echo -e "\n" | |
| fi | |
| fi | |
| if [ -f $NODE_PACKAGES ]; then | |
| if [ ! -d $NODE_MODULES ] || has_changes $NODE_PACKAGES; then | |
| echo "--- Installing dependencies with NPM ---------------------------------" | |
| cd `dirname $NODE_PACKAGES` && npm install && cd - | |
| echo -e "\n" | |
| fi | |
| fi | |
| if [ -f $BOWER_PACKAGES ]; then | |
| if [ ! -d $BOWER_COMPONENTS ] || has_changes $BOWER_PACKAGES; then | |
| echo "--- Generating static assets with Bower ------------------------------" | |
| cd `dirname $BOWER_PACKAGES` && bower install && cd - | |
| echo -e "\n" | |
| fi | |
| fi | |
| if [ -f $GRUNT_TASKS ]; then | |
| echo "--- Grunting project ------------------------------------------------" | |
| cd `dirname $GRUNT_TASKS` && grunt build:$APP_TIER && cd - | |
| fi | |
| # clear cached assets (unversioned/ignored files) | |
| # run "git clean -x -f -- public/stylesheets public/javascripts" | |
| # clean unversioned files from vendor/plugins (e.g. old submodules) | |
| # run "git clean -d -f -- vendor/plugins" |
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/sh | |
| echo "I'm stupid HTML site, Nothing to restart!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment