Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ stub/stub

# intellij
.idea

node_modules
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ We appreciate any participation in the project, including:
- [Introduction](docs/introduction.md)
- [Getting Started](docs/getting_started.md)
- [Writing Extensions](docs/writing_extensions.md)
- [Writing an extension in Go](docs/writing_extensions_go.md)
- [Writing an extension in Javascript/Typescript](docs/writing_extensions_nodejs.md)
- [Operator Manual](docs/operator_manual.md)
1 change: 0 additions & 1 deletion cloak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ dependencies:
- local: examples/alpine/cloak.yaml
- local: examples/yarn/cloak.yaml
- local: examples/netlify/go/cloak.yaml
- local: examples/todoapp/go/cloak.yaml
24 changes: 5 additions & 19 deletions cmd/cloak/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

"github.com/dagger/cloak/engine"
"github.com/dagger/cloak/sdk/go/dagger"
"github.com/spf13/cobra"
)

Expand All @@ -17,27 +16,14 @@ var devCmd = &cobra.Command{

func Dev(cmd *cobra.Command, args []string) {
localDirs := getKVInput(localDirsInput)
localDirs[projectContextLocalName] = projectContext
startOpts := &engine.Config{
LocalDirs: localDirs,
DevServer: devServerPort,
LocalDirs: localDirs,
DevServer: devServerPort,
Workdir: workdir,
ConfigPath: configPath,
}

err := engine.Start(context.Background(), startOpts, func(ctx context.Context) error {
cl, err := dagger.Client(ctx)
if err != nil {
return err
}

localDirMapping, err := loadLocalDirs(ctx, cl, localDirs)
if err != nil {
return err
}

if _, err := installProject(ctx, cl, localDirMapping[projectContextLocalName]); err != nil {
return err
}

err := engine.Start(context.Background(), startOpts, func(ctx engine.Context) error {
return nil
})
if err != nil {
Expand Down
123 changes: 8 additions & 115 deletions cmd/cloak/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import (
"golang.org/x/term"
)

const (
projectContextLocalName = ".projectContext"
)

var doCmd = &cobra.Command{
Use: "do",
Run: Do,
Expand All @@ -38,10 +34,11 @@ func Do(cmd *cobra.Command, args []string) {
secrets := getKVInput(secretsInput)

localDirs := getKVInput(localDirsInput)
localDirs[projectContextLocalName] = projectContext

startOpts := &engine.Config{
LocalDirs: localDirs,
LocalDirs: localDirs,
Workdir: workdir,
ConfigPath: configPath,
}

// Use the provided query file if specified
Expand All @@ -65,42 +62,26 @@ func Do(cmd *cobra.Command, args []string) {
}

var result []byte
err := engine.Start(ctx, startOpts, func(ctx context.Context) error {
cl, err := dagger.Client(ctx)
if err != nil {
return err
}

localDirMapping, err := loadLocalDirs(ctx, cl, localDirs)
if err != nil {
return err
}
for name, id := range localDirMapping {
if name == projectContextLocalName {
continue
}
err := engine.Start(ctx, startOpts, func(ctx engine.Context) error {
for name, id := range ctx.LocalDirs {
vars[name] = string(id)
}

secretMapping, err := loadSecrets(ctx, cl, secrets)
secretMapping, err := loadSecrets(ctx, ctx.Client, secrets)
if err != nil {
return err
}
for name, id := range secretMapping {
vars[name] = string(id)
}

defaultOperations, err := installProject(ctx, cl, localDirMapping[projectContextLocalName])
if err != nil {
return err
}
if operations == "" {
operations = defaultOperations
operations = ctx.Operations
}

res := make(map[string]interface{})
resp := &graphql.Response{Data: &res}
err = cl.MakeRequest(ctx,
err = ctx.Client.MakeRequest(ctx,
&graphql.Request{
Query: operations,
Variables: vars,
Expand Down Expand Up @@ -138,45 +119,6 @@ func getKVInput(kvs []string) map[string]string {
return m
}

func installProject(ctx context.Context, cl graphql.Client, contextFS dagger.FSID) (operations string, rerr error) {
res := struct {
Core struct {
Filesystem struct {
LoadExtension struct {
Operations string
}
}
}
}{}
resp := &graphql.Response{Data: &res}

err := cl.MakeRequest(ctx,
&graphql.Request{
Query: `
query LoadExtension($fs: FSID!, $configPath: String!) {
core {
filesystem(id: $fs) {
loadExtension(configPath: $configPath) {
install
operations
}
}
}
}`,
Variables: map[string]any{
"fs": contextFS,
"configPath": projectFile,
},
},
resp,
)
if err != nil {
return "", err
}

return res.Core.Filesystem.LoadExtension.Operations, nil
}

func loadSecrets(ctx context.Context, cl graphql.Client, secrets map[string]string) (map[string]dagger.SecretID, error) {
var eg errgroup.Group
var l sync.Mutex
Expand Down Expand Up @@ -222,52 +164,3 @@ func loadSecrets(ctx context.Context, cl graphql.Client, secrets map[string]stri

return mapping, eg.Wait()
}

func loadLocalDirs(ctx context.Context, cl graphql.Client, localDirs map[string]string) (map[string]dagger.FSID, error) {
var eg errgroup.Group
var l sync.Mutex

mapping := map[string]dagger.FSID{}
for localID := range localDirs {
localID := localID
eg.Go(func() error {
res := struct {
Core struct {
Clientdir struct {
ID dagger.FSID
}
}
}{}
resp := &graphql.Response{Data: &res}

err := cl.MakeRequest(ctx,
&graphql.Request{
Query: `
query ClientDir($id: String!) {
core {
clientdir(id: $id) {
id
}
}
}
`,
Variables: map[string]any{
"id": localID,
},
},
resp,
)
if err != nil {
return err
}

l.Lock()
mapping[localID] = res.Core.Clientdir.ID
l.Unlock()

return nil
})
}

return mapping, eg.Wait()
}
Loading