Skip to content

Instantly share code, notes, and snippets.

@1mike12
Last active March 8, 2023 18:08
Show Gist options
  • Select an option

  • Save 1mike12/1dc54ded1a399fbd150e5ecc151ea528 to your computer and use it in GitHub Desktop.

Select an option

Save 1mike12/1dc54ded1a399fbd150e5ecc151ea528 to your computer and use it in GitHub Desktop.

Revisions

  1. 1mike12 revised this gist Feb 10, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion post-receive.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/bash
    TRAGET="/var/www/project"
    SERVER="/var/www/project/server"
    CLIENT="/var/www/project/react"
    CLIENT="/var/www/project/reactcode"
    GIT_DIR="/var/repos/project.git"
    BRANCH="master"

    @@ -12,9 +12,13 @@ do
    then
    echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
    git --work-tree=$TRAGET --git-dir=$GIT_DIR checkout -f
    echo "installing react modules"
    cd $CLIENT
    npm install
    echo "building client"
    npm run build
    cd $SERVER
    echo "installing server modules"
    npm install
    echo "Running knex migration"
    npx knex migrate:latest
  2. 1mike12 revised this gist Feb 10, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions how to post-receive.md
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    2. `cd project.git && git init --bare`
    3. `cd project.git/hooks && touch post-receive`
    4. copy paste post-receive script
    5. make executable `chmod +x post-receive`

    ### local
    `git remote add production [email protected]:/var/www/project.git`
  3. 1mike12 revised this gist Feb 10, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion how to post-receive.md
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,6 @@
    4. copy paste post-receive script

    ### local
    `git remote add production [email protected]:/var/www/project.git`
    `git remote add production [email protected]:/var/www/project.git`

    `git push production`
  4. 1mike12 revised this gist Feb 10, 2019. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions how to post-receive.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    ### server
    1. make a project/ directory and project.git/ directory
    2. cd project.git && git init --bare
    3. go into project.git/hooks and create post-receive
    1. make a `project/` directory and `project.git/` directory
    2. `cd project.git && git init --bare`
    3. `cd project.git/hooks && touch post-receive`
    4. copy paste post-receive script

    ### local
    git remote add production [email protected]:/var/www/project.git
    git push production
    `git remote add production [email protected]:/var/www/project.git`
    `git push production`
  5. 1mike12 revised this gist Feb 10, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions how to post-receive.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ### server
    1. make a project and project.git folder and project/ folder
    2. git init --bare in project.git
    1. make a project/ directory and project.git/ directory
    2. cd project.git && git init --bare
    3. go into project.git/hooks and create post-receive

    ### local
  6. 1mike12 revised this gist Feb 10, 2019. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions post-receive.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #!/bin/bash
    TRAGET="/var/www/tickers"
    SERVER="/var/www/tickers/server"
    CLIENT="/var/www/tickers/react"
    GIT_DIR="/var/www/tickers.git"
    TRAGET="/var/www/project"
    SERVER="/var/www/project/server"
    CLIENT="/var/www/project/react"
    GIT_DIR="/var/repos/project.git"
    BRANCH="master"

    while read oldrev newrev ref
    @@ -12,8 +12,10 @@ do
    then
    echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
    git --work-tree=$TRAGET --git-dir=$GIT_DIR checkout -f
    cd $CLIENT
    npm install
    cd $SERVER
    yarn install
    npm install
    echo "Running knex migration"
    npx knex migrate:latest
    echo "restarting PM2"
  7. 1mike12 renamed this gist Oct 3, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. 1mike12 revised this gist Aug 23, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions howto.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    ### server
    make a project and project.git folder and project/ folder
    git init --bare in project.git
    go into project.git/hooks and create post-receive
    1. make a project and project.git folder and project/ folder
    2. git init --bare in project.git
    3. go into project.git/hooks and create post-receive

    ### local
    git remote add production [email protected]:/var/www/project.git
  9. 1mike12 revised this gist Aug 23, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion howto.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ### server
    make a project and project.git folder
    make a project and project.git folder and project/ folder
    git init --bare in project.git
    go into project.git/hooks and create post-receive

  10. 1mike12 revised this gist Jul 28, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions howto.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    ### server
    make a project and project.git folder
    git init --bare in project.git
    go into project.git/hooks and create post-receive

    ### local
    git remote add production [email protected]:/var/www/project.git
    git push production
  11. 1mike12 created this gist Jul 28, 2018.
    25 changes: 25 additions & 0 deletions post-receive.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash
    TRAGET="/var/www/tickers"
    SERVER="/var/www/tickers/server"
    CLIENT="/var/www/tickers/react"
    GIT_DIR="/var/www/tickers.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=$TRAGET --git-dir=$GIT_DIR checkout -f
    cd $SERVER
    yarn install
    echo "Running knex migration"
    npx knex migrate:latest
    echo "restarting PM2"
    pm2 restart server

    else
    echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
    fi
    done