Skip to content

Commit

Permalink
feat: download kusion modules with current os arch filter (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkYuan committed Apr 29, 2024
1 parent 92243b5 commit 5de6f99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/engine/api/generate/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ func copyDependentModules(workDir string) error {
if dep.Source.Oci != nil {
info := dep.Source.Oci
pkgDir := filepath.Join(absPkgPath, dep.FullName)
source := filepath.Join(pkgDir, runtime.GOOS, runtime.GOARCH, "kusion-module-"+dep.FullName)

source := filepath.Join(pkgDir, "kusion-module-"+dep.FullName)
moduleDir := filepath.Join(kusionHomePath, "modules", info.Repo, info.Tag, runtime.GOOS, runtime.GOARCH)
dest := filepath.Join(moduleDir, fmt.Sprintf("kusion-module-%s", dep.FullName))
if runtime.GOOS == "windows" {
source = fmt.Sprintf("%s.exe", source)
dest = fmt.Sprintf("%s.exe", dest)
}
// copy the module binary to the $KUSION_HOME modules directory
err = io.CopyFile(source, dest)
if err == nil {
// mark the dest file executable
// mark the dest file as executable
err = os.Chmod(dest, 0o755)
}
allErrs = append(allErrs, err)
Expand Down
21 changes: 17 additions & 4 deletions pkg/engine/api/generate/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package run
import (
"os"
"path/filepath"
"runtime"

kcl "kcl-lang.io/kcl-go"
kclpkg "kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kpm/pkg/api"
"kcl-lang.io/kpm/pkg/client"
"kcl-lang.io/kpm/pkg/downloader"
"kcl-lang.io/kpm/pkg/opt"
)

Expand All @@ -23,15 +25,26 @@ var _ CodeRunner = &KPMRunner{}
type KPMRunner struct{}

// Run calls KPM api to compile and run KCL based configuration code.
func (r *KPMRunner) Run(workDir string, arguments map[string]string) ([]byte, error) {
func (r *KPMRunner) Run(workDir string, arguments map[string]string) (res []byte, err error) {
cacheDir := filepath.Join(workDir, ".kclvm")
defer os.RemoveAll(cacheDir)
defer func(path string) {
if err != nil {
return
}
err = os.RemoveAll(path)
}(cacheDir)

optList, err := buildKCLOptions(workDir, arguments)
if err != nil {
return nil, err
}
result, err := api.RunWithOpts(
cli, err := client.NewKpmClient()
if err != nil {
return nil, err
}
cli.DepDownloader = downloader.NewOciDownloader(runtime.GOOS + "/" + runtime.GOARCH)

result, err := cli.RunWithOpts(
opt.WithKclOption(*kclpkg.NewOption().Merge(optList...)),
opt.WithNoSumCheck(false),
opt.WithLogWriter(nil),
Expand Down

0 comments on commit 5de6f99

Please sign in to comment.