Skip to content

Commit 3c1a5ae

Browse files
authored
Merge branch 'main' into improve-backport-locales
2 parents 1b50355 + f020fc2 commit 3c1a5ae

File tree

24 files changed

+657
-447
lines changed

24 files changed

+657
-447
lines changed

.drone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ steps:
726726

727727
# TODO: We should probably build all dependencies into a test image
728728
- name: test-e2e
729-
image: mcr.microsoft.com/playwright:v1.31.2-focal
729+
image: mcr.microsoft.com/playwright:v1.32.1-focal
730730
commands:
731731
- curl -sLO https://go.dev/dl/go1.20.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.20.linux-amd64.tar.gz
732732
- groupadd --gid 1001 gitea && useradd -m --gid 1001 --uid 1001 gitea

.stylelintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ rules:
8888
no-invalid-position-at-import-rule: null
8989
no-irregular-whitespace: true
9090
no-unknown-animations: null
91+
no-unknown-custom-properties: null
9192
number-max-precision: null
9293
property-allowed-list: null
9394
property-disallowed-list: null

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ var migrations = []Migration{
477477
NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner),
478478
// v249 -> v250
479479
NewMigration("Improve Action table indices v3", v1_20.ImproveActionTableIndices),
480+
// v250 -> v251
481+
NewMigration("Change Container Metadata", v1_20.ChangeContainerMetadataMultiArch),
480482
}
481483

482484
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v250.go

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import (
7+
"strings"
8+
9+
"code.gitea.io/gitea/modules/json"
10+
11+
"xorm.io/xorm"
12+
)
13+
14+
func ChangeContainerMetadataMultiArch(x *xorm.Engine) error {
15+
sess := x.NewSession()
16+
defer sess.Close()
17+
18+
if err := sess.Begin(); err != nil {
19+
return err
20+
}
21+
22+
type PackageVersion struct {
23+
ID int64 `xorm:"pk"`
24+
MetadataJSON string `xorm:"metadata_json"`
25+
}
26+
27+
type PackageBlob struct{}
28+
29+
// Get all relevant packages (manifest list images have a container.manifest.reference property)
30+
31+
var pvs []*PackageVersion
32+
err := sess.
33+
Table("package_version").
34+
Select("id, metadata_json").
35+
Where("id IN (SELECT DISTINCT ref_id FROM package_property WHERE ref_type = 0 AND name = 'container.manifest.reference')").
36+
Find(&pvs)
37+
if err != nil {
38+
return err
39+
}
40+
41+
type MetadataOld struct {
42+
Type string `json:"type"`
43+
IsTagged bool `json:"is_tagged"`
44+
Platform string `json:"platform,omitempty"`
45+
Description string `json:"description,omitempty"`
46+
Authors []string `json:"authors,omitempty"`
47+
Licenses string `json:"license,omitempty"`
48+
ProjectURL string `json:"project_url,omitempty"`
49+
RepositoryURL string `json:"repository_url,omitempty"`
50+
DocumentationURL string `json:"documentation_url,omitempty"`
51+
Labels map[string]string `json:"labels,omitempty"`
52+
ImageLayers []string `json:"layer_creation,omitempty"`
53+
MultiArch map[string]string `json:"multiarch,omitempty"`
54+
}
55+
56+
type Manifest struct {
57+
Platform string `json:"platform"`
58+
Digest string `json:"digest"`
59+
Size int64 `json:"size"`
60+
}
61+
62+
type MetadataNew struct {
63+
Type string `json:"type"`
64+
IsTagged bool `json:"is_tagged"`
65+
Platform string `json:"platform,omitempty"`
66+
Description string `json:"description,omitempty"`
67+
Authors []string `json:"authors,omitempty"`
68+
Licenses string `json:"license,omitempty"`
69+
ProjectURL string `json:"project_url,omitempty"`
70+
RepositoryURL string `json:"repository_url,omitempty"`
71+
DocumentationURL string `json:"documentation_url,omitempty"`
72+
Labels map[string]string `json:"labels,omitempty"`
73+
ImageLayers []string `json:"layer_creation,omitempty"`
74+
Manifests []*Manifest `json:"manifests,omitempty"`
75+
}
76+
77+
for _, pv := range pvs {
78+
var old *MetadataOld
79+
if err := json.Unmarshal([]byte(pv.MetadataJSON), &old); err != nil {
80+
return err
81+
}
82+
83+
// Calculate the size of every contained manifest
84+
85+
manifests := make([]*Manifest, 0, len(old.MultiArch))
86+
for platform, digest := range old.MultiArch {
87+
size, err := sess.
88+
Table("package_blob").
89+
Join("INNER", "package_file", "package_blob.id = package_file.blob_id").
90+
Join("INNER", "package_version pv", "pv.id = package_file.version_id").
91+
Join("INNER", "package_version pv2", "pv2.package_id = pv.package_id").
92+
Where("pv.lower_version = ? AND pv2.id = ?", strings.ToLower(digest), pv.ID).
93+
SumInt(new(PackageBlob), "size")
94+
if err != nil {
95+
return err
96+
}
97+
98+
manifests = append(manifests, &Manifest{
99+
Platform: platform,
100+
Digest: digest,
101+
Size: size,
102+
})
103+
}
104+
105+
// Convert to new metadata format
106+
107+
new := &MetadataNew{
108+
Type: old.Type,
109+
IsTagged: old.IsTagged,
110+
Platform: old.Platform,
111+
Description: old.Description,
112+
Authors: old.Authors,
113+
Licenses: old.Licenses,
114+
ProjectURL: old.ProjectURL,
115+
RepositoryURL: old.RepositoryURL,
116+
DocumentationURL: old.DocumentationURL,
117+
Labels: old.Labels,
118+
ImageLayers: old.ImageLayers,
119+
Manifests: manifests,
120+
}
121+
122+
metadataJSON, err := json.Marshal(new)
123+
if err != nil {
124+
return err
125+
}
126+
127+
pv.MetadataJSON = string(metadataJSON)
128+
129+
if _, err := sess.ID(pv.ID).Update(pv); err != nil {
130+
return err
131+
}
132+
}
133+
134+
return sess.Commit()
135+
}

