diff --git a/backend/app/api/v1/setting.go b/backend/app/api/v1/setting.go index 09c029541..5f1f7f5d2 100644 --- a/backend/app/api/v1/setting.go +++ b/backend/app/api/v1/setting.go @@ -28,22 +28,6 @@ func (b *BaseApi) GetSettingInfo(c *gin.Context) { helper.SuccessWithData(c, setting) } -// Load daemon.json path -// @Tags System Setting -// @Summary Load daemon.json path -// @Description 加载 docker 配置路径 -// @Success 200 {string} path -// @Security ApiKeyAuth -// @Router /settings/daemonjson [get] -func (b *BaseApi) GetDaemonjson(c *gin.Context) { - value, err := settingService.GetDaemonjson() - if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - helper.SuccessWithData(c, value) -} - // @Tags System Setting // @Summary Update system setting // @Description 更新系统配置 diff --git a/backend/app/dto/docker.go b/backend/app/dto/docker.go index 950a030ba..f5985643b 100644 --- a/backend/app/dto/docker.go +++ b/backend/app/dto/docker.go @@ -7,6 +7,7 @@ type DaemonJsonUpdateByFile struct { type DaemonJsonConf struct { Status string `json:"status"` + Version string `json:"version"` Mirrors []string `json:"registryMirrors"` Registries []string `json:"insecureRegistries"` LiveRestore bool `json:"liveRestore"` diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index 609397158..7abe02de3 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -2,14 +2,17 @@ package service import ( "bufio" + "context" "encoding/json" "io/ioutil" "os" "os/exec" + "path" "strings" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/1Panel-dev/1Panel/backend/utils/docker" "github.com/pkg/errors" ) @@ -53,31 +56,33 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { if string(stdout) != "active\n" || err != nil { status = constant.Stopped } - fileSetting, err := settingRepo.Get(settingRepo.WithByKey("DaemonJsonPath")) + version := "-" + client, err := docker.NewDockerClient() + if err == nil { + ctx := context.Background() + itemVersion, err := client.ServerVersion(ctx) + if err == nil { + version = itemVersion.Version + } + } + if _, err := os.Stat(constant.DaemonJsonPath); err != nil { + return &dto.DaemonJsonConf{Status: status, Version: version} + } + file, err := ioutil.ReadFile(constant.DaemonJsonPath) if err != nil { - return &dto.DaemonJsonConf{Status: status} - } - if len(fileSetting.Value) == 0 { - return &dto.DaemonJsonConf{Status: status} - } - if _, err := os.Stat(fileSetting.Value); err != nil { - return &dto.DaemonJsonConf{Status: status} - } - file, err := ioutil.ReadFile(fileSetting.Value) - if err != nil { - return &dto.DaemonJsonConf{Status: status} + return &dto.DaemonJsonConf{Status: status, Version: version} } var conf daemonJsonItem deamonMap := make(map[string]interface{}) if err := json.Unmarshal(file, &deamonMap); err != nil { - return &dto.DaemonJsonConf{Status: status} + return &dto.DaemonJsonConf{Status: status, Version: version} } arr, err := json.Marshal(deamonMap) if err != nil { - return &dto.DaemonJsonConf{Status: status} + return &dto.DaemonJsonConf{Status: status, Version: version} } if err := json.Unmarshal(arr, &conf); err != nil { - return &dto.DaemonJsonConf{Status: status} + return &dto.DaemonJsonConf{Status: status, Version: version} } driver := "cgroupfs" for _, opt := range conf.ExecOpts { @@ -88,6 +93,7 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { } data := dto.DaemonJsonConf{ Status: status, + Version: version, Mirrors: conf.Mirrors, Registries: conf.Registries, LiveRestore: conf.LiveRestore, @@ -98,22 +104,16 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { } func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error { - fileSetting, err := settingRepo.Get(settingRepo.WithByKey("DaemonJsonPath")) - if err != nil { - return err - } - if len(fileSetting.Value) == 0 { - return errors.New("error daemon.json path in request") - } - if _, err := os.Stat(fileSetting.Value); err != nil && os.IsNotExist(err) { - if err = os.MkdirAll(fileSetting.Value, os.ModePerm); err != nil { + if _, err := os.Stat(constant.DaemonJsonPath); err != nil && os.IsNotExist(err) { + if err = os.MkdirAll(path.Dir(constant.DaemonJsonPath), os.ModePerm); err != nil { if err != nil { return err } } + _, _ = os.Create(constant.DaemonJsonPath) } - file, err := ioutil.ReadFile(fileSetting.Value) + file, err := ioutil.ReadFile(constant.DaemonJsonPath) if err != nil { return err } @@ -155,7 +155,7 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error { if err != nil { return err } - if err := ioutil.WriteFile(fileSetting.Value, newJson, 0640); err != nil { + if err := ioutil.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil { return err } diff --git a/backend/app/service/image_repo.go b/backend/app/service/image_repo.go index a60638ddd..c20634a73 100644 --- a/backend/app/service/image_repo.go +++ b/backend/app/service/image_repo.go @@ -176,24 +176,17 @@ func (u *ImageRepoService) checkConn(host, user, password string) error { } func (u *ImageRepoService) handleRegistries(newHost, delHost, handle string) error { - fileSetting, err := settingRepo.Get(settingRepo.WithByKey("DaemonJsonPath")) - if err != nil { - return err - } - if len(fileSetting.Value) == 0 { - return errors.New("error daemon.json in settings") - } - if _, err := os.Stat(path.Dir(fileSetting.Value)); err != nil && os.IsNotExist(err) { - if err = os.MkdirAll(fileSetting.Value, os.ModePerm); err != nil { + if _, err := os.Stat(constant.DaemonJsonPath); err != nil && os.IsNotExist(err) { + if err = os.MkdirAll(path.Dir(constant.DaemonJsonPath), os.ModePerm); err != nil { if err != nil { return err } } - _, _ = os.Create(fileSetting.Value) + _, _ = os.Create(constant.DaemonJsonPath) } deamonMap := make(map[string]interface{}) - file, err := ioutil.ReadFile(fileSetting.Value) + file, err := ioutil.ReadFile(constant.DaemonJsonPath) if err != nil { return err } @@ -229,7 +222,7 @@ func (u *ImageRepoService) handleRegistries(newHost, delHost, handle string) err if err != nil { return err } - if err := ioutil.WriteFile(fileSetting.Value, newJson, 0640); err != nil { + if err := ioutil.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil { return err } return nil diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go index b778798db..6033087d3 100644 --- a/backend/app/service/setting.go +++ b/backend/app/service/setting.go @@ -16,7 +16,6 @@ type SettingService struct{} type ISettingService interface { GetSettingInfo() (*dto.SettingInfo, error) - GetDaemonjson() (string, error) Update(c *gin.Context, key, value string) error UpdatePassword(c *gin.Context, old, new string) error HandlePasswordExpired(c *gin.Context, old, new string) error @@ -47,14 +46,6 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) { return &info, err } -func (u *SettingService) GetDaemonjson() (string, error) { - setting, err := settingRepo.Get(settingRepo.WithByKey("DaemonJsonPath")) - if err != nil { - return "", err - } - return setting.Value, nil -} - func (u *SettingService) Update(c *gin.Context, key, value string) error { if key == "ExpirationDays" { timeout, _ := strconv.Atoi(value) diff --git a/backend/constant/container.go b/backend/constant/container.go index 82873a963..a843c8fa6 100644 --- a/backend/constant/container.go +++ b/backend/constant/container.go @@ -16,4 +16,5 @@ const ( TmpDockerBuildDir = "/opt/1Panel/data/docker/build" TmpComposeBuildDir = "/opt/1Panel/data/docker/compose" + DaemonJsonPath = "/tmp/docker/daemon.json" ) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index 9a777c1bf..ffb8cc413 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -114,10 +114,6 @@ var AddTableSetting = &gormigrate.Migration{ return err } - if err := tx.Create(&model.Setting{Key: "DaemonJsonPath", Value: "/opt/1Panel/docker/conf/daemon.json"}).Error; err != nil { - return err - } - if err := tx.Create(&model.Setting{Key: "MessageType", Value: "none"}).Error; err != nil { return err } diff --git a/backend/router/ro_setting.go b/backend/router/ro_setting.go index 47c0c2271..4071995a1 100644 --- a/backend/router/ro_setting.go +++ b/backend/router/ro_setting.go @@ -23,7 +23,6 @@ func (s *SettingRouter) InitSettingRouter(Router *gin.RouterGroup) { settingRouter.POST("/time/sync", baseApi.SyncTime) settingRouter.POST("/monitor/clean", baseApi.CleanMonitor) settingRouter.GET("/mfa", baseApi.GetMFA) - settingRouter.GET("/daemonjson", baseApi.GetDaemonjson) settingRouter.POST("/mfa/bind", baseApi.MFABind) } } diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index c42409ffd..186681131 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -236,7 +236,6 @@ export namespace Container { } export interface DaemonJsonUpdateByFile { - path: string; file: string; } export interface DockerOperate { @@ -244,6 +243,7 @@ export namespace Container { } export interface DaemonJsonConf { status: string; + version: string; registryMirrors: Array; insecureRegistries: Array; liveRestore: boolean; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 47ec3c281..c78cf17ba 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -359,6 +359,7 @@ export default { rdbInfo: 'Rule list has 0 value, please confirm and try again!', }, container: { + containerList: 'Container list', operatorHelper: '{0} will be performed on the selected container. Do you want to continue?', start: 'Start', stop: 'Stop', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 0b5fc915b..2c3d86aa5 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -372,6 +372,7 @@ export default { rdbInfo: '规则列表存在 0 值,请确认后重试!', }, container: { + containerList: '容器列表', operatorHelper: '将对选中容器进行 {0} 操作,是否继续?', start: '启动', stop: '停止', diff --git a/frontend/src/views/container/compose/detail/index.vue b/frontend/src/views/container/compose/detail/index.vue index 24ceea33e..dcbe4e82f 100644 --- a/frontend/src/views/container/compose/detail/index.vue +++ b/frontend/src/views/container/compose/detail/index.vue @@ -1,31 +1,42 @@ @@ -314,3 +325,18 @@ defineExpose({ acceptParams, }); + + diff --git a/frontend/src/views/container/compose/index.vue b/frontend/src/views/container/compose/index.vue index 73f7fba67..36e128e21 100644 --- a/frontend/src/views/container/compose/index.vue +++ b/frontend/src/views/container/compose/index.vue @@ -1,6 +1,10 @@