1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-07 17:10:07 +08:00

fix: 解决镜像清理显示不全的问题 (#3558)

This commit is contained in:
ssongliu 2024-01-10 17:05:52 +08:00 committed by GitHub
parent 2c04d24108
commit 3c39415d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 194 additions and 18 deletions

View File

@ -35,8 +35,24 @@ func (b *BaseApi) SearchImage(c *gin.Context) {
} }
// @Tags Container Image // @Tags Container Image
// @Summary List images // @Summary List all images
// @Description 获取镜像列表 // @Description 获取所有镜像列表
// @Produce json
// @Success 200 {array} dto.ImageInfo
// @Security ApiKeyAuth
// @Router /containers/image/all [get]
func (b *BaseApi) ListAllImage(c *gin.Context) {
list, err := imageService.ListAll()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
// @Tags Container Image
// @Summary load images options
// @Description 获取镜像名称列表
// @Produce json // @Produce json
// @Success 200 {array} dto.Options // @Success 200 {array} dto.Options
// @Security ApiKeyAuth // @Security ApiKeyAuth

View File

@ -28,6 +28,7 @@ type ImageService struct{}
type IImageService interface { type IImageService interface {
Page(req dto.SearchWithPage) (int64, interface{}, error) Page(req dto.SearchWithPage) (int64, interface{}, error)
List() ([]dto.Options, error) List() ([]dto.Options, error)
ListAll() ([]dto.ImageInfo, error)
ImageBuild(req dto.ImageBuild) (string, error) ImageBuild(req dto.ImageBuild) (string, error)
ImagePull(req dto.ImagePull) (string, error) ImagePull(req dto.ImagePull) (string, error)
ImageLoad(req dto.ImageLoad) error ImageLoad(req dto.ImageLoad) error
@ -97,6 +98,30 @@ func (u *ImageService) Page(req dto.SearchWithPage) (int64, interface{}, error)
return int64(total), backDatas, nil return int64(total), backDatas, nil
} }
func (u *ImageService) ListAll() ([]dto.ImageInfo, error) {
var records []dto.ImageInfo
client, err := docker.NewDockerClient()
if err != nil {
return nil, err
}
list, err := client.ImageList(context.Background(), types.ImageListOptions{})
if err != nil {
return nil, err
}
containers, _ := client.ContainerList(context.Background(), types.ContainerListOptions{All: true})
for _, image := range list {
size := formatFileSize(image.Size)
records = append(records, dto.ImageInfo{
ID: image.ID,
Tags: image.RepoTags,
IsUsed: checkUsed(image.ID, containers),
CreatedAt: time.Unix(image.Created, 0),
Size: size,
})
}
return records, nil
}
func (u *ImageService) List() ([]dto.Options, error) { func (u *ImageService) List() ([]dto.Options, error) {
var ( var (
list []types.ImageSummary list []types.ImageSummary

View File

@ -55,6 +55,7 @@ func (s *ContainerRouter) InitRouter(Router *gin.RouterGroup) {
baRouter.POST("/template/del", baseApi.DeleteComposeTemplate) baRouter.POST("/template/del", baseApi.DeleteComposeTemplate)
baRouter.GET("/image", baseApi.ListImage) baRouter.GET("/image", baseApi.ListImage)
baRouter.GET("/image/all", baseApi.ListAllImage)
baRouter.POST("/image/search", baseApi.SearchImage) baRouter.POST("/image/search", baseApi.SearchImage)
baRouter.POST("/image/pull", baseApi.ImagePull) baRouter.POST("/image/pull", baseApi.ImagePull)
baRouter.POST("/image/push", baseApi.ImagePush) baRouter.POST("/image/push", baseApi.ImagePush)

View File

@ -1,5 +1,5 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT // Code generated by swaggo/swag. DO NOT EDIT.
// This file was generated by swaggo/swag
package docs package docs
import "github.com/swaggo/swag" import "github.com/swaggo/swag"
@ -1564,14 +1564,14 @@ const docTemplate = `{
"ApiKeyAuth": [] "ApiKeyAuth": []
} }
], ],
"description": "获取镜像列表", "description": "获取镜像名称列表",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"Container Image" "Container Image"
], ],
"summary": "List images", "summary": "load images options",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -1585,6 +1585,34 @@ const docTemplate = `{
} }
} }
}, },
"/containers/image/all": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取所有镜像列表",
"produces": [
"application/json"
],
"tags": [
"Container Image"
],
"summary": "List all images",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.ImageInfo"
}
}
}
}
}
},
"/containers/image/build": { "/containers/image/build": {
"post": { "post": {
"security": [ "security": [
@ -16047,6 +16075,29 @@ const docTemplate = `{
} }
} }
}, },
"dto.ImageInfo": {
"type": "object",
"properties": {
"createdAt": {
"type": "string"
},
"id": {
"type": "string"
},
"isUsed": {
"type": "boolean"
},
"size": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"dto.ImageLoad": { "dto.ImageLoad": {
"type": "object", "type": "object",
"required": [ "required": [

View File

@ -1557,14 +1557,14 @@
"ApiKeyAuth": [] "ApiKeyAuth": []
} }
], ],
"description": "获取镜像列表", "description": "获取镜像名称列表",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"Container Image" "Container Image"
], ],
"summary": "List images", "summary": "load images options",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -1578,6 +1578,34 @@
} }
} }
}, },
"/containers/image/all": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取所有镜像列表",
"produces": [
"application/json"
],
"tags": [
"Container Image"
],
"summary": "List all images",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.ImageInfo"
}
}
}
}
}
},
"/containers/image/build": { "/containers/image/build": {
"post": { "post": {
"security": [ "security": [
@ -16040,6 +16068,29 @@
} }
} }
}, },
"dto.ImageInfo": {
"type": "object",
"properties": {
"createdAt": {
"type": "string"
},
"id": {
"type": "string"
},
"isUsed": {
"type": "boolean"
},
"size": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"dto.ImageLoad": { "dto.ImageLoad": {
"type": "object", "type": "object",
"required": [ "required": [

View File

@ -1374,6 +1374,21 @@ definitions:
- from - from
- name - name
type: object type: object
dto.ImageInfo:
properties:
createdAt:
type: string
id:
type: string
isUsed:
type: boolean
size:
type: string
tags:
items:
type: string
type: array
type: object
dto.ImageLoad: dto.ImageLoad:
properties: properties:
path: path:
@ -5965,7 +5980,7 @@ paths:
- Container Docker - Container Docker
/containers/image: /containers/image:
get: get:
description: 获取镜像列表 description: 获取镜像名称列表
produces: produces:
- application/json - application/json
responses: responses:
@ -5977,7 +5992,24 @@ paths:
type: array type: array
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: List images summary: load images options
tags:
- Container Image
/containers/image/all:
get:
description: 获取所有镜像列表
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/dto.ImageInfo'
type: array
security:
- ApiKeyAuth: []
summary: List all images
tags: tags:
- Container Image - Container Image
/containers/image/build: /containers/image/build:

View File

@ -53,6 +53,9 @@ export const inspect = (params: Container.ContainerInspect) => {
export const searchImage = (params: SearchWithPage) => { export const searchImage = (params: SearchWithPage) => {
return http.post<ResPage<Container.ImageInfo>>(`/containers/image/search`, params); return http.post<ResPage<Container.ImageInfo>>(`/containers/image/search`, params);
}; };
export const listAllImage = () => {
return http.get<Array<Container.ImageInfo>>(`/containers/image/all`);
};
export const listImage = () => { export const listImage = () => {
return http.get<Array<Container.Options>>(`/containers/image`); return http.get<Array<Container.Options>>(`/containers/image`);
}; };

View File

@ -231,7 +231,7 @@ const onOpenBuild = () => {
}; };
const onOpenPrune = () => { const onOpenPrune = () => {
dialogPruneRef.value!.acceptParams({ list: data.value }); dialogPruneRef.value!.acceptParams();
}; };
const onOpenload = () => { const onOpenload = () => {

View File

@ -48,8 +48,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { Container } from '@/api/interface/container'; import { containerPrune, listAllImage } from '@/api/modules/container';
import { containerPrune } from '@/api/modules/container';
import i18n from '@/lang'; import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message'; import { MsgSuccess } from '@/utils/message';
import { computeSize } from '@/utils/util'; import { computeSize } from '@/utils/util';
@ -61,11 +60,9 @@ const loading = ref();
const unTagList = ref(); const unTagList = ref();
const unUsedList = ref(); const unUsedList = ref();
interface DialogProps { const acceptParams = async (): Promise<void> => {
list: Array<Container.ImageInfo>; const res = await listAllImage();
} let list = res.data || [];
const acceptParams = (params: DialogProps): void => {
let list = params.list || [];
unTagList.value = []; unTagList.value = [];
unUsedList.value = []; unUsedList.value = [];
for (const item of list) { for (const item of list) {