-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use buildengine for deploy cmd #1002
Conversation
buildengine/deploy.go
Outdated
ctx = log.ContextWithLogger(ctx, logger) | ||
logger.Infof("Deploying module") | ||
|
||
deployDir := filepath.Join(module.Dir, module.DeployDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated but I keep having to do this, maybe we should add helper methods that do the joining for us, eg. module.AbsDeployDir()
Or maybe we should make DeployDir
et al absolute when we load the config. Not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah same! I'll add the module.AbsDeployDir
for now and maybe we can clean this up with the DeployDir
stuff if that makes sense
buildengine/engine.go
Outdated
@@ -201,6 +206,56 @@ func (e *Engine) Build(ctx context.Context, modules ...string) error { | |||
return nil | |||
} | |||
|
|||
func (e *Engine) Deploy(ctx context.Context, replicas int32, waitForDeployOnline bool, modules ...string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a comment.
buildengine/engine.go
Outdated
modules = maps.Keys(e.modules) | ||
} | ||
|
||
buildSubscription := e.builds.SubscribeSync(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't bother with pubsub for an internal implementation. It's useful for decoupling components, but if all your code is in a single type then it's just overhead. I'd probably refactor the exist build code into a function that can accept a callback that is executed after each module is built.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I like that! I'll give it a go
} | ||
|
||
_, err = client.ReplaceDeploy(ctx, connect.NewRequest(&ftlv1.ReplaceDeployRequest{DeploymentName: resp.Msg.GetDeploymentName(), MinReplicas: d.Replicas})) | ||
func (d *deployCmd) Run(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW both these approaches work - clients in context and clients passed directly.
7d4822e
to
c1ca97a
Compare
localPath string | ||
} | ||
|
||
func Deploy(ctx context.Context, module Module, replicas int32, waitForDeployOnline bool, client ftlv1connect.ControllerServiceClient) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a comment.
buildengine/engine.go
Outdated
// Build attempts to build the specified modules, or all local modules if none are provided. | ||
func (e *Engine) Build(ctx context.Context, modules ...string) error { | ||
// The callback is invoked for each module after it is built. | ||
func (e *Engine) Build(ctx context.Context, callback BuildCallback, modules ...string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callback is (currently) an internal implementation detail only used by Deploy
, just make its use private.
24c37ef
to
4df9870
Compare
7806df1
to
00a755e
Compare
} | ||
|
||
// Deploy attempts to build and deploy the specified modules, or all local modules if none are provided. | ||
func (e *Engine) Deploy(ctx context.Context, replicas int32, waitForDeployOnline bool, modules ...string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a better idea really, but passing the same number of replicas for all deployments probably isn't what we'll want longer term.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah same. I wasn't 100% sure what to do here either, but open to improvements. Maybe we give this a go and if we have some use cases in the future that need something else we can update.
} | ||
|
||
return e.buildWithCallback(ctx, func(ctx context.Context, module Module) error { | ||
return Deploy(ctx, module, replicas, waitForDeployOnline, e.client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this wait for each deploy in turn will significantly slow down the deploy, as the build won't be able to continue until each group has fully deployed.
OTOH this will mean the deployed services will always have the correct dependencies up, so I'm a bit conflicted.
Probably okay for now, but we'll see how it goes. I think what would ideally happen is that deployments that don't have all the correct dependencies available wouldn't go live.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Word! I was thinking, this is nice and reliable for now, but probably can be quicker in the future. I had it deploying without a wait, but def ran into issues with complex dependencies. Maybe something we can chat through to see if we can make this fast and reliable.
4a9a9c1
to
574087a
Compare
Not fully tested yet, but starting to flesh out the subscription flow for build -> deploy