Skip to content

Instantly share code, notes, and snippets.

@elmariofredo
Created July 2, 2014 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmariofredo/9737d41b89b598a09d2f to your computer and use it in GitHub Desktop.
Save elmariofredo/9737d41b89b598a09d2f to your computer and use it in GitHub Desktop.
Simple PHP deploy script using git, inspired by capistrano magic. Just run ./php-deploy.sh BRANCH-NAME and target apache to /srv/app/public folder.
#!/bin/bash
project_name=app
project_url=git@github.com:some/repo.git
target_branch=$1
if [ ! -d "/srv/$project_name/repo" ]
then
echo "Setting up repo for the firts time"
mkdir -p /srv/$project_name/repo
mkdir -p /srv/$project_name/public
git clone --mirror $project_url /srv/$project_name/repo
fi
cd /srv/$project_name/repo
git remote update
last_commit_sha=$(git rev-parse $target_branch)
if [ ! -d "/srv/$project_name/public/$target_branch" ]
then
echo "Deploying $last_commit_sha on $target_branch"
mkdir -p /srv/$project_name/public/$target_branch
git archive $target_branch | tar -x -C /srv/ztrack/public/$target_branch
else
echo "Deploying $last_commit_sha on $target_branch has been done already"
fi
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment