Skip to content

Commit

Permalink
fix: fix CR comments
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe committed Oct 23, 2023
1 parent 93bf00e commit d05a477
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ func (c *KpmClient) PushToOci(localPath string, ociOpts *opt.OciOptions) error {
)
}

return ociCli.Push(localPath, ociOpts.Tag, ociOpts.Annotations)
return ociCli.PushWithOciManifest(localPath, ociOpts.Tag, &opt.OciManifestOptions{
Annotations: ociOpts.Annotations,
})
}

// LoginOci will login to the oci registry.
Expand Down
12 changes: 9 additions & 3 deletions pkg/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/thoas/go-funk"
"kcl-lang.io/kpm/pkg/constants"
"kcl-lang.io/kpm/pkg/errors"
"kcl-lang.io/kpm/pkg/opt"
pkg "kcl-lang.io/kpm/pkg/package"
"kcl-lang.io/kpm/pkg/reporter"
"kcl-lang.io/kpm/pkg/semver"
Expand Down Expand Up @@ -200,7 +201,12 @@ func (ociClient *OciClient) ContainsTag(tag string) (bool, *reporter.KpmEvent) {
}

// Push will push the oci artifacts to oci registry from local path
func (ociClient *OciClient) Push(localPath, tag string, annotations map[string]string) *reporter.KpmEvent {
func (ociClient *OciClient) Push(localPath, tag string) *reporter.KpmEvent {
return ociClient.PushWithOciManifest(localPath, tag, &opt.OciManifestOptions{})
}

// PushWithManifest will push the oci artifacts to oci registry from local path
func (ociClient *OciClient) PushWithOciManifest(localPath, tag string, manifest_opts *opt.OciManifestOptions) *reporter.KpmEvent {
// 0. Create a file store
fs, err := file.New(filepath.Dir(localPath))
if err != nil {
Expand All @@ -226,7 +232,7 @@ func (ociClient *OciClient) Push(localPath, tag string, annotations map[string]s

// 2. Pack the files, tag the packed manifest and add metadata as annotations
packOpts := oras.PackManifestOptions{
ManifestAnnotations: annotations,
ManifestAnnotations: manifest_opts.Annotations,
Layers: fileDescriptors,
}
manifestDescriptor, err := oras.PackManifest(*ociClient.ctx, fs, oras.PackManifestVersion1_1_RC4, DEFAULT_OCI_ARTIFACT_TYPE, packOpts)
Expand Down Expand Up @@ -318,7 +324,7 @@ func Push(localPath, hostName, repoName, tag string, settings *settings.Settings
}

// Push the oci package by the oci client.
return ociClient.Push(localPath, tag, make(map[string]string))
return ociClient.Push(localPath, tag)
}

func GenOciManifestFromPkg(kclPkg *pkg.KclPkg) map[string]string {
Expand Down
4 changes: 4 additions & 0 deletions pkg/opt/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,7 @@ func ParseOciUrl(ociUrl string) (*OciOptions, *reporter.KpmEvent) {
func (oci *OciOptions) AddStoragePathSuffix(pathPrefix string) string {
return filepath.Join(filepath.Join(filepath.Join(pathPrefix, oci.Reg), oci.Repo), oci.Tag)
}

type OciManifestOptions struct {
Annotations map[string]string
}

0 comments on commit d05a477

Please sign in to comment.