Fix bug related to application binding domain

This commit is contained in:
zhaojing1987 2024-06-06 08:12:50 +08:00
parent 6b867f0743
commit dad4781508
5 changed files with 50 additions and 9 deletions

View file

@ -20,7 +20,7 @@ user_pwd = L@BI75LJ7Shi7oLA
key = bd3d92e0f52e299d014c38f8aac7f730602a8a7a41adbee77eddf07b391b9d31
[domain]
wildcard_domain = test.websoft9.cn
wildcard_domain =
[cockpit]
port = 9000
@ -29,5 +29,4 @@ port = 9000
keys =
[favorite_apps]
keys = kibana
keys =

View file

@ -5,4 +5,4 @@ path = /websoft9/library/apps
path = /websoft9/media/json/
[max_apps]
key = 2
key =

View file

@ -104,6 +104,21 @@ class GiteaAPI:
path=f"repos/{self.owner}/{repo_name}/contents/{file_path}",
params={"ref": "main"}
)
def get_file_raw_from_repo(self, repo_name: str, file_path: str):
"""
Get file raw from repository
Args:
repo_name (str): Repository name
file_path (str): File path
Returns:
Response: Response from Gitea API
"""
return self.api.get(
path=f"repos/{self.owner}/{repo_name}/raw/{file_path}"
)
def update_file_content_in_repo(self, repo_name: str, file_path: str, content: str, sha: str):
"""

14
apphub/src/services/app_manager.py Executable file → Normal file
View file

@ -995,13 +995,19 @@ class AppManger:
# redeploy app
self.redeploy_app(app_id,False)
# Get the forward scheme form env file: http or https
proxy_host = proxyManager.create_proxy_by_app(domain_names,app_id,forward_port,forward_scheme=forward_scheme)
# Get the nginx proxy config
advanced_config = GiteaManager().get_file_raw_from_repo(app_id, "src/nginx-proxy.conf")
if advanced_config:
proxy_host = proxyManager.create_proxy_by_app(domain_names, app_id, forward_port, advanced_config, forward_scheme=forward_scheme)
else:
proxy_host = proxyManager.create_proxy_by_app(domain_names, app_id, forward_port, forward_scheme=forward_scheme)
if proxy_host:
logger.access(f"Created domains:{domain_names} for app: [{app_id}]")
logger.access(f"Created domains: {domain_names} for app: [{app_id}]")
return proxy_host
else:
logger.error(f"Create app:{app_id} proxy error")
logger.error(f"Failed to create proxy host for app: [{app_id}]")
raise CustomException()
else:
logger.error(f"Get app:{app_id} forward_port error")

View file

@ -130,4 +130,25 @@ class GiteaManager:
response = self.gitea.remove_repo(repo_name)
if response.status_code != 204:
logger.error(f"Remove repo:{repo_name} error:{response.status_code}:{response.text}")
raise CustomException()
raise CustomException()
def get_file_raw_from_repo(self, repo_name: str, file_path: str):
"""
Get a file from a repository
Args:
repo_name (str): Repository name
file_path (str): File path
Returns:
dict: File content
"""
response = self.gitea.get_file_raw_from_repo(repo_name, file_path)
if response.status_code == 200:
return response.text
elif response.status_code == 404:
return None
else:
logger.error(f"Get file:{file_path} content from repo:{repo_name} error:{response.status_code}:{response.text}")
raise CustomException()