mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 16:48:30 +01:00
Persistent the URLs and annotations of artifact references in database
Persistent the URLs and annotations of artifact references in database Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
a5d9a3b65d
commit
76c04b0219
@ -105,7 +105,10 @@ CREATE TABLE artifact_reference
|
|||||||
id SERIAL PRIMARY KEY NOT NULL,
|
id SERIAL PRIMARY KEY NOT NULL,
|
||||||
parent_id int NOT NULL,
|
parent_id int NOT NULL,
|
||||||
child_id int NOT NULL,
|
child_id int NOT NULL,
|
||||||
|
child_digest varchar(255) NOT NULL ,
|
||||||
platform varchar(255),
|
platform varchar(255),
|
||||||
|
urls varchar(1024),
|
||||||
|
annotations jsonb,
|
||||||
FOREIGN KEY (parent_id) REFERENCES artifact(id),
|
FOREIGN KEY (parent_id) REFERENCES artifact(id),
|
||||||
FOREIGN KEY (child_id) REFERENCES artifact(id),
|
FOREIGN KEY (child_id) REFERENCES artifact(id),
|
||||||
CONSTRAINT unique_reference UNIQUE (parent_id, child_id)
|
CONSTRAINT unique_reference UNIQUE (parent_id, child_id)
|
||||||
|
@ -67,8 +67,11 @@ func (r *resolver) ResolveMetadata(ctx context.Context, manifest []byte, art *ar
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
art.References = append(art.References, &artifact.Reference{
|
art.References = append(art.References, &artifact.Reference{
|
||||||
ChildID: ar.ID,
|
ChildID: ar.ID,
|
||||||
Platform: mani.Platform,
|
ChildDigest: digest,
|
||||||
|
Platform: mani.Platform,
|
||||||
|
URLs: mani.URLs,
|
||||||
|
Annotations: mani.Annotations,
|
||||||
})
|
})
|
||||||
// try to get the digest of the manifest that the config layer is referenced by
|
// try to get the digest of the manifest that the config layer is referenced by
|
||||||
if mani.Annotations != nil &&
|
if mani.Annotations != nil &&
|
||||||
|
@ -63,8 +63,11 @@ func (i *indexResolver) ResolveMetadata(ctx context.Context, manifest []byte, ar
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
art.References = append(art.References, &artifact.Reference{
|
art.References = append(art.References, &artifact.Reference{
|
||||||
ChildID: ar.ID,
|
ChildID: ar.ID,
|
||||||
Platform: mani.Platform,
|
ChildDigest: digest,
|
||||||
|
Platform: mani.Platform,
|
||||||
|
URLs: mani.URLs,
|
||||||
|
Annotations: mani.Annotations,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -49,10 +49,13 @@ func (a *Artifact) TableName() string {
|
|||||||
|
|
||||||
// ArtifactReference records the child artifact referenced by parent artifact
|
// ArtifactReference records the child artifact referenced by parent artifact
|
||||||
type ArtifactReference struct {
|
type ArtifactReference struct {
|
||||||
ID int64 `orm:"pk;auto;column(id)"`
|
ID int64 `orm:"pk;auto;column(id)"`
|
||||||
ParentID int64 `orm:"column(parent_id)"`
|
ParentID int64 `orm:"column(parent_id)"`
|
||||||
ChildID int64 `orm:"column(child_id)"`
|
ChildID int64 `orm:"column(child_id)"`
|
||||||
Platform string `orm:"column(platform)"` // json string
|
ChildDigest string `orm:"column(child_digest)"`
|
||||||
|
Platform string `orm:"column(platform)"` // json string
|
||||||
|
URLs string `orm:"column(urls)"` // json string
|
||||||
|
Annotations string `orm:"column(annotations);type(jsonb)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName for artifact reference
|
// TableName for artifact reference
|
||||||
|
@ -135,11 +135,6 @@ func (m *manager) ListReferences(ctx context.Context, query *q.Query) ([]*Refere
|
|||||||
for _, reference := range references {
|
for _, reference := range references {
|
||||||
ref := &Reference{}
|
ref := &Reference{}
|
||||||
ref.From(reference)
|
ref.From(reference)
|
||||||
art, err := m.dao.Get(ctx, reference.ChildID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ref.ChildDigest = art.Digest
|
|
||||||
refs = append(refs, ref)
|
refs = append(refs, ref)
|
||||||
}
|
}
|
||||||
return refs, nil
|
return refs, nil
|
||||||
|
@ -122,9 +122,6 @@ func (m *managerTestSuite) TestAssemble() {
|
|||||||
ChildID: 3,
|
ChildID: 3,
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
m.dao.On("Get").Return(&dao.Artifact{
|
|
||||||
Digest: "digest",
|
|
||||||
}, nil)
|
|
||||||
artifact, err := m.mgr.assemble(nil, art)
|
artifact, err := m.mgr.assemble(nil, art)
|
||||||
m.Require().Nil(err)
|
m.Require().Nil(err)
|
||||||
m.dao.AssertExpectations(m.T())
|
m.dao.AssertExpectations(m.T())
|
||||||
@ -244,15 +241,10 @@ func (m *managerTestSuite) TestListReferences() {
|
|||||||
ChildID: 2,
|
ChildID: 2,
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
m.dao.On("Get").Return(&dao.Artifact{
|
|
||||||
ID: 1,
|
|
||||||
Digest: "digest",
|
|
||||||
}, nil)
|
|
||||||
references, err := m.mgr.ListReferences(nil, nil)
|
references, err := m.mgr.ListReferences(nil, nil)
|
||||||
m.Require().Nil(err)
|
m.Require().Nil(err)
|
||||||
m.Require().Len(references, 1)
|
m.Require().Len(references, 1)
|
||||||
m.Equal(int64(1), references[0].ID)
|
m.Equal(int64(1), references[0].ID)
|
||||||
m.Equal("digest", references[0].ChildDigest)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *managerTestSuite) TestDeleteReference() {
|
func (m *managerTestSuite) TestDeleteReference() {
|
||||||
|
@ -114,8 +114,10 @@ type Reference struct {
|
|||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
ParentID int64 `json:"parent_id"`
|
ParentID int64 `json:"parent_id"`
|
||||||
ChildID int64 `json:"child_id"`
|
ChildID int64 `json:"child_id"`
|
||||||
ChildDigest string `json:"child_digest"` // As we only provide the API based on digest rather than ID, the digest of child artifact is needed
|
ChildDigest string `json:"child_digest"`
|
||||||
Platform *v1.Platform
|
Platform *v1.Platform
|
||||||
|
URLs []string `json:"urls"`
|
||||||
|
Annotations map[string]string `json:"annotations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// From converts the data level reference to business level
|
// From converts the data level reference to business level
|
||||||
@ -123,20 +125,34 @@ func (r *Reference) From(ref *dao.ArtifactReference) {
|
|||||||
r.ID = ref.ID
|
r.ID = ref.ID
|
||||||
r.ParentID = ref.ParentID
|
r.ParentID = ref.ParentID
|
||||||
r.ChildID = ref.ChildID
|
r.ChildID = ref.ChildID
|
||||||
|
r.ChildDigest = ref.ChildDigest
|
||||||
if len(ref.Platform) > 0 {
|
if len(ref.Platform) > 0 {
|
||||||
r.Platform = &v1.Platform{}
|
r.Platform = &v1.Platform{}
|
||||||
if err := json.Unmarshal([]byte(ref.Platform), r.Platform); err != nil {
|
if err := json.Unmarshal([]byte(ref.Platform), r.Platform); err != nil {
|
||||||
log.Errorf("failed to unmarshal the platform of reference: %v", err)
|
log.Errorf("failed to unmarshal the platform of reference: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(ref.URLs) > 0 {
|
||||||
|
r.URLs = []string{}
|
||||||
|
if err := json.Unmarshal([]byte(ref.URLs), &r.URLs); err != nil {
|
||||||
|
log.Errorf("failed to unmarshal the URLs of reference: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(ref.Annotations) > 0 {
|
||||||
|
r.Annotations = map[string]string{}
|
||||||
|
if err := json.Unmarshal([]byte(ref.Annotations), &r.Annotations); err != nil {
|
||||||
|
log.Errorf("failed to unmarshal the annotations of reference: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// To converts the reference to data level object
|
// To converts the reference to data level object
|
||||||
func (r *Reference) To() *dao.ArtifactReference {
|
func (r *Reference) To() *dao.ArtifactReference {
|
||||||
ref := &dao.ArtifactReference{
|
ref := &dao.ArtifactReference{
|
||||||
ID: r.ID,
|
ID: r.ID,
|
||||||
ParentID: r.ParentID,
|
ParentID: r.ParentID,
|
||||||
ChildID: r.ChildID,
|
ChildID: r.ChildID,
|
||||||
|
ChildDigest: r.ChildDigest,
|
||||||
}
|
}
|
||||||
if r.Platform != nil {
|
if r.Platform != nil {
|
||||||
platform, err := json.Marshal(r.Platform)
|
platform, err := json.Marshal(r.Platform)
|
||||||
@ -145,5 +161,19 @@ func (r *Reference) To() *dao.ArtifactReference {
|
|||||||
}
|
}
|
||||||
ref.Platform = string(platform)
|
ref.Platform = string(platform)
|
||||||
}
|
}
|
||||||
|
if len(r.URLs) > 0 {
|
||||||
|
urls, err := json.Marshal(r.URLs)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to marshal the URLs of reference: %v", err)
|
||||||
|
}
|
||||||
|
ref.URLs = string(urls)
|
||||||
|
}
|
||||||
|
if len(r.Annotations) > 0 {
|
||||||
|
annotations, err := json.Marshal(r.Annotations)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to marshal the annotations of reference: %v", err)
|
||||||
|
}
|
||||||
|
ref.Annotations = string(annotations)
|
||||||
|
}
|
||||||
return ref
|
return ref
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user