Skip to content

Commit

Permalink
update clone project
Browse files Browse the repository at this point in the history
  • Loading branch information
deploy committed Apr 26, 2020
1 parent 9203a4c commit 3e4c2b9
Show file tree
Hide file tree
Showing 8 changed files with 809 additions and 861 deletions.
80 changes: 34 additions & 46 deletions app/main/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,13 @@

def project_info(project):
print(project)
sql = "SELECT * FROM `projectinfo` WHERE project_name = '%s';" % (project)
c.execute(sql)
ones = c.fetchall()
return ones[0]

def config_info(project):
print(project)
sql = "SELECT * FROM `project_config` WHERE project_name = '%s';" % (project)
sql = "SELECT * FROM `projectinfo` WHERE project = '%s';" % (project)
c.execute(sql)
ones = c.fetchall()
return ones[0]

def gethostname(project):
sql = "SELECT `ip`,`hostname`,`pnum` FROM `serverinfo` WHERE project_name = '%s';" % (project)
sql = "SELECT `ip`,`hostname`,`pnum` FROM `serverinfo` WHERE project = '%s';" % (project)
c.execute(sql)
ones = c.fetchall()
hostnameinfo = {}
Expand Down Expand Up @@ -78,35 +71,30 @@ def __init__(self, project, tag, taskid, hostlist, operation, currentuser, reaso
self.reason = reason

pinfo = project_info(project)
cinfo = config_info(project)
self.hostnameinfo = gethostname(project)
self.workorderinfo = getworkorder(project)

print(pinfo)
print(cinfo)
print(self.hostnameinfo)
print(self.workorderinfo)

self.business = pinfo[1]
self.group = pinfo[1]
self.environment = pinfo[2]
self.p = pinfo[3]
self.Type = pinfo[4]
self.codetype = pinfo[4]
self.port = int(pinfo[5])
self.git = pinfo[6]
self.branch = pinfo[7]

self.checkport = pinfo[8]
self.checkhttp = pinfo[9]
self.httpurl = pinfo[10]
self.httpcode = pinfo[11]

self.make = cinfo[1]
self.supervisor = cinfo[2]
self.config = cinfo[3]
self.remarks = cinfo[4]
self.startcmd = cinfo[5]
self.packfile = cinfo[6]
self.istag = cinfo[7]
self.checkport = cinfo[8]
self.checkhttp = cinfo[9]
self.httpurl = cinfo[10]
self.httpcode = cinfo[11]
self.make = pinfo[12]
self.supervisor = pinfo[13]
self.config = pinfo[14]
self.remarks = pinfo[15]

self.host = 'Deploy'
self.hostName = 'Deploy'
Expand All @@ -117,7 +105,7 @@ def __init__(self, project, tag, taskid, hostlist, operation, currentuser, reaso

self.execUser = exec_user
self.basicGlist = basicGlist
self.businessRobot = businessRobot
self.groupRobot = groupRobot
self.sreRobot = sreRobot
self.autotestURL = autotestURL
self.autolist = autolist
Expand Down Expand Up @@ -212,15 +200,15 @@ def serviceStop(self):
pnum = self.hostnameinfo[self.host][1]
for port in range(self.port, self.port + pnum):
self.removeService(port)
self.stop[self.Type](port)
self.stop[self.codetype](port)

def serviceRestart(self):
pnum = self.hostnameinfo[self.host][1]
for port in range(self.port, self.port + pnum):
self.addlog('\nDel Service Start:')
self.removeService(port)
self.addlog('\nRestart Service:')
self.restart[self.Type](port)
self.restart[self.codetype](port)
self.addlog('\nCheck Start:')
self.check_status(port)
self.http_check(port)
Expand All @@ -230,14 +218,14 @@ def serviceRestart(self):
self.increaseService(port)

def serviceUpdate(self):
self.rsyncCode[self.Type]()
self.rsyncCode[self.codetype]()
self.serviceRestart()

def serviceFastback(self):
self.rsyncCode[self.Type]()
self.rsyncCode[self.codetype]()
pnum = self.hostnameinfo[self.host][1]
for port in range(self.port, self.port + pnum):
self.restart[self.Type](port)
self.restart[self.codetype](port)


def currenthost(self, host):
Expand All @@ -255,7 +243,7 @@ def addlog(self, newlog):
def updateHostCommit(self):
if self.commitid:
sql = "update `serverinfo` set `commitid`='%s',`updatetime`='%s' \
where project_name='%s' and ip='%s'; " % (
where project='%s' and ip='%s'; " % (
self.commitid, self.tag, self.project, self.host)
try:
c.execute(sql)
Expand All @@ -265,7 +253,7 @@ def updateHostCommit(self):

def updateTaskStatus(self):
sql = "update `updateoperation` set `status`='%s',`tag`='%s',`commitid`='%s' \
where project_name='%s' and taskid='%s'; " % (
where project='%s' and taskid='%s'; " % (
self.status, self.tag, self.commitid, self.project, self.taskid)
try:
c.execute(sql)
Expand All @@ -275,7 +263,7 @@ def updateTaskStatus(self):

def updateProgress(self):
self.progress = self.progress + 1
sql = "update `updateoperation` set `progress`=%d where project_name='%s' and taskid='%s';" % (self.progress, self.project, self.taskid)
sql = "update `updateoperation` set `progress`=%d where project='%s' and taskid='%s';" % (self.progress, self.project, self.taskid)
print(sql)
try:
c.execute(sql)
Expand Down Expand Up @@ -305,8 +293,8 @@ def notice(self):
content = "%s %s: %s\n%s\n操作人: %s" %(
self.project, self.operation, self.status, HL, self.currentuser)

if self.business in self.basicGlist:
self.dingding(self.businessRobot, content)
if self.group in self.basicGlist:
self.dingding(self.groupRobot, content)

def expansion_notice(self):
if self.environment != 'online':
Expand All @@ -321,7 +309,7 @@ def expansion_notice(self):

def getlastokstatus(self):
sql = "SELECT `tag`,`commitid` FROM `updateoperation` \
WHERE project_name = '%s' and operation = 'serviceUpdate' and status = 'ok' \
WHERE project = '%s' and operation = 'serviceUpdate' and status = 'ok' \
order by taskid desc limit 1;" % (self.project)
c.execute(sql)
ones = c.fetchall()
Expand Down Expand Up @@ -400,7 +388,7 @@ def makeUpdate(self):
self.addlog('\nCode Compile:')
self.make_operation()
self.makestatus = 'yes'
self.tag_operation()
#self.tag_operation()
self.addlog('\nVersion Backup:')
self.backup_operation()
self.write_commitid()
Expand All @@ -423,7 +411,7 @@ def makeExpansion(self):
self.local_commitid()

def code_update(self):
if self.Type == 'go':
if self.codetype == 'go':
shell_cmd = ''' rm -rf %s/%s ; git clone --depth=1 -b %s %s %s/%s && cd %s/%s && git log -n 1 --stat
''' %(self.dir_path_git, self.project, self.branch, self.git, self.dir_path_git, self.project, self.dir_path_git, self.project )
self.exec_shell(shell_cmd)
Expand Down Expand Up @@ -481,7 +469,7 @@ def build_file_operation(self):
self.faildone('%s/%s-%s/ directory does not exist. build_file_operation'
%(self.dir_path_git, self.project, self.tag) )

if self.Type == 'golang':
if self.codetype == 'golang':
shell_cmd = "cd %s/%s-%s && rm -rf deploy-etc/ deploy-bin/etc && mkdir -p deploy-bin && git clone --depth=1 %s deploy-etc && cp -a deploy-etc/etc deploy-bin/etc " %(self.dir_path_git, self.project, self.tag, self.supervisor.strip() )
self.exec_shell(shell_cmd)
shell_cmd = '''cd %s/%s-%s && cp -a startdata libs deploy-bin/ ''' %(
Expand All @@ -499,7 +487,7 @@ def build_file_operation(self):
def make_operation(self):
if self.make:
make_start_time = time.strftime('%Y-%m-%d %H:%M:%S')
if self.Type == 'golang':
if self.codetype == 'golang':
shell_cmd = '''cd %s/%s && . $HOME/.bashrc \
&& sh deploy_build.sh %s %s
''' %(self.dir_path_git, self.project, self.project, self.make)
Expand All @@ -512,11 +500,11 @@ def make_operation(self):
self.addlog('make_done_time: %s' %(make_done_time))


def tag_operation(self):
if self.istag == 'yes':
shell_cmd = "cd %s/%s && git tag %s-%s && git push origin --tags" %(
self.dir_path_git, self.project, self.project, self.tag)
self.exec_shell(shell_cmd)
#def tag_operation(self):
# if self.istag == 'yes':
# shell_cmd = "cd %s/%s && git tag %s-%s && git push origin --tags" %(
# self.dir_path_git, self.project, self.project, self.tag)
# self.exec_shell(shell_cmd)

def write_commitid(self):
self.addlog('INFO: write_commitid')
Expand Down Expand Up @@ -687,7 +675,7 @@ def removeService(self, port = None):
if self.operation == 'serviceExpansion':
return 'not removeService'

if self.Type == 'golang':
if self.codetype == 'golang':
consul_port = port - 3000
consul_srv_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
consul_srv_sock.settimeout(2)
Expand Down
40 changes: 20 additions & 20 deletions app/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def hostInit(project, host, Type):
return Result['status']


def deployConfig(project, host, ones, ones1, ones2):
def deployConfig(project, host, ones, ones1):
try:
if ones.type in supervisord_list:
if ones.codetype in supervisord_list:
DIR = getdir(project)

supervisor_conf = ones2.supervisor
supervisor_conf = ones.supervisor

variable = {
'$USER$': exec_user,
Expand Down Expand Up @@ -149,7 +149,7 @@ def logHandle(logtext):

return result

crontab_conf = '''#01 01 * * * $HOST_PATH$$environment$_$project$/deploy_start.sh >> $supervisor_log_path$/$environment$_$project$.log 2>&1
crontab_conf = '''#01 01 * * * $HOST_PATH$$project$/deploy_start.sh >> $supervisor_log_path$/$project$.log 2>&1
'''


Expand All @@ -158,10 +158,10 @@ def logHandle(logtext):
'''


supervisor_python_conf = '''[program:$environment$_$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT_NAME=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$environment$_$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$environment$_$project$/
command=/usr/bin/python $HOST_PATH$$environment$_$project$/main.py --port=%(process_num)02d
supervisor_python_conf = '''[program:$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$project$/
command=/usr/bin/python $HOST_PATH$$project$/main.py --port=%(process_num)02d
process_name=%(process_num)d
user=$USER$
startretries=5
Expand All @@ -177,10 +177,10 @@ def logHandle(logtext):
numprocs_start=$port$
'''

supervisor_nodejs_conf = '''[program:$environment$_$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT_NAME=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$environment$_$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$environment$_$project$/
command=/usr/bin/node $HOST_PATH$$environment$_$project$/index.js --port=%(process_num)d
supervisor_nodejs_conf = '''[program:$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$project$/
command=/usr/bin/node $HOST_PATH$$project$/index.js --port=%(process_num)d
process_name=%(process_num)d
user=$USER$
startretries=5
Expand All @@ -196,10 +196,10 @@ def logHandle(logtext):
numprocs_start=$port$
'''

supervisor_go_conf = '''[program:$environment$_$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT_NAME=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$environment$_$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$environment$_$project$/
command=$HOST_PATH$$environment$_$project$/bin/$project$ -f $HOST_PATH$$environment$_$project$/etc/$environment$_$project$.conf
supervisor_go_conf = '''[program:$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$project$/
command=$HOST_PATH$$project$/bin/$project$ -f $HOST_PATH$$project$/etc/$project$.conf
process_name = %(process_num)d
user=$USER$
startretries=5
Expand All @@ -214,10 +214,10 @@ def logHandle(logtext):
'''

supervisor_sh_conf = '''[program:$environment$_$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT_NAME=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$environment$_$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$environment$_$project$/
command=/bin/bash $HOST_PATH$$environment$_$project$/deploy_start.sh --port=%(process_num)d
supervisor_sh_conf = '''[program:$project$]
environment=HOME=/home/$USER$,PROJECT_ENV="$environment$",PROJECT=$project$,PROJECT_PORT=$port$,PROJECT_PATH="$HOST_PATH$$project$/",PRODUCT_ENV="",$env$
directory=$HOST_PATH$$project$/
command=/bin/bash $HOST_PATH$$project$/deploy_start.sh --port=%(process_num)d
process_name = %(process_num)d
user=$USER$
startretries=5
Expand Down
Loading

0 comments on commit 3e4c2b9

Please sign in to comment.