Skip to content

Commit

Permalink
feat: persist kotlin schemas during deploy (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
worstell authored Oct 19, 2023
1 parent daaf45c commit 9d0efcc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
35 changes: 27 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,31 @@ func (d *deployCmd) Run(ctx context.Context, client ftlv1connect.ControllerServi
return errors.WithStack(err)
}

schema, err := findFiles(d.Base, []string{config.Module})
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)
}

module := schemapb.Module{}
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 +97,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 @@ -153,7 +153,7 @@ class Visitor(val logger: KSPLogger, val modules: MutableMap<String, ModuleData>
class SchemaExtractor(val logger: KSPLogger, val options: Map<String, String>) : SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
val dest = requireNotNull(options["dest"]) { "Must provide output directory for generated schemas" }
val outputDirectory = File(dest, "generated-sources/ksp").also { Path.of(it.absolutePath).createDirectories() }
val outputDirectory = File(dest).also { Path.of(it.absolutePath).createDirectories() }
val modules = mutableMapOf<String, ModuleData>()

val symbols = resolver.getSymbolsWithAnnotation("xyz.block.ftl.Verb")
Expand Down

0 comments on commit 9d0efcc

Please sign in to comment.