added fix for deployment race condition
This commit is contained in:
@@ -183,19 +183,9 @@ func (m *Manager) DeployStack(req DeployRequest) (string, error) {
|
||||
m.checkLocalImages(req.StackName, stackDir)
|
||||
}
|
||||
|
||||
// Run docker compose up -d
|
||||
start := time.Now()
|
||||
_, composeErr := m.composeExecWithEnv(stackDir, env, "up", "-d")
|
||||
if composeErr != nil {
|
||||
m.logger.Printf("[ERROR] Stack %s deploy failed after %.1fs: %v", req.StackName, time.Since(start).Seconds(), composeErr)
|
||||
// Deployment failed — keep app.yaml for debugging but mark as not deployed
|
||||
appCfg.Deployed = false
|
||||
_ = SaveAppConfig(stackDir, appCfg)
|
||||
return "", fmt.Errorf("docker compose up failed: %w", composeErr)
|
||||
}
|
||||
|
||||
// Update in-memory stack state immediately so the UI reflects the deployment
|
||||
// without waiting for the next ScanStacks() cycle.
|
||||
// Update in-memory stack state BEFORE compose up so the UI reflects
|
||||
// "deployed" immediately (compose up can take 30-60s for image pulls).
|
||||
// If compose up fails, we revert both disk and in-memory state below.
|
||||
m.mu.Lock()
|
||||
if s, ok := m.stacks[req.StackName]; ok {
|
||||
s.Deployed = true
|
||||
@@ -203,6 +193,24 @@ func (m *Manager) DeployStack(req DeployRequest) (string, error) {
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
// Run docker compose up -d
|
||||
start := time.Now()
|
||||
_, composeErr := m.composeExecWithEnv(stackDir, env, "up", "-d")
|
||||
if composeErr != nil {
|
||||
m.logger.Printf("[ERROR] Stack %s deploy failed after %.1fs: %v", req.StackName, time.Since(start).Seconds(), composeErr)
|
||||
// Revert in-memory state
|
||||
m.mu.Lock()
|
||||
if s, ok := m.stacks[req.StackName]; ok {
|
||||
s.Deployed = false
|
||||
s.AppConfig = nil
|
||||
}
|
||||
m.mu.Unlock()
|
||||
// Revert disk state — keep app.yaml for debugging but mark as not deployed
|
||||
appCfg.Deployed = false
|
||||
_ = SaveAppConfig(stackDir, appCfg)
|
||||
return "", fmt.Errorf("docker compose up failed: %w", composeErr)
|
||||
}
|
||||
|
||||
m.logger.Printf("[INFO] Stack %s deployed successfully (took %.1fs)", req.StackName, time.Since(start).Seconds())
|
||||
|
||||
// Post-deploy container state check (async, non-blocking)
|
||||
|
||||
Reference in New Issue
Block a user