1

I have a VPS and am able to connect trough ssh using Terminal. Every project I have are dockerized and have github repositories. Since I am new to deployments so far my deployment process is manual:

$ ssh [email protected]
$ cd /root/www/project_dir
$ git pull
$ docker-compose up --build -d --force-recreate

I would like to know how should I correctly deploy dockerized github applications on VPS? Is there a better practice or script, maybe a tool?

2
  • where is your git repo hosted?
    – simbo1905
    Apr 8, 2019 at 21:56
  • @simbo1905 GitHub Apr 9, 2019 at 7:21

1 Answer 1

2

Here is a Webhook rule to catch Github release events and run a custom bash script. It is run by adnanh/webhook which is a small go app that can run your deployment script. You then configure GitHub to send release events as per this screenshot:

enter image description here

You can then use the github hub command line tool to create releases with a name that matches the regex in the hook rule e.g., v1.2.3. That will fire the release webhook. That can be caught by your deploy script running in a container on your server. Your deploy script can take the release number parsed from the release event payload. It can then git pull the git tag v1.2.3 launch your code. Note that you don’t have to use the hub cli a release event will also be fired if you push a tag to your repo using regular git. We find it helpful to use the hub tool that creates the tag and a github release. You can attach automatically generated release notes using github_changelog_generator see this example script.

Using similar webhooks is how OCD can drive kubernetes from configuration in GitHub. We have OCD deploy all our apps on AWS based on configuration and tags in GitHub. You can use the same techniques to drive your small deployment scripts quite easily. All you need to do is create docker container with adnanh/webhook, the json config and your deploy script. Here is a where we install webhook into a container and here is where we copy our rules. As it is a go app it doesn’t need a lot of memory to be able to fully automate your software based on git webhook events.

3
  • Wow amazing! This makes it so much easier! Thank you for brief explanation, hats off to you, sir Apr 10, 2019 at 9:57
  • OCD will take release events and build a new container when the code and tag that container with the same tag. It will also catch push events to master in a config repo then sync all the configuration into our environments such as encrypted passwords. Obviously that is all for Kubernetes but it's all just shell scripts driven by that little Webhook go app which is so very useful.
    – simbo1905
    Apr 10, 2019 at 15:04
  • I have added a note about github_changelog_generator which you might find helpful
    – simbo1905
    Apr 14, 2019 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.