Skip to content

Instantly share code, notes, and snippets.

@cupnoodle
Last active February 9, 2017 05:19
Show Gist options
  • Select an option

  • Save cupnoodle/0faef2c737ebb7eb988e2a56b4fe1bad to your computer and use it in GitHub Desktop.

Select an option

Save cupnoodle/0faef2c737ebb7eb988e2a56b4fe1bad to your computer and use it in GitHub Desktop.

Revisions

  1. cupnoodle revised this gist Aug 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion post-receive
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ do
    echo "work tree is located at"
    echo $WORK_TREE

    bundle install
    bundle install --deployment
    rake db:create RAILS_ENV=production
    rake db:migrate RAILS_ENV=production
    rake assets:precompile RAILS_ENV=production
  2. cupnoodle created this gist Aug 7, 2016.
    34 changes: 34 additions & 0 deletions post-receive
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/bin/bash -l

    #The -l parameter executes the command in a login shell

    GIT_DIR=/home/rails/repo/fox_sample.git
    WORK_TREE=/home/rails/fox_sample


    while read oldrev newrev ref
    do
    if [[ $ref =~ .*/master$ ]];
    then
    echo "Master ref received. Deploying master branch to production"
    git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f

    # start deploy tasks
    cd $WORK_TREE
    echo "work tree is located at"
    echo $WORK_TREE

    bundle install
    rake db:create RAILS_ENV=production
    rake db:migrate RAILS_ENV=production
    rake assets:precompile RAILS_ENV=production
    sudo service unicorn restart
    sudo service nginx restart

    # end deploy tasks

    echo "Git post-receive deploy complete"
    else
    echo "Ref $ref received successfully. No action performed: only the master branch can be deployed on this server."
    fi
    done