Skip to content

Commit

Permalink
feat: persist kotlin schemas during deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
worstell committed Oct 19, 2023
1 parent 54ed725 commit 8b8bd98
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/common/moduleconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ModuleConfig struct {
Language string `toml:"language"`
Module string `toml:"module"`
Deploy []string `toml:"deploy"`
Schema string `toml:"schema"`
}

// LoadConfig from a directory.
Expand Down
41 changes: 33 additions & 8 deletions cmd/ftl/cmd_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"connectrpc.com/connect"
"github.com/alecthomas/errors"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/TBD54566975/ftl/backend/common/log"
Expand Down Expand Up @@ -53,6 +54,37 @@ func (d *deployCmd) Run(ctx context.Context, client ftlv1connect.ControllerServi
return errors.WithStack(err)
}

module := schemapb.Module{
Name: config.Module,
}
// TODO(worstell): clean up deploy cmd to handle language-specific stuff
if config.Language == "kotlin" {
schemaDirectory := config.Schema
schema, err := findFiles(d.Base, []string{schemaDirectory})
if err != nil {
return errors.WithStack(err)
}

if len(schema) != 1 {
return errors.Errorf("cannot define multiple module schemas")
}

content, err := os.ReadFile(schema[0])
if err != nil {
return errors.WithStack(err)
}

err = proto.Unmarshal(content, &module)
if err != nil {
return errors.WithStack(err)
}
}
module.Runtime = &schemapb.ModuleRuntime{
CreateTime: timestamppb.Now(),
Language: config.Language,
MinReplicas: d.Replicas,
}

logger.Infof("Uploading %d/%d files", len(gadResp.Msg.MissingDigests), len(files))
for _, missing := range gadResp.Msg.MissingDigests {
file := filesByHash[missing]
Expand All @@ -71,14 +103,7 @@ func (d *deployCmd) Run(ctx context.Context, client ftlv1connect.ControllerServi
}
resp, err := client.CreateDeployment(ctx, connect.NewRequest(&ftlv1.CreateDeploymentRequest{
// TODO(aat): Use real data for this.
Schema: &schemapb.Module{
Name: config.Module,
Runtime: &schemapb.ModuleRuntime{
CreateTime: timestamppb.Now(),
Language: config.Language,
MinReplicas: d.Replicas,
},
},
Schema: &module,
Artefacts: slices.Map(maps.Values(filesByHash), func(a deploymentArtefact) *ftlv1.DeploymentArtefact {
return a.DeploymentArtefact
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class ModuleGenerator() {
module = "${module}"
language = "kotlin"
deploy = ["main", "classes", "dependency", "classpath.txt"]
schema = "generated-sources/ksp"
""".trimIndent()
)

Expand Down

0 comments on commit 8b8bd98

Please sign in to comment.