Auto pull on commit and run bash script

Hi,

I’m trying to get the following working:

  1. My server(s) listen for a git commit to a specific branch (dev and prod).
  2. Server then pulls the latest and executes a shell script “sudo update.sh”
  3. sudo update.sh: will stop all docker containers/services and delete them, it will also delete any images. It will then re-build and re-start the swarm.

Step 1: I find various information from long ago online on how to do this but nothing that explains the linking of this or how to set it up. Or its telling me to go into menus that just don’t exist on github. Should I switch to gitlab? There will be many servers litening to the repo and some will be prod and 2 or 3 will be dev. I’ve watched lots of videos on people building scripts on github and its doing tests and etc etc but where is it building this, how do i build on the actual servers? I don’t get the link between server and github, is this just for image docker image build and then server to monitor the new image save to docker and to update?

Step 2: No idea, can’t get step 1 working.

Step 3: Not a problem just write a bash script, getting git or whatever step 1 and 2 is handled by no idea.

I don’t care about unit tests, I just need to auto pull and re-build on branch commit.

Anyone got any tips? guide / tutorial links? YouTube walkthroughs for such a process?

Should I write some python or node server, listen for hook calls and get python/node to handle the git pull and execution of the bash script?

This is probably the solution that will work for me…

  • Created github webhook callback to some server (1 for many)

  • Created serverside script somewhere to keep a list of all servers where the node express applications will be listening for the correct key and command to process, when called from the webook it will loop through them and make a request to each ip sending the key and command

  • Created node express application which listens for key and command

  • Deployed express application with vm install and ensured it restarts on server reboot

  • When express application receives the correct key and command it will execute a bash script and terminate its own process

  • Bash script then pull repo, deleted all docker images and containers, re-builds and re-starts the swarm and express application waiting for furhter commit events