Skip to content

Commit

Permalink
fix(serve): connect to Cloud if process is started outside of project…
Browse files Browse the repository at this point in the history
… dir

This came up in the Desktop client because it'd start the serve command
outside of any project root, and thus not connect to Cloud at all for the
live view etc. to work.
  • Loading branch information
edvald committed Jul 13, 2023
1 parent 55fdeee commit b9fcf44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class ServeCommand<
const session = await cloudApi.registerSession({
parentSessionId: undefined,
projectId,
// Use the process (i.e. parent command) session ID for the serve command session
// Use the process (i.e. parent command) session ID for the serve/dev command session
sessionId: manager.sessionId,
commandInfo: garden.commandInfo,
localServerPort: this.server.port,
Expand Down
21 changes: 20 additions & 1 deletion core/src/server/instance-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class GardenInstanceManager {

const gardenParams = await resolveGardenParamsPartial(projectRoot, gardenOpts)

return this.ensureInstance(
const garden = await this.ensureInstance(
log,
{
projectRoot,
Expand All @@ -389,5 +389,24 @@ export class GardenInstanceManager {
},
gardenOpts
)

if (cloudApi && garden.projectId && this.serveCommand.server) {
// Ensure cloud session is registered for the domain and server session, since this may not happen on startup
// if the command isn't started in a Garden project root. This is a no-op if it's already registered.
// FIXME: We still need to rethink on the Cloud side how sessions are scoped
await cloudApi.registerSession({
parentSessionId: undefined,
projectId: garden.projectId,
// Use the process (i.e. parent command) session ID for the serve/dev command session
sessionId: this.sessionId,
commandInfo: garden.commandInfo,
localServerPort: this.serveCommand.server.port,
environment: garden.environmentName,
namespace: garden.namespace,
isDevCommand: true,
})
}

return garden
}
}

0 comments on commit b9fcf44

Please sign in to comment.