模拟生产环境中的代码上线实战篇

                  模拟生产环境中的代码上线实战篇

                                     作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.代码上线流程

 

二.开发人员做的事情

1>.模拟开发人员编写的测试代码

#!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com

import random

def ValdateCode(number=5):
    res = ""
    for i in range(number):
        num = random.randint(1, 9)
        string = chr(random.randint(97,122))
        s = random.choice([str(num),string])
        res += s
    return res

res = ValdateCode(10)
print(res)

2>.测试代码是是否可以成功运行

 

3>.提交代码到GitLab

4>.进行push操作

5>.push成功界面

6>.查看GitLab是否push成功

三.运维人员做的事情

1>.在服务器端拉取(pull)代码

[root@yinzhengjie yinzhengjieCode]# pwd
/root/yinzhengjieCode
[root@yinzhengjie yinzhengjieCode]# 
[root@yinzhengjie yinzhengjieCode]# ll
total 4
-rw-r--r-- 1 root root 70 Sep  9 07:13 README.md
[root@yinzhengjie yinzhengjieCode]# 
[root@yinzhengjie yinzhengjieCode]# git pull
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (11/11), done.
From www.yinzhengjie.org.cn:root/yinzhengjieCode
   a697c69..317317e  master     -> origin/master
 * [new branch]      yinzhengjie-pycharm -> origin/yinzhengjie-pycharm
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
[root@yinzhengjie yinzhengjieCode]# 
[root@yinzhengjie yinzhengjieCode]# ll
total 8
-rw-r--r-- 1 root root 341 Sep  9 07:13 README.md
-rw-r--r-- 1 root root 484 Sep  9 07:13 VerificationCode.py
[root@yinzhengjie yinzhengjieCode]# 
[root@yinzhengjie yinzhengjieCode]#

2>.运维需要运行代码,检查是否可以正常运行

  代码上线处理步骤:

        2.1>.当你测试代码运行失败时,需要找开发解决问题;

        2.2>.当你测试代码运行成功时,需要告知你的上司,当公司的领导说可以上线了,你才能上线代码;

        2.3>.当上线代码时,你应该讲之前稳定的代码进行备份;

        2.4>.上线新的代码,加入生成环境中出现不稳定的状况,需要及时复原之前的数据,这个时候你备份的操作就显得尤为重要;

        2.5>.这些操作你可以写成脚本来完成,当然你也可以使用git+Jenkins来实现代码自动发布;

原文地址:https://www.cnblogs.com/yinzhengjie/p/9576475.html