Skip to content

Commit

Permalink
Merge pull request #134 from klothoplatform/open-sourcing
Browse files Browse the repository at this point in the history
Open Source Preprocessing
  • Loading branch information
atorres-klo authored Aug 14, 2024
2 parents ad31162 + 52bad11 commit 45bb151
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 124 deletions.
39 changes: 9 additions & 30 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,19 @@
}
},
{
"name": "Klotho",
"name": "Debug: Klotho",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./cmd/klotho",
"cwd": "${workspaceFolder}",
"args": [
"-v",
"-a",
// "b879296f-94dd-4cb7-a7fe-99980965376f", // prod ID
"2fa61fd0-e1db-4557-bf82-3c98c020a598", // local ID
"../infracopilot"
],
"env": {
"BROWSER": "none",
"INFRACOPILOT_URL": "http://localhost:3000",
"AUTH_DOMAIN": "klotho-dev.us.auth0.com",
"AUTH_CLIENT_ID": "A0sIE3wvh8LpG8mtJEjWPnBqZgBs5cNM"
}
},
{
"name": "Debug: k2",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./cmd/k2",
// CWD is mostly responsible for the pipenv environment. There's one at the root that can be used generally.
// If a specific env is needed, uncomment the following line.
// "cwd": "${fileDirname}",
"args": [
"up",
"-v=3",
"--state-directory=${workspaceFolder}/out",
"--profiling=${workspaceFolder}/out/k2.prof",
"--profiling=${workspaceFolder}/out/klotho.prof",
"-n=1",
"--debug=vscode",
"${file}"
Expand All @@ -115,11 +94,11 @@
},
},
{
"name": "k2: deploy",
"name": "Klotho: deploy",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./cmd/k2",
"program": "./cmd/klotho",
"cwd": "${fileDirname}",
"args": [
"up",
Expand All @@ -135,11 +114,11 @@
"console": "integratedTerminal"
},
{
"name": "k2: destroy",
"name": "Klotho: destroy",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./cmd/k2",
"program": "./cmd/klotho",
"cwd": "${fileDirname}",
"args": [
"down",
Expand All @@ -157,12 +136,12 @@
],
"compounds": [
{
"name": "Debug: k2 + infra.py",
"name": "Debug: Llotho + infra.py",
"configurations": [
"Debug: k2",
"Debug: Klotho",
"Python Debugger: Listen"
],
"stopAll": true,
}
]
}
}
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"**/node_modules": true
},
"go.testTimeout": "5m",
"go.lintTool": "golangci-lint"
}
"go.lintTool": "golangci-lint",
"makefile.configureOnOpen": false
}
3 changes: 0 additions & 3 deletions cmd/k2/buildinfo.go

This file was deleted.

86 changes: 0 additions & 86 deletions cmd/k2/main.go

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
82 changes: 82 additions & 0 deletions cmd/klotho/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,86 @@
package main

import (
"os"
"syscall"

"github.com/klothoplatform/klotho/pkg/k2/cleanup"
"github.com/klothoplatform/klotho/pkg/logging"
"go.uber.org/zap"

clicommon "github.com/klothoplatform/klotho/pkg/cli_common"
"github.com/spf13/cobra"
)

var commonCfg struct {
clicommon.CommonConfig
dryRun clicommon.LevelledFlag
}

func cli() int {
// Set up signal and panic handling to ensure cleanup is executed
defer func() {
if r := recover(); r != nil {
_ = cleanup.Execute(syscall.SIGTERM)
panic(r)
}
}()

var rootCmd = &cobra.Command{
Use: "app",
SilenceUsage: true,
}

rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
cmd.SetContext(cleanup.InitializeHandler(cmd.Context()))
cmd.SilenceErrors = true
}

flags := rootCmd.PersistentFlags()
dryRunFlag := flags.VarPF(&commonCfg.dryRun, "dry-run", "n", "Dry run (once for pulumi preview, twice for tsc)")
dryRunFlag.NoOptDefVal = "true" // Allow -n to be used without a value

var cleanupFuncs []func()
defer func() {
for _, f := range cleanupFuncs {
f()
}
}()

initCommand := newInitCommand()

upCommand := newUpCmd()
cleanupFuncs = append(cleanupFuncs, clicommon.SetupCoreCommand(upCommand, &commonCfg.CommonConfig))

downCommand := newDownCmd()
cleanupFuncs = append(cleanupFuncs, clicommon.SetupCoreCommand(downCommand, &commonCfg.CommonConfig))

var irCommand = &cobra.Command{
Use: "ir [file path]",
Short: "Run the IR command",
//Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
filePath := args[0]
if _, err := os.Stat(filePath); err != nil {
return err
}
irCmd(filePath)
return nil
},
}

rootCmd.AddCommand(initCommand)
rootCmd.AddCommand(upCommand)
rootCmd.AddCommand(downCommand)
rootCmd.AddCommand(irCommand)

if err := rootCmd.Execute(); err != nil {
logging.GetLogger(rootCmd.Context()).Error("Failed to execute command", zap.Error(err))
return 1
}
return 0
}

func main() {
os.Exit(cli())
}
File renamed without changes.
6 changes: 3 additions & 3 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def release(goos, arch, out_dir):

Path(out_dir).mkdir(parents=True, exist_ok=True)

for prog in ["engine", "iac", "k2"]:
for prog in ["engine", "iac", "klotho"]:
prog_env = env.copy()
if prog == "iac" or prog == "k2":
if prog == "iac" or prog == "klotho":
# IaC rendering requires cgo for treesitter parsing of the pulumi ts templates
# both 'iac' and 'k2' do iac rendering
# both 'iac' and 'klotho' do iac rendering
prog_env["CGO_ENABLED"] = "1"

zig_arch = arch_to_zig_target[arch]
Expand Down

0 comments on commit 45bb151

Please sign in to comment.