aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/packages
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-04-02 11:53:37 +0200
committerGitHub <noreply@github.com>2023-04-02 17:53:37 +0800
commitfbd4eaceed801e7400ed04a9dadedaf3a25dccb9 (patch)
tree9c25636fbfa755702b77f781147a096e5eafd309 /routers/api/packages
parentf5593d08dc6d615e650fe5e954b300d1895212b7 (diff)
downloadgitea-fbd4eaceed801e7400ed04a9dadedaf3a25dccb9.tar.gz
gitea-fbd4eaceed801e7400ed04a9dadedaf3a25dccb9.zip
Display image size for multiarch container images (#23821)
Fixes #23771 Changes the display of different architectures for multiarch images to show the image size: ![grafik](https://user-images.githubusercontent.com/1666336/228781477-cc76c4d1-4728-434f-8a27-fc008790d924.png)
Diffstat (limited to 'routers/api/packages')
-rw-r--r--routers/api/packages/container/manifest.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/routers/api/packages/container/manifest.go b/routers/api/packages/container/manifest.go
index e36c6a851b..1dbd058d6b 100644
--- a/routers/api/packages/container/manifest.go
+++ b/routers/api/packages/container/manifest.go
@@ -217,7 +217,7 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H
metadata := &container_module.Metadata{
Type: container_module.TypeOCI,
- MultiArch: make(map[string]string),
+ Manifests: make([]*container_module.Manifest, 0, len(index.Manifests)),
}
for _, manifest := range index.Manifests {
@@ -233,7 +233,7 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H
}
}
- _, err := container_model.GetContainerBlob(ctx, &container_model.BlobSearchOptions{
+ pfd, err := container_model.GetContainerBlob(ctx, &container_model.BlobSearchOptions{
OwnerID: mci.Owner.ID,
Image: mci.Image,
Digest: string(manifest.Digest),
@@ -246,7 +246,18 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H
return err
}
- metadata.MultiArch[platform] = string(manifest.Digest)
+ size, err := packages_model.CalculateFileSize(ctx, &packages_model.PackageFileSearchOptions{
+ VersionID: pfd.File.VersionID,
+ })
+ if err != nil {
+ return err
+ }
+
+ metadata.Manifests = append(metadata.Manifests, &container_module.Manifest{
+ Platform: platform,
+ Digest: string(manifest.Digest),
+ Size: size,
+ })
}
pv, err := createPackageAndVersion(ctx, mci, metadata)
@@ -369,8 +380,8 @@ func createPackageAndVersion(ctx context.Context, mci *manifestCreationInfo, met
return nil, err
}
}
- for _, digest := range metadata.MultiArch {
- if _, err := packages_model.InsertProperty(ctx, packages_model.PropertyTypeVersion, pv.ID, container_module.PropertyManifestReference, digest); err != nil {
+ for _, manifest := range metadata.Manifests {
+ if _, err := packages_model.InsertProperty(ctx, packages_model.PropertyTypeVersion, pv.ID, container_module.PropertyManifestReference, manifest.Digest); err != nil {
log.Error("Error setting package version property: %v", err)
return nil, err
}