Skip to content

Commit

Permalink
Merge pull request #302 from zong-zhe/fix-oci-url
Browse files Browse the repository at this point in the history
fix: fix download deps from oci url
  • Loading branch information
Peefy authored Apr 23, 2024
2 parents bb39f68 + cc65b50 commit c1ade45
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ require (
github.com/BurntSushi/toml v1.2.1
github.com/docker/distribution v2.8.2+incompatible
github.com/dominikbraun/graph v0.23.0
github.com/opencontainers/image-spec v1.1.0-rc4
github.com/opencontainers/image-spec v1.1.0
github.com/otiai10/copy v1.9.0
github.com/sirupsen/logrus v1.9.0
github.com/urfave/cli/v2 v2.25.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.4.0
kcl-lang.io/kcl-go v0.8.0
)
Expand Down Expand Up @@ -128,7 +129,6 @@ require (
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
kcl-lang.io/lib v0.8.0 // indirect
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0=
github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/otiai10/copy v1.9.0 h1:7KFNiCgZ91Ru4qW4CWPf/7jqtxLagGRmIxWldPP9VY4=
github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3FczI=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
Expand Down
32 changes: 18 additions & 14 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,31 +764,35 @@ func (c *KpmClient) FillDepInfo(dep *pkg.Dependency, homepath string) error {
return nil
}
if dep.Source.Oci != nil {
dep.Source.Oci.Reg = c.GetSettings().DefaultOciRegistry()
urlpath := utils.JoinPath(c.GetSettings().DefaultOciRepo(), dep.Name)
dep.Source.Oci.Repo = urlpath
if len(dep.Source.Oci.Reg) == 0 {
dep.Source.Oci.Reg = c.GetSettings().DefaultOciRegistry()
}

if len(dep.Source.Oci.Repo) == 0 {
urlpath := utils.JoinPath(c.GetSettings().DefaultOciRepo(), dep.Name)
dep.Source.Oci.Repo = urlpath
}
manifest := ocispec.Manifest{}
jsonDesc, err := c.FetchOciManifestIntoJsonStr(opt.OciFetchOptions{
FetchBytesOptions: oras.DefaultFetchBytesOptions,
OciOptions: opt.OciOptions{
Reg: c.GetSettings().DefaultOciRegistry(),
Repo: fmt.Sprintf("%s/%s", c.GetSettings().DefaultOciRepo(), dep.Name),
Reg: dep.Source.Oci.Reg,
Repo: fmt.Sprintf("%s/%s", dep.Source.Oci.Repo, dep.Name),
Tag: dep.Version,
},
})

if err != nil {
return err
}
if err == nil {
err = json.Unmarshal([]byte(jsonDesc), &manifest)
if err != nil {
return err
}

err = json.Unmarshal([]byte(jsonDesc), &manifest)
if err != nil {
return err
if value, ok := manifest.Annotations[constants.DEFAULT_KCL_OCI_MANIFEST_SUM]; ok {
dep.Sum = value
}
}

if value, ok := manifest.Annotations[constants.DEFAULT_KCL_OCI_MANIFEST_SUM]; ok {
dep.Sum = value
}
return nil
}
return nil
Expand Down
15 changes: 15 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1422,3 +1422,18 @@ func TestRunGitWithLocalDep(t *testing.T) {
assert.Equal(t, gotObj, expectObj)
}
}

func TestLoadOciUrlDiffSetting(t *testing.T) {
kpmcli, err := NewKpmClient()
assert.Equal(t, err, nil)

testPath := getTestDir("diffsettings")

pkg, err := kpmcli.LoadPkgFromPath(testPath)
assert.Equal(t, err, nil)
assert.Equal(t, len(pkg.ModFile.Deps), 1)
assert.Equal(t, pkg.ModFile.Deps["oci_pkg"].Oci.Reg, "docker.io")
assert.Equal(t, pkg.ModFile.Deps["oci_pkg"].Oci.Repo, "test/oci_pkg")
assert.Equal(t, pkg.ModFile.Deps["oci_pkg"].Oci.Tag, "0.0.1")
assert.Equal(t, err, nil)
}
7 changes: 7 additions & 0 deletions pkg/client/test_data/diffsettings/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "diffsettings"
edition = "v0.8.0"
version = "0.0.1"

[dependencies]
oci_pkg = { oci = "oci://docker.io/test/oci_pkg", tag = "0.0.1" }
Empty file.
1 change: 1 addition & 0 deletions pkg/client/test_data/diffsettings/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'

0 comments on commit c1ade45

Please sign in to comment.