This article can be considered a continuation of the previous post, “Using Amazon Web Services (AWS) Free Tier to Set Up a WordPress Blog.” Building on that foundation, we can establish our own Git server. The method described here utilizes gitolite and gitlist. Gitolite is a user management layer for Git, facilitating convenient management of users and Git repositories, while gitlist is a tool that allows for easy viewing of Git repositories via a web interface. This article assumes you have a basic understanding of Git and that the environment has been set up as described in the previous post.
Installing and Configuring Gitolite on EC2 (sudo su)
cd /tmp
# Prepare key files, or use your existing key files
ssh-keygen -t rsa
cp id_rsa.pub /tmp/your-name.pub
# Install packages
sudo apt-get install git gitolite git-daemon-run
# Create git user
sudo adduser --system --shell /bin/bash --gecos 'git version control' --group --disabled-password --home /home/git git
sudo su - git
cd /home/git
echo "PATH=$HOME/bin:$PATH" > .bashrc
# Initialize gitolite
gl-setup /tmp/your-name.pub
# After executing the above command, gitolite will prompt you to choose a familiar editor to modify the configuration file. Open the configuration and make the following modification:
$REPO_UMASK = 0022;
Gitolite installation is now complete. It is recommended to proceed with the following steps.
Configuring the ~/.ssh/config File on Your Workstation
To facilitate connection, update your config file as follows:
Host preferred_name, e.g., gs
Hostname AWS_PUBLIC_DNS
User git
IdentityFile C:/Users/test/.ssh/id_rsa # Path to your private key
#PreferredAuthentications publickey
Managing Gitolite from Your Workstation
You can now connect from your workstation. Clone the administration directory:
git clone git@gs:gitolite-admin.git
Edit conf/gitolite.conf to add repositories, for example:
repo anothertest
RW+ = @all
To add users, simply add their public keys to the keydir. If a user has multiple public keys (e.g., one for the workstation and one for a laptop), you can create subdirectories under keydir and add the keys accordingly. For example, to add keys for Tom, place laptop/tom.pub and workspace/tom.pub in the respective directories.
After making modifications, commit and push back to the corresponding repository and user settings on the host.
Configuring Gitlist on EC2
While managing repositories and users via Git is convenient, it may not be ideal if your boss needs to review Git commits (:P). Installing Gitlist provides a much more convenient way to view repositories via a web browser.
Download the latest version from gitlist.org and complete the configuration:
cd /tmp
wget https://s3.amazonaws.com/gitlist/gitlist-0.4.0.tar.gz
tar -zxf gitlist-0.4.0.tar.gz
mv gitlist /sites/
cd /sites/gitlist
mv config.ini-example config.ini
edit config.ini
repositories[] = '/data/git/repositories/'
hidden[] = '/data/git/repositories/gitolite-admin.git' # Recommended to add this so the admin directory is not visible via the web interface
mkdir cache # Must be created manually
chown -Rh www-data:www-data /sites/gitlist
Create the Nginx site configuration at /etc/nginx/sites-available/gitlist:
server {
listen 80;
server_name gitlist;
keepalive_timeout 70;
access_log /var/log/nginx/gitlist-access.log;
error_log /var/log/nginx/gitlist-error.log;
root /sites/gitlist;
index index.php;
location ~ /include {
deny all;
return 403;
}
location ~ ^/api/(tickets|tasks)(.*)$ {
try_files $uri $uri/ /api/http.php;
}
location ~ ^/scp/ajax.php/(.*)$ {
try_files $uri $uri/ /scp/ajax.php;
}
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-admin.sock;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
If you are using the same fastcgi_pass as before, no additional settings are required. If not, you need to create a new pool configuration:
cd /etc/php5/fpm/pool.d/
cp www.conf gitlist.conf
edit gitlist.conf
name -> gitlist
listen -> [match the socket path in the nginx config]
Then restart php5-fpm and Nginx. You should now be able to access the Gitlist page by visiting your address.
If there were no issues during the initial configuration setup, the webpage should display correctly. If there were errors previously, edit /home/git/.gitolite.rc, find $REPO_UMASK, change it to 0022, and manually set permissions for existing files using chmod -R 755 /home/git. This should resolve the issue.