Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schmaluk/0c4b11d19430ad1f1a8247d0f5b8349d to your computer and use it in GitHub Desktop.
Save schmaluk/0c4b11d19430ad1f1a8247d0f5b8349d to your computer and use it in GitHub Desktop.

Revisions

  1. Thomas Fritz revised this gist Apr 11, 2017. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions post-receive
    Original file line number Diff line number Diff line change
    @@ -66,6 +66,11 @@ do
    export DEPLOY_NEWREV="$newrev"
    export DEPLOY_REFNAME="$refname"

    if [ "$DEPLOY_NEWREV" = "0000000000000000000000000000000000000000" ]; then
    echo "githook: This ref has been deleted"
    exit 1
    fi

    if [ ! -z "${DEPLOY_ALLOWED_BRANCH}" ]; then
    if [ "${DEPLOY_ALLOWED_BRANCH}" != "$DEPLOY_BRANCH" ]; then
    echo "githook: Branch '$DEPLOY_BRANCH' of '${DEPLOY_APP_NAME}' application will not be deployed. Exiting."
  2. Thomas Fritz revised this gist Apr 11, 2017. 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
    @@ -5,7 +5,7 @@
    #
    # The MIT License (MIT)
    #
    # Copyright (c) 2014-2015 FRITZ Thomas
    # Copyright (c) 2014-2017 FRITZ Thomas
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
  3. Thomas Fritz revised this gist Jun 8, 2015. 1 changed file with 46 additions and 42 deletions.
    88 changes: 46 additions & 42 deletions post-receive
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    #
    # The MIT License (MIT)
    #
    # Copyright (c) 2014 FRITZ Thomas
    # Copyright (c) 2014-2015 FRITZ Thomas
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    @@ -27,68 +27,72 @@
    #


    # Received branch will be checked against this. Only deploy when receiving this branch.
    DEPLOY_BRANCH="master"
    # Application Name:
    export DEPLOY_APP_NAME=`whoami`

    # This is the root deploy dir.
    DEPLOY_ROOT="/var/www"
    export DEPLOY_ROOT="${HOME}/work"

    # This will be 'eval'ed after git checkout -f step.
    # Use this to call your build/update script or run make, grunt, gulp, etc.
    # If empty or not set this step gets ignored.
    UPDATE_CMD='cd "${DEPLOY_TO}" && make "update"'
    # When receiving a new git push, the received branch gets compared to this one.
    # If you do not need this, just add a comment
    export DEPLOY_ALLOWED_BRANCH="master"

    # Command gets executed after 'UPDATE_CMD' has finished. Use this to restart running services
    # or daemons. If empty or unset this step gets ignored.
    RESTART_CMD='sudo systemctl restart "${PROJECT_NAME}.service" && sudo systemctl status "${PROJECT_NAME}.service"'
    # You could use this to do a backup before updating to be able to do a quick rollback.
    # If you need this just delete the comment and modify to your needs
    #PRE_UPDATE_CMD='cd ${DEPLOY_ROOT} && backup.sh'

    # Use this to do update tasks and maybe service restarts
    # If you need this just delete the comment and modify to your needs
    #POST_UPDATE_CMD='cd ${DEPLOY_ROOT} && make update'

    ###########################################################################################

    export GIT_DIR="$(cd $(dirname $(dirname $0));pwd)"
    export PROJECT_NAME="${GIT_DIR##*/}"
    export DEPLOY_TO="${DEPLOY_ROOT}/${PROJECT_NAME}"
    export GIT_WORK_TREE="${DEPLOY_TO}"
    export GIT_WORK_TREE="${DEPLOY_ROOT}"
    IP="$(ip addr show eth0 | grep 'inet ' | cut -f2 | awk '{ print $2}')"


    echo "+++++++++++++++++++++++ Welcome to '${HOSTNAME}' (${IP}) ++++++++++++++++++++++++"
    echo "githook: $(date): Welcome to '$(hostname -f)' (${IP})"
    echo

    # Make sure directory exists. Maybe its deployed for the first time.
    mkdir -p "${DEPLOY_TO}"
    mkdir -p "${DEPLOY_ROOT}"

    # Loop, because it is possible to push more than one branch at a time. (git push --all)
    while read oldrev newrev refname
    do

    branch=$(git rev-parse --symbolic --abbrev-ref $refname)

    if [ "${DEPLOY_BRANCH}" == "$branch" ]; then
    # Make sure GIT_DIR and GIT_WORK_TREE is correctly set and 'export'ed. Otherwhise
    # these two environment variables could also be passed as parameters to the git cli
    echo "githook: I will deploy '${DEPLOY_BRANCH}' branch of the '${PROJECT_NAME}' project to '${DEPLOY_TO}'"
    git checkout -f "${DEPLOY_BRANCH}"
    git reset --hard HEAD

    if [ ! -z "${UPDATE_CMD}" ]; then
    echo
    echo "githook: UPDATE (CMD: '${UPDATE_CMD}'):"
    eval $UPDATE_CMD
    fi

    if [ ! -z "${RESTART_CMD}" ]; then
    echo
    echo "githook: RESTART (CMD: '${RESTART_CMD}'):"
    eval $RESTART_CMD
    fi

    else
    echo "githook: I am NOT going to deploy the '${branch}' branch of the '${PROJECT_NAME}' project. Expected branch to deploy is '${DEPLOY_BRANCH}'."
    fi
    export DEPLOY_BRANCH=$(git rev-parse --symbolic --abbrev-ref $refname)
    export DEPLOY_OLDREV="$oldrev"
    export DEPLOY_NEWREV="$newrev"
    export DEPLOY_REFNAME="$refname"

    if [ ! -z "${DEPLOY_ALLOWED_BRANCH}" ]; then
    if [ "${DEPLOY_ALLOWED_BRANCH}" != "$DEPLOY_BRANCH" ]; then
    echo "githook: Branch '$DEPLOY_BRANCH' of '${DEPLOY_APP_NAME}' application will not be deployed. Exiting."
    exit 1
    fi
    fi

    if [ ! -z "${PRE_UPDATE_CMD}" ]; then
    echo
    echo "githook: PRE UPDATE (CMD: '${PRE_UPDATE_CMD}'):"
    eval $PRE_UPDATE_CMD || exit 1
    fi

    # Make sure GIT_DIR and GIT_WORK_TREE is correctly set and 'export'ed. Otherwhise
    # these two environment variables could also be passed as parameters to the git cli
    echo "githook: I will deploy '${DEPLOY_BRANCH}' branch of the '${DEPLOY_APP_NAME}' project to '${DEPLOY_ROOT}'"
    git checkout -f "${DEPLOY_BRANCH}" || exit 1
    git reset --hard "$DEPLOY_NEWREV" || exit 1

    if [ ! -z "${POST_UPDATE_CMD}" ]; then
    echo
    echo "githook: POST UPDATE (CMD: '${POST_UPDATE_CMD}'):"
    eval $POST_UPDATE_CMD || exit 1
    fi

    done

    echo
    echo "++++++++++++++++++++ See you soon at '${HOSTNAME}' (${IP}) ++++++++++++++++++++++"
    echo "githook: $(date): See you soon at '$(hostname -f)' (${IP})"
    exit 0
  4. Thomas Fritz revised this gist Jul 28, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion post-receive
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,8 @@ do
    # Make sure GIT_DIR and GIT_WORK_TREE is correctly set and 'export'ed. Otherwhise
    # these two environment variables could also be passed as parameters to the git cli
    echo "githook: I will deploy '${DEPLOY_BRANCH}' branch of the '${PROJECT_NAME}' project to '${DEPLOY_TO}'"
    git checkout -f
    git checkout -f "${DEPLOY_BRANCH}"
    git reset --hard HEAD

    if [ ! -z "${UPDATE_CMD}" ]; then
    echo
  5. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -112,6 +112,7 @@ Here are some more configuration files as a starting point:
    * [NGINX reverse proxy to local service running on non-privileged port (e.g. node.js)](https://gist.github.com/thomasfr/8653547)
    * [A common set of iptable rules](https://gist.github.com/thomasfr/9712418)
    * [A systemd service file for autossh (keeps an ssh tunnel open)](https://gist.github.com/thomasfr/9707568)
    * [Warmly - a poor mans wget based cache warmer script](https://gist.github.com/thomasfr/7926314)



  6. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -109,9 +109,9 @@ make deploy
    *Congratulations, you just setup git push deployment with automated build and service restart*

    Here are some more configuration files as a starting point:
    * [NGINX Reverse Proxy for local service running on non-privileged port (e.g. node.js)](https://gist.github.com/thomasfr/8653547)
    * [NGINX reverse proxy to local service running on non-privileged port (e.g. node.js)](https://gist.github.com/thomasfr/8653547)
    * [A common set of iptable rules](https://gist.github.com/thomasfr/9712418)
    * [A systemd service file for autossh](https://gist.github.com/thomasfr/9707568)
    * [A systemd service file for autossh (keeps an ssh tunnel open)](https://gist.github.com/thomasfr/9707568)



  7. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ This is how i used it on a *Debian Wheezy testing* (https://www.debian.org/relea
    Discuss, ask questions, etc. here https://news.ycombinator.com/item?id=7445545



    ## On the server (example.com)

    1. Create a user on `example.com`, as which we (the git client) connect (push) to `exmaple.com`.
    @@ -101,7 +102,16 @@ Discuss, ask questions, etc. here https://news.ycombinator.com/item?id=7445545
    ```

    * Repeat: Develop, test, commit and push :)
    Congratulations, you just setup git push deployment with automated build and service restart
    ```bash
    make deploy
    ```

    *Congratulations, you just setup git push deployment with automated build and service restart*

    Here are some more configuration files as a starting point:
    * [NGINX Reverse Proxy for local service running on non-privileged port (e.g. node.js)](https://gist.github.com/thomasfr/8653547)
    * [A common set of iptable rules](https://gist.github.com/thomasfr/9712418)
    * [A systemd service file for autossh](https://gist.github.com/thomasfr/9707568)



  8. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    # How-to setup a simple git push deployment
    These are my notes basically. At first i created this gist just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf https://twitter.com/thomasf
    This is how i used it on a *Debian Wheezy testing* (https://www.debian.org/releases/testing/)

    Discuss, ask questions, etc. here https://news.ycombinator.com/item?id=7445545

  9. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # How-to setup a simple git push deployment
    These are my notes basically. At first i created this gist just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf https://twitter.com/thomasf

    Discuss, ask questions, etc. here https://news.ycombinator.com/item?id=7445545


    ## On the server (example.com)

  10. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # How-to setup a simple git push deployment
    These are my notes basically. At first i created this gist just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf
    These are my notes basically. At first i created this gist just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf https://twitter.com/thomasf


    ## On the server (example.com)
  11. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,8 @@ These are my notes basically. At first i created this gist just as a reminder fo
    ```bash
    vim testapp/hooks/post-receive
    ## Paste the post-receive script from this gist and save
    ## If you do not need to execute a 'build' and/or 'restart' command,
    ## just delete or comment the lines 'UPDATE_CMD' and 'RESTART_CMD'
    chmod +x testapp/hooks/post-receive
    ```

    @@ -43,7 +45,8 @@ These are my notes basically. At first i created this gist just as a reminder fo
    ```

    * (Optional) Add a systemd service file for your app.
    If you are using `systemd`, you can use the `testapp.service` file from this gist. Make sure you name it like your repository. The post-receive hook can automatically restart your app.
    If you are using `systemd`, you can use the `testapp.service` file from this gist.
    Make sure you name it like your repository. The post-receive hook can automatically restart your app. You will also have to allow user git to make the `sudo` call. Be very careful and restrictive with this!


    ## On the client
  12. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 12 additions and 9 deletions.
    21 changes: 12 additions & 9 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -5,30 +5,34 @@ These are my notes basically. At first i created this gist just as a reminder fo
    ## On the server (example.com)

    1. Create a user on `example.com`, as which we (the git client) connect (push) to `exmaple.com`.
    We set `git-shell` as the login shell, so it is not possible to interactively login as this user.
    ```bash
    sudo useradd -m -s /usr/bin/git-shell git
    ```

    2. Add your ssh public key to the `authorized_keys` file of the created user:
    ```bash
    ## Because user git can not interactively login, we have to use sudo to get git temporarily
    sudo -u git bash
    cd ~
    ## cd /home/git
    mkdir -p .ssh
    vim .ssh/authorized_keys
    # Paste your public key and save
    ## Paste your public key and save
    ```

    3. Create a `git bare` repo for your project:
    ```bash
    mkdir testapp
    cd testapp
    ## /home/git/testapp
    git init --bare
    ```

    4. Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.
    ```bash
    vim testapp/hooks/post-receive
    # Paste the contents of post-receive from this gist
    ## Paste the post-receive script from this gist and save
    chmod +x testapp/hooks/post-receive
    ```

    @@ -38,24 +42,24 @@ These are my notes basically. At first i created this gist just as a reminder fo
    sudo chmod 775 /var/www
    ```

    6. (Optional) Add a systemd service file for your app.
    If you are using `systemd`, you can use the `testapp.service` file from this gist. Make sure you name it like your repository, so the post-receive hook can automatically find and restart your app.
    * (Optional) Add a systemd service file for your app.
    If you are using `systemd`, you can use the `testapp.service` file from this gist. Make sure you name it like your repository. The post-receive hook can automatically restart your app.


    ## On the client

    7. Create a git repo and add our newly created `remote`:
    6. Create a git repo and add our newly created `remote`:
    ```bash
    mkdir testapp
    cd testapp
    git init
    git remote add production [email protected]:~/testapp
    ```

    8. Commit and push to production:
    7. Commit and push to production:
    ```
    $ vim Makefile
    $ # Paste contents of Makefile from this gist (as an example)
    ## Paste contents of Makefile from this gist (as an example)
    $ git add .
    $ git commit -am "test commit"
    $ git push production master
    @@ -88,10 +92,9 @@ These are my notes basically. At first i created this gist just as a reminder fo
    To [email protected]:~/testapp
    08babc4..95cabcc master -> master
    $
    ```

    9. Repeat: Develop, commit and push :)
    * Repeat: Develop, test, commit and push :)
    Congratulations, you just setup git push deployment with automated build and service restart


  13. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # How-to setup a simple git push deployment
    These are my notes basically. I first created this just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf
    These are my notes basically. At first i created this gist just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf


    ## On the server (example.com)
  14. Thomas Fritz revised this gist Mar 22, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    # How-to setup a simple git push deployment
    These are my notes basically. I first created this just as a reminder for myself. Feel free to use this for your project as a starting point.
    These are my notes basically. I first created this just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf


    ## On the server (example.com)

    1. Create a user on `example.com`, as which we (the git client) connects (push) to `exmaple.com`.
    1. Create a user on `example.com`, as which we (the git client) connect (push) to `exmaple.com`.
    ```bash
    sudo useradd -m -s /usr/bin/git-shell git
    ```
  15. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ These are my notes basically. I first created this just as a reminder for myself
    4. Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.
    ```bash
    vim testapp/hooks/post-receive
    # Paste the script from this gist
    # Paste the contents of post-receive from this gist
    chmod +x testapp/hooks/post-receive
    ```

    @@ -38,8 +38,8 @@ These are my notes basically. I first created this just as a reminder for myself
    sudo chmod 775 /var/www
    ```

    6. (Optional) Systemd service file for your app
    If you are using `systemd`, you can use `testapp.service` from this gist. Make sure you name it like your repository, so the post-receive hook can automatically find and restart your app.
    6. (Optional) Add a systemd service file for your app.
    If you are using `systemd`, you can use the `testapp.service` file from this gist. Make sure you name it like your repository, so the post-receive hook can automatically find and restart your app.


    ## On the client
  16. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,9 @@ These are my notes basically. I first created this just as a reminder for myself

    ## On the server (example.com)

    1. Create a user on `example.com`, as which we (the git client) connects (push) to `exmaple.com`. (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)
    1. Create a user on `example.com`, as which we (the git client) connects (push) to `exmaple.com`.
    ```bash
    sudo groupadd -g 10001 git
    sudo useradd -u 10001 -g 10001 -d /home/git -m -s /usr/bin/git-shell git
    sudo useradd -m -s /usr/bin/git-shell git
    ```

    2. Add your ssh public key to the `authorized_keys` file of the created user:
  17. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions Git push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    On the server (example.com)
    =============
    # How-to setup a simple git push deployment
    These are my notes basically. I first created this just as a reminder for myself. Feel free to use this for your project as a starting point.


    ## On the server (example.com)

    1. Create a user on `example.com`, as which we (the git client) connects (push) to `exmaple.com`. (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)
    ```bash
    @@ -40,8 +43,7 @@ On the server (example.com)
    If you are using `systemd`, you can use `testapp.service` from this gist. Make sure you name it like your repository, so the post-receive hook can automatically find and restart your app.


    On the client
    =============
    ## On the client

    7. Create a git repo and add our newly created `remote`:
    ```bash
  18. Thomas Fritz renamed this gist Mar 21, 2014. 1 changed file with 0 additions and 0 deletions.
  19. Thomas Fritz renamed this gist Mar 21, 2014. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions 1_Preparations.md → GIT push deployment in 7 easy steps.md
    Original file line number Diff line number Diff line change
    @@ -36,21 +36,25 @@ On the server (example.com)
    sudo chmod 775 /var/www
    ```

    6. (Optional) Systemd service file for your app
    If you are using `systemd`, you can use `testapp.service` from this gist. Make sure you name it like your repository, so the post-receive hook can automatically find and restart your app.


    On the client
    =============

    6. Create a git repo and add our newly created `remote`:
    7. Create a git repo and add our newly created `remote`:
    ```bash
    mkdir testapp
    cd testapp
    git init
    git remote add production [email protected]:~/testapp
    ```

    7. Commit and push to production:
    8. Commit and push to production:
    ```
    $ echo "foo" >> test
    $ vim Makefile
    $ # Paste contents of Makefile from this gist (as an example)
    $ git add .
    $ git commit -am "test commit"
    $ git push production master
    @@ -86,7 +90,7 @@ On the client
    $
    ```

    8. Repeat: Develop, commit and push :)
    9. Repeat: Develop, commit and push :)
    Congratulations, you just setup git push deployment with automated build and service restart


  20. Thomas Fritz renamed this gist Mar 21, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  21. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -86,6 +86,8 @@ On the client
    $
    ```

    8. Repeat: Develop, commit and push :)
    Congratulations, you just setup git push deployment with automated build and service restart



  22. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions testapp.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    [Unit]
    Description=node.js testapp
    Requires=network.target
    After=network.target

    [Service]
    WorkingDirectory=/var/www/testapp
    Type=forking

    ExecStart=/bin/bash -c 'sleep 3;echo "I am starting";echo "$(whoami)";'
    # For a node.js app this could be something like:
    #ExecStart=/bin/bash -c 'npm start'

    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=testapp
    User=www-data
    Group=www-data

    Environment="NODE_ENV=production" "DEBUG=testapp:*"

    [Install]
    WantedBy=multi-user.target
  23. Thomas Fritz revised this gist Mar 21, 2014. 2 changed files with 36 additions and 5 deletions.
    3 changes: 2 additions & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,5 @@ deploy:

    update:
    @echo "Makefile: Doing UPDATE stuff like grunt, gulp, rake,..."
    @whoami
    @whoami
    @pwd
    38 changes: 34 additions & 4 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -50,10 +50,40 @@ On the client

    7. Commit and push to production:
    ```
    echo "foo" >> test
    git add .
    git commit -am "test commit"
    git push production master
    $ echo "foo" >> test
    $ git add .
    $ git commit -am "test commit"
    $ git push production master
    Counting objects: 12, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 432 bytes | 0 bytes/s, done.
    Total 4 (delta 2), reused 0 (delta 0)
    remote: +++++++++++++++++++++++ Welcome to 'example.com' (1.2.3.4) ++++++++++++++++++++++++
    remote:
    remote: githook: I will deploy 'master' branch of the 'testapp' project to '/var/www/testapp'
    remote:
    remote: githook: UPDATE (CMD: 'cd "${DEPLOY_TO}" && make "update"'):
    remote: Makefile: Doing UPDATE stuff like grunt, gulp, rake,...
    remote: git
    remote: /var/www/testapp
    remote:
    remote: githook: RESTART (CMD: 'sudo systemctl restart "${PROJECT_NAME}.service" && sudo systemctl status "${PROJECT_NAME}.service"'):
    remote: testapp.service - node.js testapp
    remote: Loaded: loaded (/etc/systemd/system/testapp.service; disabled)
    remote: Active: inactive (dead) since Fri 2014-03-21 22:10:23 UTC; 10ms ago
    remote: Process: 9265 ExecStart=/bin/bash -c sleep 3;echo "I am starting";echo "$(whoami)"; (code=exited, status=0/SUCCESS)
    remote:
    remote: Mar 21 22:10:20 image systemd[1]: Starting nodejs testapp...
    remote: Mar 21 22:10:23 image testapp[9265]: I am starting
    remote: Mar 21 22:10:23 image testapp[9265]: www-data
    remote: Mar 21 22:10:23 image systemd[1]: Started node.js testapp.
    remote:
    remote: ++++++++++++++++++++ See you soon at 'example.com' (1.2.3.4) ++++++++++++++++++++++
    To [email protected]:~/testapp
    08babc4..95cabcc master -> master
    $
    ```


  24. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    all:
    @echo "Doing all"

    deploy:
    @echo "Pushing to production"
    @git push [email protected]:~/testapp master

    update:
    @echo "Makefile: Doing UPDATE stuff like grunt, gulp, rake,..."
    @whoami
  25. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,23 @@
    On the server (example.com)
    =============

    1. Create a user on `example.com`, which we (the git client) use(s) to connect (push). (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)
    1. Create a user on `example.com`, as which we (the git client) connects (push) to `exmaple.com`. (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)
    ```bash
    sudo groupadd -g 10001 git
    sudo useradd -u 10001 -g 10001 -d /home/git -m -s /usr/bin/git-shell git
    ```

    2. Add your ssh public key to `git`s `authorized_keys` file:
    2. Add your ssh public key to the `authorized_keys` file of the created user:
    ```bash
    mkdir -p /home/git.ssh/
    vim /home/git/.ssh/authorized_keys
    # Paste your public key
    sudo -u git bash
    cd ~
    mkdir -p .ssh
    vim .ssh/authorized_keys
    # Paste your public key and save
    ```

    3. Create a `git bare` repo for your project:
    ```bash
    sudo -u git bash
    cd ~
    mkdir testapp
    cd testapp
    git init --bare
  26. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 14 additions and 16 deletions.
    30 changes: 14 additions & 16 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,7 @@
    On the server (example.com)
    =============

    1. Create a user on `example.com`, which we (the git client) use(s) to connect (push).
    (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)
    1. Create a user on `example.com`, which we (the git client) use(s) to connect (push). (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)
    ```bash
    sudo groupadd -g 10001 git
    sudo useradd -u 10001 -g 10001 -d /home/git -m -s /usr/bin/git-shell git
    @@ -24,7 +23,7 @@ On the server (example.com)
    git init --bare
    ```

    4. Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.
    4. Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.
    ```bash
    vim testapp/hooks/post-receive
    # Paste the script from this gist
    @@ -41,22 +40,21 @@ On the server (example.com)
    On the client
    =============


    6. Create a git repo and add our newly created `remote`:
    ```bash
    mkdir testapp
    cd testapp
    git init
    git remote add production [email protected]:~/testapp
    ```
    ```bash
    mkdir testapp
    cd testapp
    git init
    git remote add production [email protected]:~/testapp
    ```

    7. Commit and push to production:
    ```
    echo "foo" >> test
    git add .
    git commit -am "test commit"
    git push production master
    ```
    ```
    echo "foo" >> test
    git add .
    git commit -am "test commit"
    git push production master
    ```



  27. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 27 additions and 27 deletions.
    54 changes: 27 additions & 27 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -3,39 +3,39 @@ On the server (example.com)

    1. Create a user on `example.com`, which we (the git client) use(s) to connect (push).
    (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)
    ```bash
    sudo groupadd -g 10001 git
    sudo useradd -u 10001 -g 10001 -d /home/git -m -s /usr/bin/git-shell git
    ```
    ```bash
    sudo groupadd -g 10001 git
    sudo useradd -u 10001 -g 10001 -d /home/git -m -s /usr/bin/git-shell git
    ```

    2. Add your ssh public key to `git`s `authorized_keys` file:
    ```bash
    mkdir -p /home/git.ssh/
    vim /home/git/.ssh/authorized_keys
    # Paste your public key
    ```
    ```bash
    mkdir -p /home/git.ssh/
    vim /home/git/.ssh/authorized_keys
    # Paste your public key
    ```

    3. Create a `git bare` repo for your project:
    ```bash
    sudo -u git bash
    cd ~
    mkdir testapp
    cd testapp
    git init --bare
    ```

    4. Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.
    ```bash
    vim testapp/hooks/post-receive
    # Paste the script from this gist
    chmod +x testapp/hooks/post-receive
    ```
    ```bash
    sudo -u git bash
    cd ~
    mkdir testapp
    cd testapp
    git init --bare
    ```

    4. Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.
    ```bash
    vim testapp/hooks/post-receive
    # Paste the script from this gist
    chmod +x testapp/hooks/post-receive
    ```

    5. Set ownership and permissions of the `DEPLOY_ROOT` directory:
    ```bash
    sudo chown root:git -R /var/www
    sudo chmod 775 /var/www
    ```
    ```bash
    sudo chown root:git -R /var/www
    sudo chmod 775 /var/www
    ```


    On the client
  28. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 8 additions and 12 deletions.
    20 changes: 8 additions & 12 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,21 @@
    On the server
    On the server (example.com)
    =============

    * Create a user on the server `example.com`, which we (the git client) uses to connect (push).
    1. Create a user on `example.com`, which we (the git client) use(s) to connect (push).
    (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)

    ```bash
    sudo groupadd -g 10001 git
    sudo useradd -u 10001 -g 10001 -d /home/git -m -s /usr/bin/git-shell git
    ```

    * Add your ssh public key to `git`s `authorized_keys` file:

    2. Add your ssh public key to `git`s `authorized_keys` file:
    ```bash
    mkdir -p /home/git.ssh/
    vim /home/git/.ssh/authorized_keys
    # Paste your public key
    ```

    * Create a `git bare` repo for your project:

    3. Create a `git bare` repo for your project:
    ```bash
    sudo -u git bash
    cd ~
    @@ -27,15 +24,14 @@ cd testapp
    git init --bare
    ```

    * Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.

    4. Copy the `post-receive` script from this gist to the `hooks` dir of the created bare repo.
    ```bash
    vim testapp/hooks/post-receive
    # Paste the script from this gist
    chmod +x testapp/hooks/post-receive
    ```

    * Set ownership and permissions of the `DEPLOY_ROOT` directory:
    5. Set ownership and permissions of the `DEPLOY_ROOT` directory:
    ```bash
    sudo chown root:git -R /var/www
    sudo chmod 775 /var/www
    @@ -46,15 +42,15 @@ On the client
    =============


    * Create a git repo and add our newly created `remote`:
    6. Create a git repo and add our newly created `remote`:
    ```bash
    mkdir testapp
    cd testapp
    git init
    git remote add production [email protected]:~/testapp
    ```

    * Commit and push to production:
    7. Commit and push to production:
    ```
    echo "foo" >> test
    git add .
  29. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 17 additions and 4 deletions.
    21 changes: 17 additions & 4 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,6 @@ chmod +x testapp/hooks/post-receive
    ```

    * Set ownership and permissions of the `DEPLOY_ROOT` directory:

    ```bash
    sudo chown root:git -R /var/www
    sudo chmod 775 /var/www
    @@ -47,10 +46,24 @@ On the client
    =============


    * Create a git repo and add our newly created `remote`

    * Create a git repo and add our newly created `remote`:
    ```bash
    mkdir testapp
    cd testapp
    git init
    git remote add production [email protected]:~/testapp
    git remote add production [email protected]:~/testapp
    ```

    * Commit and push to production:
    ```
    echo "foo" >> test
    git add .
    git commit -am "test commit"
    git push production master
    ```






  30. Thomas Fritz revised this gist Mar 21, 2014. 1 changed file with 14 additions and 5 deletions.
    19 changes: 14 additions & 5 deletions Preparations.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    On the server
    _____________
    =============

    * Create a user on the server, which we (the git client) uses to connect (push) to this server.
    I am using gid und uid higher than normally, if i want to restrict the user more than other user accounts, i could check for uid>10000 or gid>10000
    * Create a user on the server `example.com`, which we (the git client) uses to connect (push).
    (I am using gid und uid higher than normally because, in case i want to restrict the user later based on the uid, i could then check for uid>10000 or gid>10000 - but you can safely ommit the `-u` and `-g` flags)

    ```bash
    sudo groupadd -g 10001 git
    sudo useradd -u 10001 -g 10001 -d /home/git -m -s /usr/bin/git-shell git
    ```

    * Add your ssh public key to the `git` users `authorized_keys` file:
    * Add your ssh public key to `git`s `authorized_keys` file:

    ```bash
    mkdir -p /home/git.ssh/
    @@ -44,4 +44,13 @@ sudo chmod 775 /var/www


    On the client
    _____________
    =============


    * Create a git repo and add our newly created `remote`

    ```bash
    mkdir testapp
    cd testapp
    git init
    git remote add production [email protected]:~/testapp