Best way to run build scripts before deployment of web app?

When working with a git repository that holds all source assets and a gulp / grunt build script or composer install that needs to be ran before it will function, what is the best way to deploy it to the production server? Here are some solutions I came up with:

I keep running into this problem and thus far I have resorted to the first option (which is more of a manual workaround in my experience)

  • Visual SVN diff and compare tools for Linux
  • How do I cat revisions of a file, following it through renames?
  • Comparing differences across a rebase in Git
  • Git rebase edit and a few branches
  • Can Git bash be setup to not require me to type “git” for every command?
  • What is the canonical way to reference a git repository and branch
  • One Solution collect form web for “Best way to run build scripts before deployment of web app?”

    One method I have seen working is to combine local build scripts with simple git-deployment and using two repositories: e.g. src and www.

    1. Your src repository contains sources and build scripts, tests etc.

    2. The build runs locally (composer, grunt, sass, js-min etc) and outputs the ‘static’ result across to the www / htdocs folder in the www repo.

    3. The www repo is committed by the build and pushed to the deployment remote.

    4. The deployment remote is on the production www server, with a post-receive hook which checks out the head (from a bare repo in /var/git/yourdomain) to the web server (e.g. in /var/www/yourdomain) which is a git working directory.

    It’s basically simple, with little proprietary technology (beyond grunt, composer and git), but of course the details will take a while to get right.

    I’ve found building to a branch is a nightmare, partly due to git’s tenacity on tracking files and having to avoid some merges. It makes it really hard to do build cleans for example. You’d have to at least have a separate www folder you’d build into an essentially duplicate any back-end scripts which weren’t compiled (like PHP). And versioning and branching dev v.s. releases is sometimes at odds. Having two repos separates this completely, and allows you to have deployment branches deployed to different websites for example (staging, prod).

    Of course the git deployment method means you do need “full” access to the host to install git, the hooks and have ssh access. But most web hosts provide ssh access?

    I’ve found git-deployment to be extremely reliable and trouble free.

    Git Baby is a git and github fan, let's start git clone.