[Tools] operation and maintenance systems Git code release

introduction

Code Publishing System is an Internet company the necessary operation and maintenance system, the role of the main business users to publish code to the server business

Why do you need the code distribution system

Some students may say that our company server so one, to be a publishing system is too cumbersome? I do not agree with this statement


Distribution system has the following advantages

  1. Process management, plus rights management , you can keep track of who did what in the operating system

  2. Reduce human error affected the login server operation itself is possible misuse of

  3. Operation and maintenance of automation for the operation and maintenance burdens

  4. Facilitate publication without manual login N servers released

  5. Fast and easy rollback version


Technology Selection

git: code management tool   git use notes

rsync: a synchronization code to specify the server

Yii2: php mvc framework

Bootstrap3: front-end framework

jquery: js library

Code Publishing System

FIG flow frame

600

  1. Web interface operation, process management, submission publishing tasks

  2. Timing script gets publishing tasks

  3. Develop synchronization strategy release code

Interface operation, process management

Process management personnel more time particularly evident advantages, many people hand-mixed easily go wrong. So join in the code release process management system is also advancing with the times


600


The figure is a more complete flow diagram I drew (before the company realized in such a complicated process), as described below

  1. New development branch

  2. Local development and commit code

  3. Publish to test server

  4. Testers test

  5. After waiting for approval by the test line executive (not by re-take the test steps 2-4)

  6. Published on-line

  7. Project Manager product acceptance

  8. Project completion


PS: 1,3,6 which is the business logic (scripts need help), others are flow control

Timing script gets publishing tasks

Through process control tasks will be published on-line push queue to go, you need to have scripting consumer queue tasks, on the timing of the script I did not choose to use crontab, the lowest since the beginning of the crontab is not satisfied minute business needs, it is recommended to write a permanent memory the shell, the following run once every 2 seconds

#!/bin/sh
cmd='php yii release/index'
while true
do
    if [ $(ps -ef |grep  '$cmd' |grep -v grep|wc -l) -eq 0 ];then
        eval $cmd
        sleep 3;
    else
        echo 'queue is Running';
    fi
done


Script release / index Source Address: https://github.com/apanly/dream/blob/master/console/controllers/ReleaseController.php 


Link configuration

'ops_repo' => [
   "dream_blog" => [
      'title' => '博客',
      'feature' => [
         'path' => '/home/www/yii_tools/tools'
      ],
      'remote' => [
         'hosts' => [  ],
         'path' => '/home/www/yii_tools/dream',
         'ssh_param' => ' -i /home/www/.ssh/publish_rsa  www@'
      ],
      'version' => [
         '/tmp/release_version/version_blog'
      ]
   ]
]

Develop synchronization strategy release code

About synchronization strategy I practiced several, using different strategies depending on the situation, only the following is a personal experience


  • Excess separate service server 10 is recommended to use less than 20 rsync pushed to the target server (in this case, if the operation git directly on the target server is slow, and the source server little high load)

  • Fewer than 10 separate business server implementation of the recommendations git commands directly on the target server (of course, you can also rsync)



Examples show

600

(Figure 1)


600

(Figure II)


600

(Figure 3)


600

(Figure IV)


  • Figure 1: shows the task list is released

  • Figure 2: shows task is to add a release operation

  • Figure 3: shows the release of the task execution process instruction executed

  • Figure 4: is a supplement to Figure III, because I blog system is very simple and there is no remote (remote) server, just update the local server, so the Figure Four shots is original in the company doing system release remote code output of the Figure III remote objects supplement


PS: operation object version is the version number of the operation, the role of two


  1. Static resource plus a version number, the browser will visit (action to achieve penetration browser cache) re-requested resources

  2. Version rollback


As shown below


600


Reference material

  1. Use git notes

  2. [RBAC] to create a Web access control system


Original Address: [tool] operation and maintenance systems Git code released
Tags: git    distribution system    operation and maintenance    rsync   

Intelligent Recommendation

Reproduced in: https: //my.oschina.net/54php/blog/791750

Guess you like

Origin blog.csdn.net/weixin_34095889/article/details/91634920