Automatic update of release code via git webhooks+ script

Source: Internet
Author: User

Demand:

Write an automated deployment script that automatically updates the release code according to the Git Push action (patch file (or update file, patch for short))

Solution:

With git webhooks, Python scripts, and Linux shell scripts, all actions are done automatically, and the manual part is limited to the release of patch files

    • git webhooks implementation triggers execution script

    • Python scripts are used to receive post data from Git webhooks and determine whether to execute shell scripts based on this data

    • Linux shell scripts for operations such as deployment, backup, rollback, etc.

Specific steps (scenario implementation): The principle of implementation:

After the user has written the patch, in addition to push the patch file to Git, Writes the path of the patch file and related operations to the specified file (for example, the name update.conf, the short profile), the Automated Deployment script (hereinafter referred to as the script) performs the relevant operations on the production server based on the configuration file, assigns the files the correct permissions, and clears the cache if it needs to be cached (about whether you need to Clear the cache, which can be obtained from the specified file mentioned above, and restart related services as needed

Conventions about specifying file formats. You can follow the following format:

file    path/to/filename1      addfile     path/to/filename2      removefile    path/to/filename3       updatefile    path/to/filename4       addconfig  cleancache              enableconfig  cleancache              disableconfig  restartservice          enableconfig  restartservice          disabletarget  serverid              ...     ...                    &NBSP, ..... 
    • File represents the patch file, path/to/filename1 represents the path to the files, add, remove, and update indicate the action of the file execution

    • Config indicates configuration, clears cache and restarts service, and is determined by enable and disable

    • Target represents the IP or hostname of the production server, and each target can be ssh-connected by an update server

The work and steps of the script completion (some are principles and related explanations):
    1. The GIT server triggers the webhooks action on the GIT service based on the user's git push action, and the GIT servers post the JSON data to the update server

    2. The update server captures JSON data sent from the Git service, obtains repository URLs and branch, and, depending on the information in the JSON, determines whether git fetch is required to get the patch files, and whether the deployment action needs to be performed

    3. When performing a deployment operation, the update server backs up the code on the production server to a backup server or other backup location on the production server, depending on the configuration file above to decide whether to add or remove files, whether to clear the cache and whether to restart the service

    4. The update server can ssh to the production server, file operations, clear cache and restart the service commands are all done via SSH

    5. Detects the relevant API, determines whether the update is successful, logs the update log if the update is successful, rolls back the file if the update fails, and then decides whether to clear the cache and restart the service if necessary

Tag:git WebHooks, automated deployment, shell scripting, Python Basehttpserver,python receive WebHooks

--end--

This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1734297

Automatic update of release code via git webhooks+ script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.