0

I have 4 servers, One for load balancing (Nginx reverse proxy) and 3 nodejs (upstream servers).

I want to deploy code from bitbucket to this 3 servers same time, How i can manage it? I can install jenkis on each this 3 server and deploy but is there better solution? can i install jenkins on load balancer server and deploy from it?

Shalva Gegia
  • 95
  • 1
  • 8
  • Git now supports pushing to more than one repo, see something like http://stackoverflow.com/questions/14290113/git-pushing-code-to-two-remotes – David Neiss Aug 08 '16 at 04:10
  • You can use a master-slave setup in which you push to the master. The master will start 3 slaves jobs (each slave on each server). – lvthillo Aug 08 '16 at 07:47

2 Answers2

0

You have to write script which will do it for you.
The script can be a shell script of any language or you can use Jenkins to do it for you as well.

You dont need Jenkins on each server, you simply need a git script which will push it to your servers or that your servers will pull the changes form the server.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • So i should write script which will pull the changes from bitbucket, than run several commands (npm install and e.tc.) and put this script on each server and call it manually? am I right? I want manual deployment (not automated after bitbucket push changes) – Shalva Gegia Aug 07 '16 at 22:28
  • Yep, or you can do it with Jenkins as well, its up to you how to do it. – CodeWizard Aug 07 '16 at 22:29
0

The best solution for this is to pick a primary repository you push to, and then to install a hook in that server that automatically pushes all incoming stuff to the other servers.

$ cat .git/hooks/post-receive
#!/bin/bash

IFS=' '
while read local_ref local_sha remote_ref remote_sha
do

  echo "$remote_ref" | egrep '^refs\/heads\/[A-Z]+-[0-9]+$' >/dev/null && {
    ref=`echo $remote_ref | sed -e 's/^refs\/heads\///'`
    echo Forwarding feature branch to other repository: $ref
    git push -q --force other_repos $ref
  }

done
AnoE
  • 8,048
  • 1
  • 21
  • 36