Skip to content

Commit

Permalink
Merge branch 'main' into improve-backport-locales
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Apr 3, 2023
2 parents 1b50355 + f020fc2 commit 3c1a5ae
Show file tree
Hide file tree
Showing 24 changed files with 657 additions and 447 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ steps:

# TODO: We should probably build all dependencies into a test image
- name: test-e2e
image: mcr.microsoft.com/playwright:v1.31.2-focal
image: mcr.microsoft.com/playwright:v1.32.1-focal
commands:
- curl -sLO https://go.dev/dl/go1.20.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.20.linux-amd64.tar.gz
- groupadd --gid 1001 gitea && useradd -m --gid 1001 --uid 1001 gitea
Expand Down
1 change: 1 addition & 0 deletions .stylelintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ rules:
no-invalid-position-at-import-rule: null
no-irregular-whitespace: true
no-unknown-animations: null
no-unknown-custom-properties: null
number-max-precision: null
property-allowed-list: null
property-disallowed-list: null
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ var migrations = []Migration{
NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner),
// v249 -> v250
NewMigration("Improve Action table indices v3", v1_20.ImproveActionTableIndices),
// v250 -> v251
NewMigration("Change Container Metadata", v1_20.ChangeContainerMetadataMultiArch),
}

// GetCurrentDBVersion returns the current db version
Expand Down
135 changes: 135 additions & 0 deletions models/migrations/v1_20/v250.go
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()
}
8 changes: 7 additions & 1 deletion modules/packages/container/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ type Metadata struct {
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"`
Manifests []*Manifest `json:"manifests,omitempty"`
}

type Manifest struct {
Platform string `json:"platform"`
Digest string `json:"digest"`
Size int64 `json:"size"`
}

// ParseImageConfig parses the metadata of an image config
Expand Down
2 changes: 1 addition & 1 deletion modules/packages/container/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestParseImageConfig(t *testing.T) {
},
metadata.Labels,
)
assert.Empty(t, metadata.MultiArch)
assert.Empty(t, metadata.Manifests)

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

Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_fr-FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ issues.add_remove_labels=a ajouté %s et supprimé les étiquettes %s %s
issues.add_milestone_at=`a ajouté cela au jalon <b>%s</b> %s`
issues.add_project_at=`a ajouté au projet <b>%s</b> %s`
issues.change_milestone_at=`a modifié le jalon de <b>%s</b> à <b>%s</b> %s`
issues.change_project_at=`modification du projet de <b>%s</b> à <b>%s</b> %s`
issues.change_project_at=modification du projet de <b>%s</b> à <b>%s</b> %s
issues.remove_milestone_at=`a supprimé cela du jalon <b>%s</b> %s`
issues.remove_project_at=`supprimer du projet <b>%s</b> %s`
issues.deleted_milestone=`(supprimée)`
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_pl-PL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ issues.del_time=Usuń ten dziennik czasu
issues.add_time_short=Dodaj czas
issues.add_time_cancel=Anuluj
issues.add_time_history=`dodał(-a) spędzony czas %s`
issues.del_time_history=`usunął(-ęła) spędzony czas %s'
issues.del_time_history=usunął(-ęła) spędzony czas %s
issues.add_time_hours=Godziny
issues.add_time_minutes=Minuty
issues.add_time_sum_to_small=Czas nie został wprowadzony.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_tr-TR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ issues.add_remove_labels=%s ekleme ve %s kaldırma işlemlerini %s yaptı
issues.add_milestone_at=`%[2]s <b>%[1]s</b> kilometre taşına ekledi`
issues.add_project_at=`bunu %s projesine <b>%s</b> ekledi`
issues.change_milestone_at=`%s kilometre taşını <b>%s</b> iken <b>%s</b> olarak değiştirdi`
issues.change_project_at=`%s <b>%s</b> olan projeyi <b>%s</b> olarak değiştirdi
issues.change_project_at=%s <b>%s</b> olan projeyi <b>%s</b> olarak değiştirdi
issues.remove_milestone_at=`%[2]s <b>%[1]s</b> kilometre taşından kaldırdı`
issues.remove_project_at=`bunu %s projesinden <b>%s</b> kaldırdı`
issues.deleted_milestone=`(silindi)`
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ min_size_error=` 長度最小為 %s 個字元。`
max_size_error=` 長度最大為 %s 個字元。`
email_error=` 是無效的電子信箱。`
url_error=`'%s' 是無效的 URL。`
include_error=` 必須包含子字串「%s」。
include_error=必須包含子字串「%s」。
glob_pattern_error=` glob 比對模式無效:%s.`
regex_pattern_error=` 正規表示式模式無效:%s.`
username_error=`只能包含英文字母數字 ('0-9''a-z''A-Z')、破折號 ('-')、底線 ('_')、句點 ('.'),不能以非英文字母數字開頭或結尾,也不允許連續的非英文字母數字。`
Expand Down
Loading

0 comments on commit 3c1a5ae

Please sign in to comment.