Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement auto-update functionality for web application on multiple server? [closed]

I need an idea how to implement following
1. Want to build python application which will update itself when the new patch is available
2. It will run the unit test to check if the patch deployed successfully
3. If there are any failure during installation it will rollback automatically

What I don't know
A. Not sure how to build a patch from the source code
B. Algorithm / standard process to check about the new updates are available
C. Auto deployment/Rollback process

Any suggestions/ links?

like image 731
Dev Avatar asked Oct 01 '22 16:10

Dev


1 Answers

I implementeed a server that recognizes the changed source code and pulls the new code. It is hosted at pythonanywhere.com at this url and the code is on github. This answer bases on my experiences when implementing the update functionality.

When you version your code with git you usually

  • have a master or deploy branch that works
  • have a develop branch that is merged into the master-->deploy branch when all the tests run through.

This way you only need to know when the deploy branch changes in order to figure out when to restart. Tests should be run before in order to have no downtime. If you run the tests on the deploy system it may take them too much time or the invalid code destroys the system. So the deploy branch works because it was tested before.

For automated testing you can use a continous integration server like travis that downloads the code and tests it. It can be asked about whether the test run of a specific commit.

When you host your code on github then you can specify a push http address. I used http://server/update Whenever the repository is changed github notifies your server then.

You can then update the source code by pulling it from git and if the deploy branch really changed then you can restart the application. I can not do this in the server ut maybe you can.

Scenario:

  1. I push code to github
  2. github sends a POST to http://server/update
  3. @post('/update') # bottle code
    def pull_own_source_code_and_restart():
        with inDirectory(server_repository):
            previous_commit = last_commit()
            text = git.pull()
            current_commit = last_commit()
        if previous_commit != current_commit:
            restart()
        return "Git says: {}".format(text)
    

    have a look at these two files:

    • command_line.py for the git commands
    • bottle_app.py for a derivating implementation if the server can not restart itself.

A version control system usually does the 'patching' for every version. I use git. If git is unknown to you now, learn it! Here is workshop material for Pythons Django and git: http://www.opentechschool.org/material.html

Let me now if this information is sufficient to implement such a functionality in Django. Please post your code here when you got it to work.

like image 53
User Avatar answered Oct 13 '22 10:10

User