update appstore

This commit is contained in:
qiaofeng1227 2023-07-24 14:47:20 +08:00
parent ee658da3cf
commit 778897faaa
6 changed files with 97 additions and 7 deletions

View file

@ -3,7 +3,7 @@ name: Push to main branch
on:
push:
branches:
- main
- mains
jobs:
ci-test:

View file

@ -1,6 +1,6 @@
FROM python:3.10-slim
LABEL maintainer="Websoft9<help@websoft9.com>"
LABEL version="0.8.1"
LABEL version="0.8.2"
# Create API Directory
WORKDIR /usr/src/app

View file

@ -36,11 +36,37 @@ redis_conn = Redis(host='websoft9-redis', port=6379)
q = Queue(connection=redis_conn, default_timeout=3600)
def auto_update():
myLogger.info_logger("auto update")
shell_execute.execute_command_output_all("rm -rf /tmp/update_appstore.sh")
shell_execute.execute_command_output_all("cd /tmp && wget https://websoft9.github.io/websoft9/install/update_appstore.sh")
shell_execute.execute_command_output_all("bash /tmp/update_appstore.sh 1>/dev/null 2>&1")
myLogger.info_logger("auto update start...")
local_path = '/usr/share/cockpit/appstore/appstore.json'
local_version = "0"
try:
op = shell_execute.execute_command_output_all("cat " + local_path)['result']
local_version = json.loads(op)['Version']
except:
local_version = "0.0.0"
download_url = const.ARTIFACT_URL + "/plugin/appstore-latest.zip"
cmd = "cd /opt && wget " + download_url + " && unzip appstore-latest.zip "
shell_execute.execute_command_output_all(cmd)
latest = shell_execute.execute_command_output_all("cat /opt/appstore/appstore.json")
version = json.loads(latest)['Version']
ret = {}
ret['current_version'] = local_version
if compared_version(local_version, version) == -1:
shell_execute.execute_command_output_all("rm -rf /usr/share/cockpit/appstore && cp /opt/appstore /usr/share/cockpit")
shell_execute.execute_command_output_all("rm -rf /opt/appstore*")
library_url = const.ARTIFACT_URL + "/plugin/library-latest.zip"
library_cmd = "cd /opt && wget " + library_url + " && unzip library-latest.zip "
shell_execute.execute_command_output_all(library_cmd)
shell_execute.execute_command_output_all("rm -rf /data/library && cp /opt/library /data")
shell_execute.execute_command_output_all("rm -rf /opt/library*")
myLogger.info_logger("auto update success...")
else:
shell_execute.execute_command_output_all("rm -rf /opt/appstore*")
myLogger.info_logger("Appstore is latest, not need to update.")
scheduler = BackgroundScheduler()
scheduler.add_job(auto_update, 'cron', hour=1)
scheduler.start()
@ -133,6 +159,45 @@ def get_update_list():
ret['Update_content']=None
return ret
# 获取 appstore update info
def get_appstore_update_list():
local_path = '/usr/share/cockpit/appstore/appstore.json'
local_version = "0"
try:
op = shell_execute.execute_command_output_all("cat " + local_path)['result']
local_version = json.loads(op)['Version']
except:
local_version = "0.0.0"
download_url = const.ARTIFACT_URL + "/plugin/appstore-latest.zip"
cmd = "cd /opt && wget " + download_url + " && unzip appstore-latest.zip "
shell_execute.execute_command_output_all(cmd)
latest = shell_execute.execute_command_output_all("cat /opt/appstore/appstore.json")
version = json.loads(latest)['Version']
ret = {}
ret['current_version'] = local_version
if compared_version(local_version, version) == -1:
content = []
change_log_contents = shell_execute.execute_command_output_all("cat /opt/appstore/CHANGELOG.md")['result']
change_log = change_log_contents.split('## ')[1].split('\n')
date = change_log[0].split()[-1]
for change in change_log[1:]:
if change != '':
content.append(change)
ret2= {}
ret2['latest_version'] = version
ret2['date'] = date
ret2['content'] = content
ret['Update_content']=ret2
shell_execute.execute_command_output_all("rm -rf /opt/appstore*")
return ret
else:
ret['Update_content']=None
shell_execute.execute_command_output_all("rm -rf /opt/appstore*")
return ret
def conbine_list(installing_list, installed_list):
app_list = installing_list + installed_list
result_list = []

View file

@ -32,3 +32,4 @@ APP_STATUS_RESTARTING = "restarting"
APP_STATUS_FAILED = "failed"
NGINX_URL="http://websoft9-nginxproxymanager:81"
ARTIFACT_URL="https://artifact.azureedge.net/release/websoft9"

View file

@ -359,6 +359,30 @@ def AppDomainList(request: Request, app_id: Optional[str] = Query(default=None,
return response
@router.api_route("/AppStoreUpdateList", methods=["GET", "POST"], summary="查询Appstore更新內容", response_model=Response, response_description=rd_appstore)
def AppStoreUpdateList(request: Request):
try:
myLogger.info_logger("Receive request: /AppStoreUpdateList")
get_headers(request)
ret = {}
ret['ResponseData'] = {}
ret['ResponseData']['Compare_content'] = manage.get_appstore_update_list()
myLogger.info_logger(ret)
response = JSONResponse(content=ret)
except CommandException as ce:
ret = {}
ret['ResponseData'] = {}
ret['Error'] = manage.get_error_info(ce.code, ce.message, ce.detail)
response = JSONResponse(content=ret)
except Exception as e:
ret = {}
ret['ResponseData'] = {}
ret['Error'] = manage.get_error_info(const.ERROR_SERVER_SYSTEM, "system original error", str(e))
response = JSONResponse(content=ret)
return response
@router.api_route("/AppUpdateList", methods=["GET", "POST"], summary="查询更新內容", response_model=Response, response_description=rd_update_list)
def AppUpdateList(request: Request):

View file

@ -1,4 +1,4 @@
APP_NAME=websoft9-appmanage
APP_VERSION=0.8.1
APP_VERSION=0.8.2
APP_HTTP_PORT=5000
APP_NETWORK=websoft9