modules/packages/container/metadata.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ type Metadata struct {
6262
DocumentationURL string `json:"documentation_url,omitempty"`
6363
Labels map[string]string `json:"labels,omitempty"`
6464
ImageLayers []string `json:"layer_creation,omitempty"`
65-
MultiArch map[string]string `json:"multiarch,omitempty"`
65+
Manifests []*Manifest `json:"manifests,omitempty"`
66+
}
67+
68+
type Manifest struct {
69+
Platform string `json:"platform"`
70+
Digest string `json:"digest"`
71+
Size int64 `json:"size"`
6672
}
6773

6874
// ParseImageConfig parses the metadata of an image config

modules/packages/container/metadata_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestParseImageConfig(t *testing.T) {
4646
},
4747
metadata.Labels,
4848
)
49-
assert.Empty(t, metadata.MultiArch)
49+
assert.Empty(t, metadata.Manifests)
5050

5151
configHelm := `{"description":"` + description + `", "home": "` + projectURL + `", "sources": ["` + repositoryURL + `"], "maintainers":[{"name":"` + author + `"}]}`
5252

options/locale/locale_fr-FR.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ issues.add_remove_labels=a ajouté %s et supprimé les étiquettes %s %s
993993
issues.add_milestone_at=`a ajouté cela au jalon <b>%s</b> %s`
994994
issues.add_project_at=`a ajouté au projet <b>%s</b> %s`
995995
issues.change_milestone_at=`a modifié le jalon de <b>%s</b> à <b>%s</b> %s`
996-
issues.change_project_at=`modification du projet de <b>%s</b> à <b>%s</b> %s`
996+
issues.change_project_at=modification du projet de <b>%s</b> à <b>%s</b> %s
997997
issues.remove_milestone_at=`a supprimé cela du jalon <b>%s</b> %s`
998998
issues.remove_project_at=`supprimer du projet <b>%s</b> %s`
999999
issues.deleted_milestone=`(supprimée)`

options/locale/locale_pl-PL.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ issues.del_time=Usuń ten dziennik czasu
12761276
issues.add_time_short=Dodaj czas
12771277
issues.add_time_cancel=Anuluj
12781278
issues.add_time_history=`dodał(-a) spędzony czas %s`
1279-
issues.del_time_history=`usunął(-ęła) spędzony czas %s'
1279+
issues.del_time_history=usunął(-ęła) spędzony czas %s
12801280
issues.add_time_hours=Godziny
12811281
issues.add_time_minutes=Minuty
12821282
issues.add_time_sum_to_small=Czas nie został wprowadzony.

options/locale/locale_tr-TR.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ issues.add_remove_labels=%s ekleme ve %s kaldırma işlemlerini %s yaptı
12561256
issues.add_milestone_at=`%[2]s <b>%[1]s</b> kilometre taşına ekledi`
12571257
issues.add_project_at=`bunu %s projesine <b>%s</b> ekledi`
12581258
issues.change_milestone_at=`%s kilometre taşını <b>%s</b> iken <b>%s</b> olarak değiştirdi`
1259-
issues.change_project_at=`%s <b>%s</b> olan projeyi <b>%s</b> olarak değiştirdi
1259+
issues.change_project_at=%s <b>%s</b> olan projeyi <b>%s</b> olarak değiştirdi
12601260
issues.remove_milestone_at=`%[2]s <b>%[1]s</b> kilometre taşından kaldırdı`
12611261
issues.remove_project_at=`bunu %s projesinden <b>%s</b> kaldırdı`
12621262
issues.deleted_milestone=`(silindi)`

options/locale/locale_zh-TW.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ min_size_error=` 長度最小為 %s 個字元。`
474474
max_size_error=` 長度最大為 %s 個字元。`
475475
email_error=` 是無效的電子信箱。`
476476
url_error=`'%s' 是無效的 URL。`
477-
include_error=` 必須包含子字串「%s」。
477+
include_error=必須包含子字串「%s」。
478478
glob_pattern_error=` glob 比對模式無效:%s.`
479479
regex_pattern_error=` 正規表示式模式無效:%s.`
480480
username_error=`只能包含英文字母數字 ('0-9''a-z''A-Z')、破折號 ('-')、底線 ('_')、句點 ('.'),不能以非英文字母數字開頭或結尾,也不允許連續的非英文字母數字。`

0 commit comments

Comments
 (0)