Created
April 28, 2015 13:22
-
-
Save antonydb/c17120dfa09b76590862 to your computer and use it in GitHub Desktop.
Setting up Git deploy to EC2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following instructions are for setting up git deployment on an AWS ec2 ubuntu instance (or any ubuntu server for that matter). Also included are instructions for deploying to the remote server and github simultaneously. | |
Git deploy setup: | |
1. copy your public key to your ec2 instance: | |
cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/your_pemfile.pem ubuntu@your_ip_addr "cat>> .ssh/authorized_keys" | |
2. on remote server: create bare git directory | |
$ cd ~ | |
$ mkdir ProjectDir.git && cd ProjectDir.git | |
$ git init --bare | |
3. on remote server: create post-receive hook | |
$ cat > hooks/post-receive | |
#!/bin/sh | |
GIT_WORK_TREE=/home/ubuntu/www/yourdomain.com | |
export GIT_WORK_TREE | |
git checkout -f | |
$ chmod +x hooks/post-receive | |
4. on local machine: init repo and add remote repository | |
git init | |
git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git | |
git push ec2 +master:refs/heads/master | |
note: only have to use “+master:refs/heads/master for 1st push | |
If you get an error for insufficient permission for adding an object to repository database. Log into remote server and run the following: | |
cd /path/to/repo.git | |
chgrp -R groupname . | |
chmod -R g+rwX . | |
find . -type d -exec chmod g+s '{}' | |
To push to remote repo in future: | |
$ git push ec2 master | |
Push to multiple remote repos with one command | |
1. add to .git/config in local repo | |
[remote "all"] | |
url = https://github.com/YourGitAccount/ProjectDir.git | |
url = ssh://ubuntu@your_ip_addr/home/ubuntu/projects/ProjectDir.git | |
2. push to both repos simultaneously | |
$ git push all master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment