Skip to content

Instantly share code, notes, and snippets.

@cdiaz
Forked from yosukehasumi/git-auto-deploy.md
Created January 29, 2018 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdiaz/7c8f6516dc6d75fde3ed25dab088f16a to your computer and use it in GitHub Desktop.
Save cdiaz/7c8f6516dc6d75fde3ed25dab088f16a to your computer and use it in GitHub Desktop.
Setting Up Git-Auto-Deploy on Digital Ocean

Install software-properties-common

sudo apt-get install software-properties-common

Add Repo

sudo add-apt-repository ppa:olipo186/git-auto-deploy

Update apt-get

sudo apt-get update

Install git-auto-deploy

sudo apt-get install git-auto-deploy

Modify /etc/git-auto-deploy.conf.json

{
  "pid-file": "/etc/git-auto-deploy/.gitautodeploy.pid",
  "http-host": "0.0.0.0",
  "http-port": 8001,
  "repositories": [
    {
      "url": "git@gitlab.example.com:user/repo.git",
      "branch": "master",
      "remote": "origin",
      "path": "/var/www/html",
      "filters": [
        {
          "object_kind": "push",
          "ref": "refs/heads/master"
        }
      ]
    }
  ]
}

Generate key

cd /root/.ssh/; ssh-keygen -t rsa;

copy key to git-auto-deploy

sudo cp /root/.ssh/id_rsa /etc/git-auto-deploy/.ssh/

change permissions for script to git-auto-deploy user

sudo chown -R git-auto-deploy:git-auto-deploy /etc/git-auto-deploy

Add git-auto-deploy user to the www-data group

usermod -a -G www-data git-auto-deploy

For some reason I'm not so good with permission stuff and the above command doesn't work the way i expect, my solution is to change the ownership of the entire html directory

chown -R git-auto-deploy:git-auto-deploy /var/www/html

You may need to make sure that the repo IP fingerprint has been added to the ~/.ssh/known_hosts file and copy this to the git-auto-deploy/.ssh/known_hosts file

ssh-keyscan -H -t rsa gitlab.pen.org  >> ~/.ssh/known_hosts
cp ~/.ssh/known_hosts /etc/git-auto-deploy/.ssh/
chown git-auto-deploy:git-auto-deploy /etc/git-auto-deploy/.ssh/known_hosts

Next make sure you add your public key from /root/.ssh/id_rsa.pub to gitlab and add a webhook that triggers the "push" event to http://mydomain.com:8001

Start and check your git-auto-deploy server by running

service git-auto-deploy start
service git-auto-deploy status

For Digital ocean you may have to open up the 8001 port

sudo ufw allow 8001/tcp

Install git

sudo apt-get install git

You may need to verify the authenticity (fingerprint) of the git repo. In my case this was a Digital Ocean git repo so I ssh'd into my /var/www/html directory and ran

git init
git remote add origin git@gitlab.example.com:user/repo.git
git fetch origin

To see git-auto-deploy logs you can watch the log file:

tail -f /var/log/git-auto-deploy.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment