Skip to content

Instantly share code, notes, and snippets.

@skyweb
Forked from necolas/Instructions.md
Created January 2, 2014 14:32
Show Gist options
  • Select an option

  • Save skyweb/8219989 to your computer and use it in GitHub Desktop.

Select an option

Save skyweb/8219989 to your computer and use it in GitHub Desktop.

Ghetto git deployment strategy

I wanted something simple for staging and deploying my static site.

  1. Generate build locally
  2. Push the build to a bare git repo on your server
  3. A post-receive hook checks out the files in the public directory

Remote server config

ssh into your server (has your public ssh key)

ssh you@example.org

create a directory for your site

mkdir ~/example.com

create a directory for git

mkdir ~/example.git 

create a bare git repo

cd example.git
git init --bare

setup a post-receive hook

cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/path/to/example.com git checkout -f

chmod +x hooks/post-receive

Repeat for staging server, if you want.

Local process

I'm using Make:

Deploy to production

make prod

Deploy to staging

make staging
# Local project makefile
BUILD_DIR := ./build
DEPLOY_DIR := ./deploy
STAGING_REPO = ssh://you@example.org/~/staging.example.git
PROD_REPO = ssh://you@example.org/~/example.git
build:
# whatever your build step is
clean-deploy:
@ rm -rf $(DEPLOY_DIR)
clone-prod: clean-deploy
git clone $(PROD_REPO) $(DEPLOY_DIR)
clone-staging: clean-deploy
git clone $(STAGING_REPO) $(DEPLOY_DIR)
# force update the remote repo with whatever is in the build directory
deploy:
cp -R $(BUILD_DIR)/ $(DEPLOY_DIR) && \
cd $(DEPLOY_DIR) && \
git checkout --orphan new_master && \
git add -A && \
git commit -m "Release" && \
git branch -M master && \
git push -f origin +master:refs/heads/master
prod: build clone-prod deploy
staging: build clone-staging deploy
.PHONY: build clean-deploy clone-prod clone-staging deploy prod staging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment