Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: download kusion modules with current os arch filter #1081

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading