powtac
powtac

Reputation: 41040

Deploy from GitHub?

Can I deploy directly from GitHub to my (debian linux) server? Is there a way of transmitting code from GitHub to my server automatically after each commit? And also manipulating a config file?

Upvotes: 0

Views: 327

Answers (2)

Jay Allen
Jay Allen

Reputation: 485

Bibhas' answer above is correct although, if you're not the only person collaborating on the repository, you may want to consider using git tags to indicate release-able code and trigger the update only when a new tag appears.

To do this, tag your latest commit on your dev machine and push it:

git tag -a v1.0 -m"Initial tag"
git push origin --tags

Then, on your server:

git remote update && git checkout v1.0

Then, your cron script should do the following:

  1. Get the latest from Github:
    cd $REPO && git remote update
  2. Get the ref of the current HEAD (assumes you are ONLY checking out to tags):
    current=$(git rev-parse HEAD)
  3. Get the ref of the latest tag:
    latest=$(git rev-list --tags | head -1)
  4. And finally, if $current is not equal to $latest, check out the latest tag:
    git checkout $(git tag --points-at $latest)

Upvotes: 1

Bibhas Debnath
Bibhas Debnath

Reputation: 14929

Clone the repository on server, Run a cronjob on the server every 1 or 2 minutes(or any interval depending on the frequency of your commits) and update the repo. That should be enough. But that's not advisable on the production server. You could do it on testing or staging server though.

Upvotes: 2

Related Questions