Hacker News new | ask | show | jobs
by csomar 975 days ago
> i have very high and unusual standards,

> this script runs every minute on a cronjob, and rebuilds my site if the git repo has been updated.

He is pulling the git repo 525,600 times a year for the few commits he'll be making in that year... I guess that explains the "unusual" word?

4 comments

git fetch is basically just one string comparison if there are no new commits [0], I don’t think it’s as costly as you make it sound.

[0] https://stackoverflow.com/a/44476803

Maybe, but Git has hooks. The author could deploy on push to do it only when needed, and immediately when relevant, rather than having to decide on a trade-off between immediacy and doing a lot of useless operations.
Obviously, this approach might not work for everyone, but I like to self-host my repos and use a git hook (post-receive) like this:

  #!/bin/sh
  BUILDDIR=/home/buildhook/.ib-build
  BUILD=`grep build |cut -d" " -f2`
  if [ -n "$BUILD" ]
  then
          touch $BUILDDIR/$BUILD
  fi

And then the buildhook user has a job that runs every minute by cron:

  #!/bin/sh
  BUILDDIR=/home/buildhook/.ib-build
  BUILD=`ls -t $BUILDDIR | head -1`
  if [ -n "$BUILD" ]
  then
          rm -f $BUILDDIR/$BUILD
          (
          echo Building $BUILD on builder...
          ssh builder time ./build $BUILD
          ) 2>&1 | mail -s "Building $BUILD on builder" build@example.com
  fi
For my use case, on this repo, pushing to a branch with the word "build" in its name will trigger a build of that commit, which builds and packages it into a dpkg, and the build server hosts a private apt repository so I can just `apt-get update; apt-get install blah` on all the servers.

An alternative strategy is pushing to a different repo on a build server, etc.

I guess that would have been fine if we didn't have alternatives (ie: callbacks). He is already running a web server, so he could listen through that for updates.
If he breaks the server, then a callback/webhook notification for the fix won't work either.

If you want to use a callback for this I'd recommend still polling periodically anyway.

Problem with self-hosting though, if his server breaks, so does the callbacks.
It might be a string comparison, but one of the strings usually comes from a remote server, which can be costly.
Unusual would be crazy in this circumstance.

Tell, don't ask.

you're making a lot of assumptions about how my deployment works here!

my git repositories are all on the same server that hosts my website - git is not doing a remote fetch - it's a local fetch, which makes it basically instantaneous.

even if it were a remote fetch, i would be fine with it. 525,600 http requests per year is less wasteful than NetworkManager's heartbeat (which defaults to 1 heartbeat request per _30 seconds_ on Arch)

for some context, a stock nginx server with 8 cpus can handle ~500k+ http requests _per second_.

Did you remember that number from Rent?