forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
* upstream/main: [skip ci] Updated translations via Crowdin Update JS deps (go-gitea#23853) Added close/open button to details page of milestone (go-gitea#23877) Check `IsActionsToken` for LFS authentication (go-gitea#23841) Prefill input values in oauth settings as intended (go-gitea#23829) Display image size for multiarch container images (go-gitea#23821) Use clippie module to copy to clipboard (go-gitea#23801) Remove assertion debug code for show/hide refactoring (go-gitea#23576) [skip ci] Updated translations via Crowdin Remove jQuery ready usage (go-gitea#23858) Fix JS error when changing PR's target branch (go-gitea#23862) Improve action log display with control chars (go-gitea#23820) Fix review conversation reply (go-gitea#23846) Improve home page template, fix Sort dropdown menu flash (go-gitea#23856) Make first section on home page full width (go-gitea#23854) [skip ci] Updated translations via Crowdin Fix incorrect CORS failure detection logic (go-gitea#23844)
- Loading branch information
Showing
36 changed files
with
801 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_20 //nolint | ||
|
||
import ( | ||
"strings" | ||
|
||
"code.gitea.io/gitea/modules/json" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func ChangeContainerMetadataMultiArch(x *xorm.Engine) error { | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
|
||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
|
||
type PackageVersion struct { | ||
ID int64 `xorm:"pk"` | ||
MetadataJSON string `xorm:"metadata_json"` | ||
} | ||
|
||
type PackageBlob struct{} | ||
|
||
// Get all relevant packages (manifest list images have a container.manifest.reference property) | ||
|
||
var pvs []*PackageVersion | ||
err := sess. | ||
Table("package_version"). | ||
Select("id, metadata_json"). | ||
Where("id IN (SELECT DISTINCT ref_id FROM package_property WHERE ref_type = 0 AND name = 'container.manifest.reference')"). | ||
Find(&pvs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
type MetadataOld struct { | ||
Type string `json:"type"` | ||
IsTagged bool `json:"is_tagged"` | ||
Platform string `json:"platform,omitempty"` | ||
Description string `json:"description,omitempty"` | ||
Authors []string `json:"authors,omitempty"` | ||
Licenses string `json:"license,omitempty"` | ||
ProjectURL string `json:"project_url,omitempty"` | ||
RepositoryURL string `json:"repository_url,omitempty"` | ||
DocumentationURL string `json:"documentation_url,omitempty"` | ||
Labels map[string]string `json:"labels,omitempty"` | ||
ImageLayers []string `json:"layer_creation,omitempty"` | ||
MultiArch map[string]string `json:"multiarch,omitempty"` | ||
} | ||
|
||
type Manifest struct { | ||
Platform string `json:"platform"` | ||
Digest string `json:"digest"` | ||
Size int64 `json:"size"` | ||
} | ||
|
||
type MetadataNew struct { | ||
Type string `json:"type"` | ||
IsTagged bool `json:"is_tagged"` | ||
Platform string `json:"platform,omitempty"` | ||
Description string `json:"description,omitempty"` | ||
Authors []string `json:"authors,omitempty"` | ||
Licenses string `json:"license,omitempty"` | ||
ProjectURL string `json:"project_url,omitempty"` | ||
RepositoryURL string `json:"repository_url,omitempty"` | ||
DocumentationURL string `json:"documentation_url,omitempty"` | ||
Labels map[string]string `json:"labels,omitempty"` | ||
ImageLayers []string `json:"layer_creation,omitempty"` | ||
Manifests []*Manifest `json:"manifests,omitempty"` | ||
} | ||
|
||
for _, pv := range pvs { | ||
var old *MetadataOld | ||
if err := json.Unmarshal([]byte(pv.MetadataJSON), &old); err != nil { | ||
return err | ||
} | ||
|
||
// Calculate the size of every contained manifest | ||
|
||
manifests := make([]*Manifest, 0, len(old.MultiArch)) | ||
for platform, digest := range old.MultiArch { | ||
size, err := sess. | ||
Table("package_blob"). | ||
Join("INNER", "package_file", "package_blob.id = package_file.blob_id"). | ||
Join("INNER", "package_version pv", "pv.id = package_file.version_id"). | ||
Join("INNER", "package_version pv2", "pv2.package_id = pv.package_id"). | ||
Where("pv.lower_version = ? AND pv2.id = ?", strings.ToLower(digest), pv.ID). | ||
SumInt(new(PackageBlob), "size") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
manifests = append(manifests, &Manifest{ | ||
Platform: platform, | ||
Digest: digest, | ||
Size: size, | ||
}) | ||
} | ||
|
||
// Convert to new metadata format | ||
|
||
new := &MetadataNew{ | ||
Type: old.Type, | ||
IsTagged: old.IsTagged, | ||
Platform: old.Platform, | ||
Description: old.Description, | ||
Authors: old.Authors, | ||
Licenses: old.Licenses, | ||
ProjectURL: old.ProjectURL, | ||
RepositoryURL: old.RepositoryURL, | ||
DocumentationURL: old.DocumentationURL, | ||
Labels: old.Labels, | ||
ImageLayers: old.ImageLayers, | ||
Manifests: manifests, | ||
} | ||
|
||
metadataJSON, err := json.Marshal(new) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
pv.MetadataJSON = string(metadataJSON) | ||
|
||
if _, err := sess.ID(pv.ID).Update(pv); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return sess.Commit() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.