feat: change docker pull process log (#8680)

This commit is contained in:
CityFun 2025-05-15 21:40:39 +08:00 committed by GitHub
parent 7210cd15f2
commit 7ad31f532a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 51 additions and 24 deletions

View file

@ -1923,12 +1923,7 @@ func handleSSLConfig(appInstall *model.AppInstall, hasDefaultWebsite bool) error
}
defaultConfig.FilePath = defaultConfigPath
defaultServer := defaultConfig.FindServers()[0]
defaultServer.UpdateListen(fmt.Sprintf("%d", appInstall.HttpPort), !hasDefaultWebsite)
defaultServer.UpdateListen(fmt.Sprintf("[::]:%d", appInstall.HttpPort), !hasDefaultWebsite)
defaultServer.UpdateListen(fmt.Sprintf("%d", appInstall.HttpsPort), !hasDefaultWebsite, "ssl")
defaultServer.UpdateListen(fmt.Sprintf("[::]:%d", appInstall.HttpsPort), !hasDefaultWebsite, "ssl")
defaultServer.UpdateListen(fmt.Sprintf("%d", appInstall.HttpsPort), false, "quic", "reuseport")
defaultServer.UpdateListen(fmt.Sprintf("[::]:%d", appInstall.HttpsPort), false, "quic", "reuseport")
updateDefaultServer(defaultServer, appInstall.HttpPort, appInstall.HttpsPort, !hasDefaultWebsite)
defaultServer.UpdateDirective("include", []string{"/usr/local/openresty/nginx/conf/ssl/root_ssl.conf"})
defaultServer.UpdateDirective("http2", []string{"on"})
if err = nginx.WriteConfig(defaultConfig, nginx.IndentedStyle); err != nil {

View file

@ -119,10 +119,7 @@ func updateDefaultServerConfig(enable bool) error {
}
defaultConfig.FilePath = defaultConfigPath
defaultServer := defaultConfig.FindServers()[0]
defaultServer.UpdateListen(fmt.Sprintf("%d", nginxInstall.HttpPort), enable)
defaultServer.UpdateListen(fmt.Sprintf("[::]:%d", nginxInstall.HttpPort), enable)
defaultServer.UpdateListen(fmt.Sprintf("%d", nginxInstall.HttpsPort), enable, "ssl")
defaultServer.UpdateListen(fmt.Sprintf("[::]:%d", nginxInstall.HttpsPort), enable, "ssl")
updateDefaultServer(defaultServer, nginxInstall.HttpPort, nginxInstall.HttpsPort, enable)
if err = nginx.WriteConfig(defaultConfig, nginx.IndentedStyle); err != nil {
return err
}
@ -264,3 +261,12 @@ func nginxCheckAndReload(oldContent string, filePath string, containerName strin
}
return nil
}
func updateDefaultServer(server *components.Server, httpPort int, httpsPort int, defaultServer bool) {
server.UpdateListen(fmt.Sprintf("%d", httpPort), defaultServer)
server.UpdateListen(fmt.Sprintf("[::]:%d", httpPort), defaultServer)
server.UpdateListen(fmt.Sprintf("%d", httpsPort), defaultServer, "ssl")
server.UpdateListen(fmt.Sprintf("[::]:%d", httpsPort), defaultServer, "ssl")
server.UpdateListen(fmt.Sprintf("%d", httpsPort), defaultServer, "quic", "reuseport")
server.UpdateListen(fmt.Sprintf("[::]:%d", httpsPort), defaultServer, "quic", "reuseport")
}

View file

@ -198,18 +198,7 @@ func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string
}
status, _ := progress["status"].(string)
if status == "Downloading" || status == "Extracting" {
id, _ := progress["id"].(string)
progressDetail, _ := progress["progressDetail"].(map[string]interface{})
current, _ := progressDetail["current"].(float64)
progressStr := ""
total, ok := progressDetail["total"].(float64)
timeStr := time.Now().Format("2006/01/02 15:04:05")
if ok {
progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, (current/total)*100)
} else {
progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, current)
}
_ = setLog(id, progressStr, task)
logProcess(progress, task)
}
if status == "Pull complete" || status == "Download complete" {
id, _ := progress["id"].(string)
@ -328,3 +317,39 @@ func (c Client) BuildImageWithProcessAndOptions(task *task.Task, tar io.ReadClos
func (c Client) PullImageWithProcess(task *task.Task, imageName string) error {
return c.PullImageWithProcessAndOptions(task, imageName, image.PullOptions{})
}
func formatBytes(bytes uint64) string {
const (
KB = 1024
MB = 1024 * KB
GB = 1024 * MB
TB = 1024 * GB
)
switch {
case bytes < MB:
return fmt.Sprintf("%.0fKB", float64(bytes)/KB)
case bytes < GB:
return fmt.Sprintf("%.1fMB", float64(bytes)/MB)
case bytes < TB:
return fmt.Sprintf("%.1fGB", float64(bytes)/GB)
default:
return fmt.Sprintf("%.2fTB", float64(bytes)/TB)
}
}
func logProcess(progress map[string]interface{}, task *task.Task) {
status, _ := progress["status"].(string)
id, _ := progress["id"].(string)
progressDetail, _ := progress["progressDetail"].(map[string]interface{})
current, _ := progressDetail["current"].(float64)
progressStr := ""
total, ok := progressDetail["total"].(float64)
timeStr := time.Now().Format("2006/01/02 15:04:05")
if ok {
progressStr = fmt.Sprintf("%s %s [%s] --- %.2f%%", timeStr, status, id, (current/total)*100)
} else {
progressStr = fmt.Sprintf("%s %s [%s] --- %s ", timeStr, status, id, formatBytes(uint64(current)))
}
_ = setLog(id, progressStr, task)
}

View file

@ -405,7 +405,7 @@ export const StatusStrategy = [
},
];
export const WebsiteTypes = [
export const getWebsiteTypes = () => [
{
label: i18n.global.t('website.deployment'),
value: 'deployment',

View file

@ -548,7 +548,7 @@ import { dateFormatSimple, getProvider, getAccountName } from '@/utils/util';
import { Website } from '@/api/interface/website';
import DomainCreate from '@/views/website/website/domain-create/index.vue';
import { getPathByType } from '@/api/modules/files';
import { WebsiteTypes } from '@/global/mimetype';
import { getWebsiteTypes } from '@/global/mimetype';
const websiteForm = ref<FormInstance>();
@ -669,6 +669,7 @@ const websiteSSL = ref();
const parentWebsites = ref();
const dirs = ref([]);
const runtimePorts = ref([]);
const WebsiteTypes = getWebsiteTypes();
const handleClose = () => {
open.value = false;