This is an expansion of Deployment page ,specifically for setting up an EC2 instance for use with git. Refer to the Deployment page first as it goes into more detail.
To SSH into the instance:
ssh -i imagineDev.pem [email protected]
From the dir containing the .pem file. pem must have 600 permission.
LAMP setup is standard:
sudo apt-get update sudo apt-get install apache2 sudo apt-get install php5 sudo apt-get install libapache2-mod-php5 sudo apt-get install mysql-server sudo apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json sudo /etc/init.d/apache2 restart
install Git
sudo apt-get install git
Next up I mkdir Repos. Currently this is just outside www to mirror Live , but perhaps this should be moved.
Then
sudo mkdir testdev.git
git init --bare
then in www create a matching dir
mkdir testdev
Then glone the Repo to the working dir
sudo git clone /var/Repos/testnew.git
Edit the hooks.
As per Andys instructions on the Deployment page , we need to setup a hook , which runs when the bare repo is pushed to .In the hooks dir:
nano post-recieve
Example hook script:
#!/bin/bash export GIT_DIR=/var/www/test/testdev/.git/ export GIT_WORK_TREE=/var/www/test/testdev/ cd /var/www/test/testdev/ git fetch git merge origin/master git submodule update --init --recursive
then on the post-recviee file:
sudo chmod a-x post-receive
cd /var/www/testnew/testnew/.git$
Add the ubuntu user to the group. We login as Ubuntu to our dev sever as shown below.
sudo chgrp -R ubuntu * sudo chmod -R g+ws * git config core.sharedRepository true
http://ec2-54-247-139-221.eu-west-1.compute.amazonaws.com/var/Repos/testdev.git
To add the second remote from within the local repo:
git remote add dev ssh://176.34.177.224/var/Repos/testdev.git
We can make things easier by creating a shortcut like:
Host imaginedev 176.34.177.224 Hostname 176.34.177.224 User ubuntu IdentityFile ~/.ssh/imagineDev.pem
in our ~/.ssh/config file.
This way we can then use something like :
imaginedev:/var/Repos/testtest.git
When we add our remote. Doing this also helps with the user issue.
Permissions.
permissions on .git/post-recieve need to be executable, other wise when pushing from local to dev you will receive warnings such as ‘HEAD_FETCH not writable’ etc.
permissions on the www/imagine-site need to be writable by the git user. Failure to do this will not result in an error message, but the working directory will not be updated , only the bare repo. This will then cause sync issues. 🙁
If the dev goes out of sync with local:
commit -a
On the dev/www/imagine-site dir and then push again from local.
Recent Comments