Move prototype 69-dagger-archon to top-level
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
14
cmd/dagger-frontend/main.go
Normal file
14
cmd/dagger-frontend/main.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.cloud/go/dagger"
|
||||
"github.com/moby/buildkit/frontend/gateway/grpcclient"
|
||||
"github.com/moby/buildkit/util/appcontext"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := &dagger.Runtime{}
|
||||
if err := grpcclient.RunFromEnvironment(appcontext.Context(), r.BKFrontend); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
2
cmd/dagger/.gitignore
vendored
Normal file
2
cmd/dagger/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
dagger
|
||||
.dagger
|
50
cmd/dagger/cmd/compute.go
Normal file
50
cmd/dagger/cmd/compute.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"dagger.cloud/go/dagger"
|
||||
"dagger.cloud/go/dagger/ui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var computeCmd = &cobra.Command{
|
||||
Use: "compute CONFIG",
|
||||
Short: "Compute a configuration",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := context.TODO()
|
||||
c, err := dagger.NewClient(ctx, "")
|
||||
if err != nil {
|
||||
ui.Fatal(err)
|
||||
}
|
||||
target := args[0]
|
||||
if target == "-" {
|
||||
ui.Info("Assembling config from stdin\n")
|
||||
// FIXME: include cue.mod/pkg from *somewhere* so stdin config can import
|
||||
if err := c.SetConfig(os.Stdin); err != nil {
|
||||
ui.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
ui.Info("Assembling config from %q\n", target)
|
||||
if err := c.SetConfig(target); err != nil {
|
||||
ui.Fatal(err)
|
||||
}
|
||||
}
|
||||
ui.Info("Running")
|
||||
output, err := c.Run(ctx, "compute")
|
||||
if err != nil {
|
||||
ui.Fatal(err)
|
||||
}
|
||||
ui.Info("Processing output")
|
||||
// output.Print(os.Stdout)
|
||||
fmt.Println(output.JSON())
|
||||
// FIXME: write computed values back to env dir
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
// computeCmd.Flags().StringP("catalog", "c", "", "Cue package catalog")
|
||||
}
|
35
cmd/dagger/cmd/create.go
Normal file
35
cmd/dagger/cmd/create.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"dagger.cloud/go/dagger/ui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var createCmd = &cobra.Command{
|
||||
Use: "create ENV BASE",
|
||||
Short: "Create an env",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
envname := args[0]
|
||||
base := args[1]
|
||||
envdir := ".dagger/env/" + envname
|
||||
if info, err := os.Stat(envdir); err == nil {
|
||||
if info.IsDir() {
|
||||
ui.Fatalf("env already exists: %s", envname)
|
||||
}
|
||||
}
|
||||
if err := os.MkdirAll(envdir, 0755); err != nil {
|
||||
ui.Fatal(err)
|
||||
}
|
||||
baseCue := fmt.Sprintf("package env\nimport base \"%s\"\nbase\n", base)
|
||||
err := ioutil.WriteFile(envdir+"/base.cue", []byte(baseCue), 0644)
|
||||
if err != nil {
|
||||
ui.Fatal(err)
|
||||
}
|
||||
ui.Info("created environment %q with base %q", envname, base)
|
||||
},
|
||||
}
|
37
cmd/dagger/cmd/root.go
Normal file
37
cmd/dagger/cmd/root.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"dagger.cloud/go/dagger/ui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "dagger",
|
||||
Short: "Open-source workflow engine",
|
||||
}
|
||||
|
||||
func init() {
|
||||
// --debug
|
||||
rootCmd.PersistentFlags().Bool("debug", false, "Enable debug mode")
|
||||
// --workspace
|
||||
rootCmd.PersistentFlags().StringP("workspace", "w", "", "Select workspace")
|
||||
rootCmd.AddCommand(
|
||||
// Create an env
|
||||
createCmd,
|
||||
computeCmd,
|
||||
// Change settings on an env
|
||||
// View or edit env serti
|
||||
// settingsCmd,
|
||||
// Query the state of an env
|
||||
// getCmd,
|
||||
// unsetCmd,
|
||||
// computeCmd,
|
||||
// listCmd,
|
||||
)
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
ui.Fatal(err)
|
||||
}
|
||||
}
|
9
cmd/dagger/main.go
Normal file
9
cmd/dagger/main.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.cloud/go/cmd/dagger/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
Reference in New Issue
Block a user