Skip to content

Instantly share code, notes, and snippets.

@philipborbon
Last active January 22, 2023 09:08

Revisions

  1. philipborbon renamed this gist Jan 22, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. philipborbon revised this gist Jun 3, 2022. No changes.
  3. philipborbon created this gist Jun 3, 2022.
    22 changes: 22 additions & 0 deletions post-receive
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/bash
    TARGET="/home/user/project"
    GIT_DIR="/home/user/project.git"
    BRANCH="master"

    while read oldrev newrev ref
    do
    # only checking out the master (or whatever branch you would like to deploy)
    if [ "$ref" = "refs/heads/$BRANCH" ];
    then
    echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
    git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
    # chmod +x $TARGET/reload.sh
    php /usr/local/bin/composer install --optimize-autoloader --no-dev --working-dir=$TARGET
    php $TARGET/artisan config:cache
    php $TARGET/artisan route:cache
    php $TARGET/artisan view:cache
    php $TARGET/artisan queue:restart
    else
    echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
    fi
    done