Skip to content

Instantly share code, notes, and snippets.

@SunDi3yansyah
Last active June 25, 2019 12:34
Show Gist options
  • Save SunDi3yansyah/d60c3ad38ebdb700aed1ad2b40f458c6 to your computer and use it in GitHub Desktop.
Save SunDi3yansyah/d60c3ad38ebdb700aed1ad2b40f458c6 to your computer and use it in GitHub Desktop.
Git Hooks

Git Hooks

On server for git hook

mkdir /git
cd /git
mkdir repository/app.git -p
cd repository/app.git
git init --bare
cd hooks
nano post-receive
#!/bin/bash

TARGET="/usr/share/nginx/repository/app"
GIT_DIR="/git/repository/app.git"
BRANCH="master"

while read oldrev newrev ref
do
  if [[ $ref = refs/heads/$BRANCH ]];
  then
    echo "Ref $ref received. Deploying ${BRANCH} branch to server..."
    git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
  else
    echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
  fi
done

# other code bash
chmod +x post-receive
cd /usr/share/nginx/repository
mkdir app

On local repository

cd /workspace
mkdir app
cd app
git init
git remote add [REMOTE NAME] ssh://user@host.com/git/repository/app.git
git add .
git commit -m "Deploy!"
git push [REMOTE NAME] [BRANCH NAME]
Ref:
@SunDi3yansyah
Copy link
Author

SunDi3yansyah commented Jul 24, 2018

Problem SSH on AWS EC2

cat ~/.ssh/id_rsa.pub | ssh -i file.pem ec2-user@ec2-ip.compute-1.amazonaws.com "cat >> ~/.ssh/authorized_keys"

@SunDi3yansyah
Copy link
Author

SunDi3yansyah commented Sep 25, 2018

Update file HEAD on git hook if use custom branch

nano HEAD
ref: refs/heads/master

to:

ref: refs/heads/development

@SunDi3yansyah
Copy link
Author

SunDi3yansyah commented Mar 27, 2019

@SunDi3yansyah
Copy link
Author

SunDi3yansyah commented Mar 27, 2019

No Need Password Normaly User (UBUNTU ONLY):

sudo sh -c 'echo "deploy ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-deploy'

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