Skip to content

Only Restart Affected Containers #17

@abhibongale

Description

@abhibongale

Optimize rebuild to only restart containers whose images have actually changed. If only Ironic code changed, don't restart infrastructure services. This reduces rebuild time and avoids unnecessary service interruptions.

Goals

  • Detect which images changed
  • Restart only affected containers
  • Skip unnecessary restarts
  • Improve rebuild reliability

Implementation

Add image change detection to stackbox/core/builder.py:

def get_image_id(tag: str) -> Optional[str]:
    """Get image ID for a tag."""
    result = subprocess.run(
        ["docker", "image", "inspect", tag, "--format", "{{.Id}}"],
        capture_output=True,
        text=True
    )
    return result.stdout.strip() if result.returncode == 0 else None


def image_changed(tag: str, old_id: str) -> bool:
    """Check if image changed."""
    new_id = get_image_id(tag)
    return new_id != old_id

Update rebuild command to track image IDs and only restart if changed.

Testing

# Make code change
stackbox rebuild ironic
# Should restart ironic containers

# No changes, rebuild
stackbox rebuild ironic
# Should detect no changes, skip restart

Acceptance Criteria

  • Detects image changes
  • Skips restart if no change
  • Restarts only affected services
  • Shows what was restarted

Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions