Skip to content

Instantly share code, notes, and snippets.

@edouard-lopez
Created August 21, 2013 08:06
Show Gist options
  • Save edouard-lopez/6291606 to your computer and use it in GitHub Desktop.
Save edouard-lopez/6291606 to your computer and use it in GitHub Desktop.
Fail: deployment post-update hook
#!/bin/bash
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
#exec git update-server-info
function deploy() {
branch="${1:-master}"
deployDir="${2:-unknown}"
deployRoot="${3:-/srv}"
deployFile="deploy."$prefixDir".tar.gz"
# create the archive with HEAD
sg - www-data -c 'git archive '"$branch"' --format=tar.gz --prefix='"$deployDir"'/ HEAD -o '"$deployRoot/$deployFile"
# deploy to vhost
cd "$deployRoot" && sg - www-data -c 'tar -xzf '"$deployFile"
sg www-data -c 'rm '"$deployRoot/$deployFile"
}
deploy master "site"
deploy master "demo.site"
deploy dev "dev.site"
@edouard-lopez
Copy link
Author

Try this instead

function deploy() {
        branch="${1:-master}"
        deployDir="${2:-unknown}"
        deployRoot="${3:-/srv}"
        deployFile="deploy."$deployDir".tar.gz"

        printf "[i] Deploying: %s/%s\n" "$deployDir" "$branch"
        # create the archive and deploy
        sg - www-data -c 'git archive '"$branch"' --format=tar.gz --prefix='"$deployDir"'/ -o '"$deployRoot/$deployFile"

        cd "$deployRoot"
        # remove existing directory
        sg www-data -c 'rm -rf '"$deployDir"
        # extract archive 
        sg www-data -c 'tar -xzf '"$deployRoot/$deployFile"
        # remove archive
        sg www-data -c 'rm '"$deployRoot/$deployFile"
        # update timestamps
        touch "$deployDir"
        cd -
}

#deploy master  "probe"
deploy master   "demo.probe-meteo"
deploy dev      "dev.probe-meteo"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment