mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-17 17:15:16 +00:00
wip
This commit is contained in:
parent
ff6cdb6fda
commit
cbbb907d6a
@ -18,6 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
dockerRootDirFilePath = "/var/lib/casaos/docker_root"
|
||||||
dockerDaemonConfigurationFilePath = "/etc/docker/daemon.json"
|
dockerDaemonConfigurationFilePath = "/etc/docker/daemon.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -274,36 +275,27 @@ func GetDockerDaemonConfiguration(c *gin.Context) {
|
|||||||
// c.JSON(common_err.SERVICE_ERROR, &model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
// c.JSON(common_err.SERVICE_ERROR, &model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
dockerConfig := model.DockerDaemonConfigurationModel{}
|
data := make(map[string]interface{})
|
||||||
data := make(map[string]interface{}, 1)
|
|
||||||
data["docker_root_dir"] = ""
|
|
||||||
|
|
||||||
// TODO read dockerRootDir from /etc/casaos/casaos.conf
|
if file.Exists(dockerRootDirFilePath) {
|
||||||
if file.Exists(dockerDaemonConfigurationFilePath) {
|
buf := file.ReadFullFile(dockerRootDirFilePath)
|
||||||
byteResult := file.ReadFullFile(dockerDaemonConfigurationFilePath)
|
err := json.Unmarshal(buf, &data)
|
||||||
err := json.Unmarshal(byteResult, &dockerConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(common_err.CLIENT_ERROR, &model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: err.Error()})
|
c.JSON(common_err.CLIENT_ERROR, &model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: err})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if dockerConfig.Root != "" {
|
|
||||||
data["docker_root_dir"] = dockerConfig.Root
|
|
||||||
} else {
|
|
||||||
data["docker_root_dir"] = "/var/lib/docker"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c.JSON(common_err.SUCCESS, &model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
c.JSON(common_err.SUCCESS, &model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
||||||
}
|
}
|
||||||
|
|
||||||
func PutDockerDaemonConfiguration(c *gin.Context) {
|
func PutDockerDaemonConfiguration(c *gin.Context) {
|
||||||
js := make(map[string]interface{})
|
request := make(map[string]interface{})
|
||||||
if err := c.BindJSON(&js); err != nil {
|
if err := c.BindJSON(&request); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, &model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: err.Error()})
|
c.JSON(http.StatusBadRequest, &model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: err})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
value, ok := js["docker_root_dir"]
|
value, ok := request["docker_root_dir"]
|
||||||
if !ok {
|
if !ok {
|
||||||
c.JSON(http.StatusBadRequest, &model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: "`docker_root_dir` should not empty"})
|
c.JSON(http.StatusBadRequest, &model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: "`docker_root_dir` should not empty"})
|
||||||
return
|
return
|
||||||
@ -314,7 +306,7 @@ func PutDockerDaemonConfiguration(c *gin.Context) {
|
|||||||
byteResult := file.ReadFullFile(dockerDaemonConfigurationFilePath)
|
byteResult := file.ReadFullFile(dockerDaemonConfigurationFilePath)
|
||||||
err := json.Unmarshal(byteResult, &dockerConfig)
|
err := json.Unmarshal(byteResult, &dockerConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, &model.Result{Success: common_err.SERVICE_ERROR, Message: "error when trying to deserialize " + dockerDaemonConfigurationFilePath, Data: err.Error()})
|
c.JSON(http.StatusInternalServerError, &model.Result{Success: common_err.SERVICE_ERROR, Message: "error when trying to deserialize " + dockerDaemonConfigurationFilePath, Data: err})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,26 +323,33 @@ func PutDockerDaemonConfiguration(c *gin.Context) {
|
|||||||
dockerConfig.Root = filepath.Join(dockerRootDir, "docker")
|
dockerConfig.Root = filepath.Join(dockerRootDir, "docker")
|
||||||
|
|
||||||
if err := file.IsNotExistMkDir(dockerConfig.Root); err != nil {
|
if err := file.IsNotExistMkDir(dockerConfig.Root); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, &model.Result{Success: common_err.SERVICE_ERROR, Message: "error when trying to create " + dockerConfig.Root, Data: err.Error()})
|
c.JSON(http.StatusInternalServerError, &model.Result{Success: common_err.SERVICE_ERROR, Message: "error when trying to create " + dockerConfig.Root, Data: err})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byteMode, err := json.Marshal(dockerConfig)
|
if buf, err := json.Marshal(request); err != nil {
|
||||||
if err != nil {
|
c.JSON(http.StatusBadRequest, &model.Result{Success: common_err.CLIENT_ERROR, Message: "error when trying to serialize docker root json", Data: err})
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if err := file.WriteToFullPath(buf, dockerRootDirFilePath, 0o644); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, &model.Result{Success: common_err.SERVICE_ERROR, Message: "error when trying to write " + dockerRootDirFilePath, Data: err})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if buf, err := json.Marshal(dockerConfig); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, &model.Result{Success: common_err.CLIENT_ERROR, Message: "error when trying to serialize docker config", Data: dockerConfig})
|
c.JSON(http.StatusBadRequest, &model.Result{Success: common_err.CLIENT_ERROR, Message: "error when trying to serialize docker config", Data: dockerConfig})
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
if err := file.WriteToFullPath(buf, dockerDaemonConfigurationFilePath, 0o644); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, &model.Result{Success: common_err.SERVICE_ERROR, Message: "error when trying to write to " + dockerDaemonConfigurationFilePath, Data: err})
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := file.WriteToFullPath(byteMode, dockerDaemonConfigurationFilePath, 0o644); err != nil {
|
|
||||||
c.JSON(http.StatusInternalServerError, &model.Result{Success: common_err.SERVICE_ERROR, Message: "error when trying to write to " + dockerDaemonConfigurationFilePath, Data: err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO also write dockerRootDir to /etc/casaos/casaos.conf
|
|
||||||
|
|
||||||
println(command.ExecResultStr("systemctl daemon-reload"))
|
println(command.ExecResultStr("systemctl daemon-reload"))
|
||||||
println(command.ExecResultStr("systemctl restart docker"))
|
println(command.ExecResultStr("systemctl restart docker"))
|
||||||
|
|
||||||
c.JSON(http.StatusOK, &model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: js})
|
c.JSON(http.StatusOK, &model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: request})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user