You've got files in a git repo and you want them on a static server. Here's how it's done using a Mac Mini:
-
Set up your local repo
$ mkdir marketing && cd marketing $ git init $ echo 'Hello, world!' > index.html $ git add . $ git commit -am "init"
-
On the server, init a bare repo
$ cd /mt/git $ mkdir getfirehose.git && cd getfirehose.git $ git init --bare --shared
3.Create a git
user in System Preferences. If can't screenshare into your server for some reason, you can also do this:
$ sudo dscl . -create /Users/git
$ sudo dscl . -create /Users/git UserShell /usr/bin/git-shell
$ sudo dscl . -create /Users/git RealName "Git server"
$ sudo dscl . -create /Users/git UniqueID 504
$ sudo dscl . -create /Users/git PrimaryGroupID 20
$ sudo dscl . -create /Users/git NFSHomeDirectory /Users/git
$ sudo dscl . -passwd /Users/git [the users password]
$ sudo mkdir -p /Users/git
$ sudo chown -R git:staff /Users/git
-
Make the owner of all files in the repo to the git user.
$ sudo chown -R git .
-
Change git user's shell to use git-shell (this allows the
git
user to do only git things)$ chsh -s /usr/bin/git-shell $ sudo dscl . -create /Users/git UserShell /usr/bin/git-shell
-
Print a greeting when someone tries to ssh in as the
git
user:$ mkdir $HOME/git-shell-commands $ cat >$HOME/git-shell-commands/no-interactive-login <<\EOF #!/bin/sh printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not" printf '%s\n' "provide interactive shell access." exit 128 EOF $ chmod +x $HOME/git-shell-commands/no-interactive-login
-
Create SSH keys on your local machine (if you already have them, skip this step)
$ mkdir .ssh $ chmod 700 .ssh $ cd .ssh $ ssh-keygen -t rsa $ cp id_rsa.pub ~/Desktop
-
Move your publish ssh key to the server:
$ scp ~/Desktop/id_rsa.pub [email protected]:/Users/git
-
Add your local machines public key to the
git
user'sauthorized_keys
file.$ mkdir .ssh $ chmod 700 .ssh $ cat id_rsa.pub >> .ssh/authorized_keys
-
Create a post-receive hook to checkout the repo to your web folder:
$ mkdir /mt/sites/getfirehose $ cd /mt/git/getfirehose.git $ cat > hooks/post-receive #!/bin/sh GIT_WORK_TREE=/mt/sites/getfirehose git checkout -f $ chmod +x hooks/post-receive
-
Add your repo as a remote on your local machine.
$ git add remote production [email protected]:/mt/git/getfirehose.git
-
Push to your repo
$ git push production master
-
Install nginx (could be a lot more complex, but if you're starting off simple)
$ brew install nginx
-
Open the nginx config file:
$ vi /usr/local/etc/nginx/nginx.conf
-
Configure nginx to serve up your site:
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; server { listen 80; server_name getfirehose.com www.getfirehose.com; location / { root /mt/sites/getfirehose/; index index.html index.htm; } } }
-
Make sure your git user owns everything in the site folder
$ sudo chown -R git /mt/sites/getfirehose
-
Start or restart nginx:
$ sudo kill -HUP `cat /usr/local/var/run/nginx.pid`