2022-11-14 19:19:42 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2023-02-01 16:15:31 +08:00
|
|
|
"os"
|
|
|
|
|
2022-11-14 19:19:42 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Docker
|
|
|
|
// @Summary Load docker status
|
|
|
|
// @Description 获取 docker 服务状态
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {string} status
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/docker/status [get]
|
2022-12-07 17:28:14 +08:00
|
|
|
func (b *BaseApi) LoadDockerStatus(c *gin.Context) {
|
|
|
|
status := dockerService.LoadDockerStatus()
|
|
|
|
helper.SuccessWithData(c, status)
|
|
|
|
}
|
2022-11-14 19:19:42 +08:00
|
|
|
|
2023-02-01 16:15:31 +08:00
|
|
|
// @Tags Container Docker
|
|
|
|
// @Summary Load docker daemon.json
|
|
|
|
// @Description 获取 docker 配置信息(表单)
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} string
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/daemonjson/file [get]
|
|
|
|
func (b *BaseApi) LoadDaemonJsonFile(c *gin.Context) {
|
|
|
|
if _, err := os.Stat(constant.DaemonJsonPath); err != nil {
|
|
|
|
helper.SuccessWithData(c, "daemon.json is not find in path")
|
|
|
|
return
|
|
|
|
}
|
2023-04-07 11:30:10 +08:00
|
|
|
content, err := os.ReadFile(constant.DaemonJsonPath)
|
2023-02-01 16:15:31 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, string(content))
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Docker
|
|
|
|
// @Summary Load docker daemon.json
|
|
|
|
// @Description 获取 docker 配置信息
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} dto.DaemonJsonConf
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/daemonjson [get]
|
2022-12-07 17:28:14 +08:00
|
|
|
func (b *BaseApi) LoadDaemonJson(c *gin.Context) {
|
|
|
|
conf := dockerService.LoadDockerConf()
|
2022-11-14 19:19:42 +08:00
|
|
|
helper.SuccessWithData(c, conf)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Docker
|
|
|
|
// @Summary Update docker daemon.json
|
|
|
|
// @Description 修改 docker 配置信息
|
|
|
|
// @Accept json
|
2023-05-29 11:24:28 +08:00
|
|
|
// @Param request body dto.SettingUpdate true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/daemonjson/update [post]
|
2024-04-25 19:07:12 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["key", "value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新配置 [key]","formatEN":"Updated configuration [key]"}
|
2022-11-14 19:19:42 +08:00
|
|
|
func (b *BaseApi) UpdateDaemonJson(c *gin.Context) {
|
2023-05-29 11:24:28 +08:00
|
|
|
var req dto.SettingUpdate
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-14 19:19:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := dockerService.UpdateConf(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Docker
|
2023-05-29 11:24:28 +08:00
|
|
|
// @Summary Update docker daemon.json log option
|
|
|
|
// @Description 修改 docker 日志配置
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.LogOption true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-11-21 22:14:07 +08:00
|
|
|
// @Router /containers/logoption/update [post]
|
2024-04-25 19:07:12 +08:00
|
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新日志配置","formatEN":"Updated the log option"}
|
2023-05-29 11:24:28 +08:00
|
|
|
func (b *BaseApi) UpdateLogOption(c *gin.Context) {
|
|
|
|
var req dto.LogOption
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBind(&req, c); err != nil {
|
2023-05-29 11:24:28 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := dockerService.UpdateLogOption(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-11-21 22:14:07 +08:00
|
|
|
// @Tags Container Docker
|
|
|
|
// @Summary Update docker daemon.json ipv6 option
|
|
|
|
// @Description 修改 docker ipv6 配置
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.LogOption true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/ipv6option/update [post]
|
2024-04-25 19:07:12 +08:00
|
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新 ipv6 配置","formatEN":"Updated the ipv6 option"}
|
2023-11-21 22:14:07 +08:00
|
|
|
func (b *BaseApi) UpdateIpv6Option(c *gin.Context) {
|
|
|
|
var req dto.Ipv6Option
|
|
|
|
if err := helper.CheckBind(&req, c); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := dockerService.UpdateIpv6Option(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-05-29 11:24:28 +08:00
|
|
|
// @Tags Container Docker
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Summary Update docker daemon.json by upload file
|
|
|
|
// @Description 上传替换 docker 配置文件
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.DaemonJsonUpdateByFile true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/daemonjson/update/byfile [post]
|
2024-04-25 19:07:12 +08:00
|
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新配置文件","formatEN":"Updated configuration file"}
|
2022-11-14 19:19:42 +08:00
|
|
|
func (b *BaseApi) UpdateDaemonJsonByFile(c *gin.Context) {
|
|
|
|
var req dto.DaemonJsonUpdateByFile
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-12-07 17:28:14 +08:00
|
|
|
return
|
|
|
|
}
|
2022-11-14 19:19:42 +08:00
|
|
|
|
|
|
|
if err := dockerService.UpdateConfByFile(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-12-07 17:28:14 +08:00
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Docker
|
|
|
|
// @Summary Operate docker
|
|
|
|
// @Description Docker 操作
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.DockerOperation true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/docker/operate [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["operation"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"docker 服务 [operation]","formatEN":"[operation] docker service"}
|
2022-12-07 17:28:14 +08:00
|
|
|
func (b *BaseApi) OperateDocker(c *gin.Context) {
|
|
|
|
var req dto.DockerOperation
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-12-07 17:28:14 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := dockerService.OperateDocker(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|