mirror of https://gitee.com/anolis/sysom.git
!852 修改sysom_hotfix_builder的部署方式
Merge pull request !852 from ydjohn/master
This commit is contained in:
commit
6def344d22
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
SERVICE_NAME=sysom-hotfix-builder
|
||||
|
||||
clear_app() {
|
||||
LOCAL_NFS_HOME=${SERVER_HOME}/builder/hotfix
|
||||
umount $LOCAL_NFS_HOME
|
||||
rm -rf /etc/supervisord.d/${SERVICE_NAME}.ini
|
||||
###use supervisorctl update to stop and clear services###
|
||||
supervisorctl update
|
||||
}
|
||||
|
||||
clear_app
|
|
@ -0,0 +1,56 @@
|
|||
#! /bin/bash
|
||||
SERVER_DIR="sysom_server"
|
||||
HOTFIX_BUILDER_DIR=${SERVER_DIR}/sysom_hotfix_builder
|
||||
VIRTUALENV_HOME=${SERVER_HOME}/virtualenv
|
||||
SERVICE_NAME=sysom-hotfix-builder
|
||||
NFS_SERVER_IP=127.0.0.1
|
||||
|
||||
source_virtualenv() {
|
||||
echo "INFO: activate virtualenv..."
|
||||
source ${VIRTUALENV_HOME}/bin/activate || exit 1
|
||||
}
|
||||
|
||||
init_conf() {
|
||||
cp ${SERVICE_NAME}.ini /etc/supervisord.d/
|
||||
}
|
||||
|
||||
install_package() {
|
||||
|
||||
rpm -q --quiet make gcc patch bison flex openssl-devel elfutils elfutils-devel dwarves || yum install -y make gcc patch bison flex openssl-devel elfutils elfutils-devel dwarves || exit 1
|
||||
|
||||
rpm -q --quiet docker git || yum install -y docker git || exit 1
|
||||
}
|
||||
|
||||
mount_nfs()
|
||||
{
|
||||
HOTFIX_NFS_HOME=${SERVER_HOME}/hotfix_builder/hotfix-nfs
|
||||
LOCAL_NFS_HOME=${SERVER_HOME}/builder/hotfix
|
||||
|
||||
mkdir -p ${LOCAL_NFS_HOME}
|
||||
|
||||
sudo umount $LOCAL_NFS_HOME # Remove the mounted directory in case it mounted before
|
||||
sudo mount -t nfs ${NFS_SERVER_IP}:${HOTFIX_NFS_HOME} ${LOCAL_NFS_HOME} || exit 1
|
||||
}
|
||||
|
||||
start_app() {
|
||||
###if supervisor service started, we need use "supervisorctl update" to start new conf####
|
||||
supervisorctl update
|
||||
supervisorctl status ${SERVICE_NAME}
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "supervisorctl start ${SERVICE_NAME} success..."
|
||||
return 0
|
||||
fi
|
||||
echo "${SERVICE_NAME} service start fail, please check log"
|
||||
exit 1
|
||||
}
|
||||
|
||||
deploy() {
|
||||
source_virtualenv
|
||||
init_conf
|
||||
install_package
|
||||
mount_nfs
|
||||
start_app
|
||||
}
|
||||
|
||||
deploy
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
SERVICE_NAME=sysom-hotfix-builder
|
||||
|
||||
start_app() {
|
||||
supervisorctl start $SERVICE_NAME
|
||||
}
|
||||
|
||||
start_app
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
SERVICE_NAME=sysom-hotfix-builder
|
||||
|
||||
stop_app() {
|
||||
supervisorctl stop $SERVICE_NAME
|
||||
}
|
||||
|
||||
stop_app
|
|
@ -0,0 +1,9 @@
|
|||
[program:sysom-hotfix-builder]
|
||||
directory = /usr/local/sysom/server/target/sysom_server/sysom_hotfix_builder
|
||||
command=/usr/local/sysom/server/virtualenv/bin/python3 builder.py
|
||||
startsecs=3
|
||||
autostart=true
|
||||
autorestart=true
|
||||
environment=PATH=/usr/local/sysom/server/virtualenv/bin:%(ENV_PATH)s
|
||||
stderr_logfile=/usr/local/sysom/server/logs/sysom-hotfix-builder-error.log
|
||||
stdout_logfile=/usr/local/sysom/server/logs/sysom-hotfix-builder.log
|
|
@ -22,5 +22,8 @@
|
|||
[hotfix]
|
||||
6_sysom_hotfix
|
||||
|
||||
[hotfix-builder]
|
||||
6_sysom_hotfix_builder
|
||||
|
||||
# [demo]
|
||||
# 7_sysom_demo
|
||||
|
|
|
@ -14,8 +14,10 @@ import json
|
|||
import platform
|
||||
import shutil
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
from cec_base.consumer import Consumer, dispatch_consumer
|
||||
from cec_base.admin import dispatch_admin
|
||||
|
||||
class ServerConnector():
|
||||
|
||||
|
@ -105,6 +107,14 @@ class HotfixBuilder():
|
|||
self.token = self.connector.get_token()
|
||||
self.prepare_env()
|
||||
|
||||
##################################################################
|
||||
# Logging config
|
||||
##################################################################
|
||||
from cec_base.log import LoggerHelper, LoggerLevel
|
||||
log_format = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level}</level> | <cyan>{file.path}</cyan>:<cyan>{line}</cyan> | {message}"
|
||||
LoggerHelper.add(sys.stdout, level=LoggerLevel.LOGGER_LEVEL_INFO, format=log_format, colorize=True)
|
||||
LoggerHelper.add(sys.stderr, level=LoggerLevel.LOGGER_LEVEL_WARNING, format=log_format, colorize=True)
|
||||
|
||||
def run(self):
|
||||
self.thread_runner.start()
|
||||
|
||||
|
@ -115,7 +125,7 @@ class HotfixBuilder():
|
|||
output = process.read()
|
||||
|
||||
# get the img_list image information and pull them based on machine's kernel arch
|
||||
image_config_file = open("./img_list.json")
|
||||
image_config_file = open(os.path.join(os.getcwd(), "img_list.json"))
|
||||
config_data = json.load(image_config_file)
|
||||
machine_kernel = platform.uname().release
|
||||
arch = machine_kernel.split(".")[-1]
|
||||
|
@ -283,7 +293,7 @@ class HotfixBuilder():
|
|||
except Exception as e:
|
||||
f.write(str(e))
|
||||
logger.error(str(e))
|
||||
self.connector.change_building_status(hotfix_id, "failed")
|
||||
# self.connector.change_building_status(hotfix_id, "failed")
|
||||
|
||||
f.write("Created Hotfix Building Task ... \n")
|
||||
f.write("Kernel Version: %s\n" % kernel_version)
|
||||
|
@ -293,7 +303,7 @@ class HotfixBuilder():
|
|||
|
||||
description = "hello world"
|
||||
# run the build hotfix script
|
||||
cmd = "sudo docker run --rm -v {}:{} -v {}:{} -v {}:{} -v {}:{} --net=host {} sh {}/build_hotfix.sh -p {} -k {} -d {} -b {} -n {} -g {} -r {}".format(
|
||||
cmd = "docker run --rm -v {}:{} -v {}:{} -v {}:{} -v {}:{} --net=host {} sh {}/build_hotfix.sh -p {} -k {} -d {} -b {} -n {} -g {} -r {}".format(
|
||||
self.hotfix_base, self.hotfix_base, self.nfs_dir_home, self.nfs_dir_home, self.builder_hotfix_package_repo, self.builder_hotfix_package_repo, self.tmpdir, self.tmpdir, image,
|
||||
self.hotfix_base, local_patch, kernel_version, description, self.hotfix_base, hotfix_name, log_file_path, source_code_repo
|
||||
)
|
||||
|
@ -380,7 +390,7 @@ class HotfixBuilder():
|
|||
description = "hello world"
|
||||
|
||||
# run the build hotfix script
|
||||
cmd = "sudo docker run --rm -v {}:{} -v {}:{} -v {}:{} -v {}:{} --net=host {} sh {}/build_hotfix.sh -p {} -k {} -d {} -b {} -n {} -g {} -c {} -v {} -r {} -t {}".format(
|
||||
cmd = "docker run --rm -v {}:{} -v {}:{} -v {}:{} -v {}:{} --net=host {} sh {}/build_hotfix.sh -p {} -k {} -d {} -b {} -n {} -g {} -c {} -v {} -r {} -t {}".format(
|
||||
self.hotfix_base, self.hotfix_base, self.nfs_dir_home, self.nfs_dir_home, self.builder_hotfix_package_repo, self.builder_hotfix_package_repo, self.tmpdir, self.tmpdir, image,
|
||||
self.hotfix_base, local_patch, kernel_version, description, self.hotfix_base, hotfix_name, log_file_path, kernel_config, vmlinux, source_code_repo, git_branch
|
||||
)
|
||||
|
@ -419,29 +429,34 @@ class HotfixBuilder():
|
|||
event.value is a dictionary.
|
||||
'''
|
||||
def build(self):
|
||||
with dispatch_admin(self.cec_url) as admin:
|
||||
if not admin.is_topic_exist(self.cec_hotfix_topic):
|
||||
admin.create_topic(self.cec_hotfix_topic)
|
||||
consumer_id = Consumer.generate_consumer_id()
|
||||
consumer = dispatch_consumer(self.cec_url, self.cec_hotfix_topic,
|
||||
consumer_id=consumer_id,
|
||||
group_id="hotfix_job_group")
|
||||
while True:
|
||||
for event in consumer:
|
||||
# get one event from cec, if match the arch, ack this event
|
||||
parameters = event.value
|
||||
if parameters['arch'] != self.local_arch:
|
||||
break
|
||||
consumer.ack(event)
|
||||
for event in consumer:
|
||||
# get one event from cec, if match the arch, ack this event
|
||||
parameters = event.value
|
||||
if parameters['arch'] != self.local_arch:
|
||||
break
|
||||
|
||||
# for each run, update the repo
|
||||
cmd = "chmod +x check_env.sh && ./check_env.sh -b %s -n %s" % (self.hotfix_base, self.nfs_dir_home)
|
||||
with os.popen(cmd) as process:
|
||||
output = process.read()
|
||||
# for each run, update the repo
|
||||
cmd = "chmod +x check_env.sh && ./check_env.sh -b %s -n %s" % (self.hotfix_base, self.nfs_dir_home)
|
||||
with os.popen(cmd) as process:
|
||||
output = process.read()
|
||||
|
||||
customize = parameters['customize']
|
||||
customize = parameters['customize']
|
||||
|
||||
if not customize:
|
||||
self.build_supported_kernel(parameters)
|
||||
else:
|
||||
self.build_customize_kernel(parameters)
|
||||
|
||||
consumer.ack(event)
|
||||
|
||||
|
||||
if not customize:
|
||||
self.build_supported_kernel(parameters)
|
||||
else:
|
||||
self.build_customize_kernel(parameters)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue