diff --git a/pkg/client/client.go b/pkg/client/client.go index 777b1371..f5ea53b0 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -645,7 +645,11 @@ func (c *KpmClient) VendorDeps(kclPkg *pkg.KclPkg) error { // FillDepInfo will fill registry information for a dependency. func (c *KpmClient) FillDepInfo(dep *pkg.Dependency) error { - if dep.Source.Git == nil { + if dep.Source.Local != nil { + dep.LocalFullPath = dep.Source.Local.Path + 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 diff --git a/pkg/cmd/cmd_metadata.go b/pkg/cmd/cmd_metadata.go index e179cf6a..ebb7b367 100644 --- a/pkg/cmd/cmd_metadata.go +++ b/pkg/cmd/cmd_metadata.go @@ -37,6 +37,20 @@ func NewMetadataCmd(kpmcli *client.KpmClient) *cli.Command { }, }, Action: func(c *cli.Context) error { + // acquire the lock of the package cache. + err := kpmcli.AcquirePackageCacheLock() + if err != nil { + return err + } + + defer func() { + // release the lock of the package cache after the function returns. + releaseErr := kpmcli.ReleasePackageCacheLock() + if releaseErr != nil && err == nil { + err = releaseErr + } + }() + pwd, err := os.Getwd() if err != nil { return errors.InternalBug diff --git a/pkg/cmd/cmd_run.go b/pkg/cmd/cmd_run.go index 694f14cb..d703dc12 100644 --- a/pkg/cmd/cmd_run.go +++ b/pkg/cmd/cmd_run.go @@ -81,6 +81,20 @@ func NewRunCmd(kpmcli *client.KpmClient) *cli.Command { } func KpmRun(c *cli.Context, kpmcli *client.KpmClient) error { + // acquire the lock of the package cache. + err := kpmcli.AcquirePackageCacheLock() + if err != nil { + return err + } + + defer func() { + // release the lock of the package cache after the function returns. + releaseErr := kpmcli.ReleasePackageCacheLock() + if releaseErr != nil && err == nil { + err = releaseErr + } + }() + kclOpts := CompileOptionFromCli(c) runEntry, errEvent := runner.FindRunEntryFrom(c.Args().Slice()) if errEvent != nil { diff --git a/pkg/cmd/cmd_update.go b/pkg/cmd/cmd_update.go index 80d9d7c8..012ff83c 100644 --- a/pkg/cmd/cmd_update.go +++ b/pkg/cmd/cmd_update.go @@ -25,6 +25,20 @@ func NewUpdateCmd(kpmcli *client.KpmClient) *cli.Command { } func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error { + // acquire the lock of the package cache. + err := kpmcli.AcquirePackageCacheLock() + if err != nil { + return err + } + + defer func() { + // release the lock of the package cache after the function returns. + releaseErr := kpmcli.ReleasePackageCacheLock() + if releaseErr != nil && err == nil { + err = releaseErr + } + }() + input_paths := c.Args().Slice() pkg_paths := []string{} diff --git a/scripts/pull_pkg.sh b/scripts/pull_pkg.sh index 3f850da4..0531da45 100755 --- a/scripts/pull_pkg.sh +++ b/scripts/pull_pkg.sh @@ -28,4 +28,8 @@ if [ ! -d "./ghcr.io/kcl-lang/k8s/1.27" ]; then $current_dir/bin/kpm pull k8s:1.27 fi +if [ ! -d "./ghcr.io/kcl-lang/helloworld" ]; then + $current_dir/bin/kpm pull helloworld +fi + cd "$current_dir" diff --git a/scripts/push_pkg.sh b/scripts/push_pkg.sh index c96340ac..51eb6e45 100755 --- a/scripts/push_pkg.sh +++ b/scripts/push_pkg.sh @@ -31,6 +31,12 @@ $current_dir/bin/kpm push cd "$current_dir" +# Push the package k8s/1.17 to the registry +cd ./scripts/pkg_in_reg/ghcr.io/kcl-lang/helloworld +$current_dir/bin/kpm push + +cd "$current_dir" + # Push the package 'kcl1' depends on 'k8s' to the registry cd ./scripts/pkg_in_reg/kcl1 $current_dir/bin/kpm push diff --git a/test/e2e/kpm_test.go b/test/e2e/kpm_test.go index 49c42b22..48a3c8e1 100644 --- a/test/e2e/kpm_test.go +++ b/test/e2e/kpm_test.go @@ -143,8 +143,31 @@ var _ = ginkgo.Describe("Kpm CLI Testing", func() { expectedStderr := ReplaceAllKeyByValue(ts.ExpectStderr, "", workspace) gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - gomega.Expect(stdout).To(gomega.Equal(expectedStdout)) - gomega.Expect(stderr).To(gomega.Equal(expectedStderr)) + gomega.Expect(stdout).To(gomega.ContainSubstring(expectedStdout)) + gomega.Expect(stderr).To(gomega.ContainSubstring(expectedStderr)) + }) + } + }) + + ginkgo.Context("testing 'kpm update '", func() { + testSuitesRoot := filepath.Join(filepath.Join(filepath.Join(GetWorkDir(), TEST_SUITES_DIR), "kpm"), "kpm_update") + testSuites := LoadAllTestSuites(testSuitesRoot) + testDataRoot := filepath.Join(filepath.Join(GetWorkDir(), TEST_SUITES_DIR), "test_data") + for _, ts := range testSuites { + ts := ts + ginkgo.It(ts.GetTestSuiteInfo(), func() { + workspace := GetWorkspace() + CopyDir(filepath.Join(testDataRoot, ts.Name), filepath.Join(workspace, ts.Name)) + + input := ReplaceAllKeyByValue(ts.Input, "", filepath.Join(workspace, ts.Name)) + stdout, stderr, err := ExecKpmWithWorkDir(input, filepath.Join(workspace, ts.Name, "test_update")) + + expectedStdout := ReplaceAllKeyByValue(ts.ExpectStdout, "", workspace) + expectedStderr := ReplaceAllKeyByValue(ts.ExpectStderr, "", workspace) + + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(stdout).To(gomega.ContainSubstring(expectedStdout)) + gomega.Expect(stderr).To(gomega.ContainSubstring(expectedStderr)) }) } }) diff --git a/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.env b/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.env new file mode 100644 index 00000000..4c789529 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.env @@ -0,0 +1,2 @@ +KPM_HOME="" +KCLVM_VENDOR_HOME="" \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.input b/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.input new file mode 100644 index 00000000..f17b39a2 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.input @@ -0,0 +1 @@ +kpm update \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.stderr new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.stdout new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_update/test_update_with_all/test_suite.stdout @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_update_with_all/test_update/kcl.mod b/test/e2e/test_suites/test_data/test_update_with_all/test_update/kcl.mod new file mode 100644 index 00000000..1126e796 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_update_with_all/test_update/kcl.mod @@ -0,0 +1,9 @@ +[package] +name = "test_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +test_update_1 = { path = "./../test_update_1" } +helloworld = "0.1.1" +catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.1" } diff --git a/test/e2e/test_suites/test_data/test_update_with_all/test_update/kcl.mod.lock b/test/e2e/test_suites/test_data/test_update_with_all/test_update/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_update_with_all/test_update/main.k b/test/e2e/test_suites/test_data/test_update_with_all/test_update/main.k new file mode 100644 index 00000000..e5f519e8 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_update_with_all/test_update/main.k @@ -0,0 +1,114 @@ +import catalog.models.schema.v1 as ac +import catalog.models.schema.v1.trait as t +import catalog.models.schema.v1.workload as wl +import catalog.models.schema.v1.workload.container as c +import catalog.models.schema.v1.workload.container.probe as p +import catalog.models.schema.v1.workload.secret as sec +import catalog.models.schema.v1.workload.network as n +import catalog.models.schema.v1.monitoring as m + +import test_update_1 as tu +import helloworld as oci_helloworld + +local = tu.The_first_kcl_program +oci = oci_helloworld.The_first_kcl_program + +# base.k declares reusable configurations for all stacks. +hello: ac.AppConfiguration { + workload: wl.Service { + containers: { + "nginx": c.Container { + image: "nginx:v1" + # Run the following command as defined + command: ["/bin/sh", "-c", "echo hi"] + # Extra arguments append to command defined above + args: ["/bin/sh", "-c", "echo hi"] + env: { + # An environment variable of name "env1" and value "VALUE" will be set + "env1": "VALUE" + # An environment variable of name "env2" and value of the key "key" in the + # secret named "sec-name" will be set. + "env2": "secret://sec-name/key" + } + # Run the command "/bin/sh -c echo hi", as defined above, in the directory "/tmp" + workingDir: "/tmp" + resources: { + "cpu": "2" + "memory": "4Gi" + } + # Configure a HTTP readiness probe + readinessProbe: p.Probe { + probeHandler: p.Http { + url: "http://localhost:80" + } + initialDelaySeconds: 10 + } + } + } + secrets: { + "basic-auth": sec.Secret { + $type: "basic" + data: { + "username": "admin" + "password": "******" + } + } + } + replicas: 2 + ports: [ + n.Port { + type: "aliyun" + port: 80 + targetPort: 8080 + public: True + } + ] + } + # Add the monitoring configuration backed by Prometheus + monitoring: m.Prometheus{ + interval: "30s" + timeout: "15s" + path: "/metrics" + port: "web" + scheme: "http" + } +} + +hellocollaset: ac.AppConfiguration { + workload: wl.Service { + type: "CollaSet" + containers: { + "nginx": c.Container { + image: "nginx:v1" + # Run the following command as defined + command: ["/bin/sh", "-c", "echo hi"] + # Extra arguments append to command defined above + args: ["/bin/sh", "-c", "echo hi"] + # Run the command "/bin/sh -c echo hi", as defined above, in the directory "/tmp" + workingDir: "/tmp" + } + } + ports: [ + n.Port { + port: 80 + } + ] + } + opsRule: t.OpsRule { + maxUnavailable: "30%" + } +} + +hellojob: ac.AppConfiguration { + workload: wl.Job { + containers: { + "busybox": c.Container { + image: "busybox:1.28" + # Run the following command as defined + command: ["/bin/sh", "-c", "echo hello"] + } + } + # Run every hour. + schedule: "0 * * * *" + } +} diff --git a/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/kcl.mod b/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/kcl.mod new file mode 100644 index 00000000..a2631b05 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "test_update_1" +edition = "0.0.1" +version = "0.0.1" + diff --git a/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/kcl.mod.lock b/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/kcl.mod.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/main.k b/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/main.k new file mode 100644 index 00000000..89130595 --- /dev/null +++ b/test/e2e/test_suites/test_data/test_update_with_all/test_update_1/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello Local !' \ No newline at end of file