2022-10-10 15:14:49 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-18 18:39:45 +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/1Panel-dev/1Panel/backend/global"
|
2022-10-10 15:14:49 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Image
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary Page images
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取镜像列表分页
|
|
|
|
// @Accept json
|
2023-02-07 18:48:32 +08:00
|
|
|
// @Param request body dto.SearchWithPage true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/search [post]
|
2022-10-10 15:14:49 +08:00
|
|
|
func (b *BaseApi) SearchImage(c *gin.Context) {
|
2023-02-07 18:48:32 +08:00
|
|
|
var req dto.SearchWithPage
|
2022-10-10 15:14:49 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, list, err := imageService.Page(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Image
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary List images
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取镜像列表
|
|
|
|
// @Produce json
|
2023-07-06 18:04:22 +08:00
|
|
|
// @Success 200 {array} dto.Options
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image [get]
|
2022-10-12 18:55:47 +08:00
|
|
|
func (b *BaseApi) ListImage(c *gin.Context) {
|
|
|
|
list, err := imageService.List()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Image
|
|
|
|
// @Summary Build image
|
|
|
|
// @Description 构建镜像
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ImageBuild true "request"
|
|
|
|
// @Success 200 {string} log
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/build [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"构建镜像 [name]","formatEN":"build image [name]"}
|
2022-10-11 14:20:51 +08:00
|
|
|
func (b *BaseApi) ImageBuild(c *gin.Context) {
|
|
|
|
var req dto.ImageBuild
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-12 13:42:58 +08:00
|
|
|
log, err := imageService.ImageBuild(req)
|
|
|
|
if err != nil {
|
2022-10-11 14:20:51 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-12 13:42:58 +08:00
|
|
|
helper.SuccessWithData(c, log)
|
2022-10-11 14:20:51 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Image
|
|
|
|
// @Summary Pull image
|
|
|
|
// @Description 拉取镜像
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ImagePull true "request"
|
|
|
|
// @Success 200 {string} log
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/pull [post]
|
2023-05-30 15:30:57 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["repoID","imageName"],"paramKeys":[],"BeforeFuntions":[{"input_column":"id","input_value":"repoID","isList":false,"db":"image_repos","output_column":"name","output_value":"reponame"}],"formatZH":"镜像拉取 [reponame][imageName]","formatEN":"image pull [reponame][imageName]"}
|
2022-10-10 15:14:49 +08:00
|
|
|
func (b *BaseApi) ImagePull(c *gin.Context) {
|
|
|
|
var req dto.ImagePull
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-07 14:28:11 +08:00
|
|
|
logPath, err := imageService.ImagePull(req)
|
|
|
|
if err != nil {
|
2022-10-10 15:14:49 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-07 14:28:11 +08:00
|
|
|
helper.SuccessWithData(c, logPath)
|
2022-10-10 15:14:49 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Image
|
|
|
|
// @Summary Push image
|
|
|
|
// @Description 推送镜像
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ImagePush true "request"
|
|
|
|
// @Success 200 {string} log
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/push [post]
|
2023-05-30 15:30:57 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["repoID","tagName","name"],"paramKeys":[],"BeforeFuntions":[{"input_column":"id","input_value":"repoID","isList":false,"db":"image_repos","output_column":"name","output_value":"reponame"}],"formatZH":"[tagName] 推送到 [reponame][name]","formatEN":"push [tagName] to [reponame][name]"}
|
2022-10-10 15:14:49 +08:00
|
|
|
func (b *BaseApi) ImagePush(c *gin.Context) {
|
|
|
|
var req dto.ImagePush
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-07 14:28:11 +08:00
|
|
|
logPath, err := imageService.ImagePush(req)
|
|
|
|
if err != nil {
|
2022-10-10 15:14:49 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-07 14:28:11 +08:00
|
|
|
helper.SuccessWithData(c, logPath)
|
2022-10-10 15:14:49 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Image
|
|
|
|
// @Summary Delete image
|
|
|
|
// @Description 删除镜像
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BatchDelete true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/remove [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["names"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"移除镜像 [names]","formatEN":"remove image [names]"}
|
2022-10-10 15:14:49 +08:00
|
|
|
func (b *BaseApi) ImageRemove(c *gin.Context) {
|
2022-10-11 17:46:52 +08:00
|
|
|
var req dto.BatchDelete
|
2022-10-10 15:14:49 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := imageService.ImageRemove(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 Image
|
|
|
|
// @Summary Save image
|
|
|
|
// @Description 导出镜像
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ImageSave true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/save [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["tagName","path","name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"保留 [tagName] 为 [path]/[name]","formatEN":"save [tagName] as [path]/[name]"}
|
2022-10-10 15:14:49 +08:00
|
|
|
func (b *BaseApi) ImageSave(c *gin.Context) {
|
|
|
|
var req dto.ImageSave
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := imageService.ImageSave(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 Image
|
|
|
|
// @Summary Tag image
|
|
|
|
// @Description Tag 镜像
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ImageTag true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/tag [post]
|
2023-05-30 15:30:57 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["repoID","targetName"],"paramKeys":[],"BeforeFuntions":[{"input_column":"id","input_value":"repoID","isList":false,"db":"image_repos","output_column":"name","output_value":"reponame"}],"formatZH":"tag 镜像 [reponame][targetName]","formatEN":"tag image [reponame][targetName]"}
|
2022-10-11 17:46:52 +08:00
|
|
|
func (b *BaseApi) ImageTag(c *gin.Context) {
|
|
|
|
var req dto.ImageTag
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := imageService.ImageTag(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 Image
|
|
|
|
// @Summary Load image
|
|
|
|
// @Description 导入镜像
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ImageLoad true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/image/load [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["path"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"从 [path] 加载镜像","formatEN":"load image from [path]"}
|
2022-10-10 15:14:49 +08:00
|
|
|
func (b *BaseApi) ImageLoad(c *gin.Context) {
|
|
|
|
var req dto.ImageLoad
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := imageService.ImageLoad(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|