Skip to content

Commit 5eb0310

Browse files
committed
support releasing latest agents
1 parent 65d6296 commit 5eb0310

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

scripts/release/atomic_pipeline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import requests
1414
from opentelemetry import trace
15-
from packaging.version import Version
1615

1716
from lib.base_logger import logger
1817
from scripts.release.build.image_build_configuration import ImageBuildConfiguration
@@ -24,6 +23,7 @@
2423
)
2524
from scripts.release.detect_ops_manager_changes import (
2625
detect_ops_manager_changes,
26+
get_currently_used_agents,
2727
get_all_agents_for_rebuild,
2828
)
2929

@@ -407,6 +407,9 @@ def build_agent(build_configuration: ImageBuildConfiguration):
407407
if build_configuration.all_agents:
408408
agent_versions_to_build = get_all_agents_for_rebuild()
409409
logger.info("building all agents")
410+
elif build_configuration.currently_used_agents:
411+
agent_versions_to_build = get_currently_used_agents()
412+
logger.info("building current used agents")
410413
else:
411414
agent_versions_to_build = detect_ops_manager_changes()
412415
logger.info("building agents for changed OM versions")

scripts/release/build/image_build_configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ImageBuildConfiguration:
1818
platforms: Optional[List[str]] = None
1919
sign: bool = False
2020
all_agents: bool = False
21+
currently_used_agents: bool = False
2122

2223
def is_release_scenario(self) -> bool:
2324
return self.scenario == BuildScenario.RELEASE

scripts/release/detect_ops_manager_changes.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
Detects changes to opsManagerMapping in release.json for triggering agent releases.
44
Relies on git origin/master vs local release.json
55
"""
6+
import glob
67
import json
78
import logging
9+
import os
810
import subprocess
911
import sys
1012
from typing import Dict, List, Optional, Tuple
@@ -132,6 +134,71 @@ def get_all_agents_for_rebuild() -> List[Tuple[str, str]]:
132134
return list(set(agents))
133135

134136

137+
def get_currently_used_agents() -> List[Tuple[str, str]]:
138+
"""Returns list of (agent_version, tools_version) tuples for agents currently used in contexts"""
139+
logger.info("Getting currently used agents from contexts")
140+
agents = []
141+
142+
try:
143+
release_data = load_current_release_json()
144+
if not release_data:
145+
logger.error("Could not load release.json")
146+
return []
147+
148+
ops_manager_mapping = extract_ops_manager_mapping(release_data)
149+
ops_manager_versions = ops_manager_mapping.get("ops_manager", {})
150+
151+
# Search all context files
152+
context_pattern = "scripts/dev/contexts/**/*"
153+
context_files = glob.glob(context_pattern, recursive=True)
154+
155+
for context_file in context_files:
156+
if os.path.isfile(context_file):
157+
try:
158+
with open(context_file, "r") as f:
159+
content = f.read()
160+
161+
# Extract AGENT_VERSION from the context file
162+
for line in content.split('\n'):
163+
if line.startswith('export AGENT_VERSION='):
164+
agent_version = line.split('=')[1].strip()
165+
tools_version = get_tools_version_for_agent(agent_version)
166+
agents.append((agent_version, tools_version))
167+
logger.info(f"Found agent {agent_version} in {context_file}")
168+
break
169+
170+
# Extract CUSTOM_OM_VERSION and map to agent version
171+
for line in content.split('\n'):
172+
if line.startswith('export CUSTOM_OM_VERSION='):
173+
om_version = line.split('=')[1].strip()
174+
if om_version in ops_manager_versions:
175+
agent_tools = ops_manager_versions[om_version]
176+
agent_version = agent_tools.get("agent_version")
177+
tools_version = agent_tools.get("tools_version")
178+
if agent_version and tools_version:
179+
agents.append((agent_version, tools_version))
180+
logger.info(f"Found OM version {om_version} -> agent {agent_version} in {context_file}")
181+
break
182+
183+
except Exception as e:
184+
logger.debug(f"Error reading context file {context_file}: {e}")
185+
186+
# Also add the main agentVersion from release.json
187+
main_agent_version = release_data.get("agentVersion")
188+
if main_agent_version:
189+
tools_version = get_tools_version_for_agent(main_agent_version)
190+
agents.append((main_agent_version, tools_version))
191+
logger.info(f"Found main agent version from release.json: {main_agent_version}")
192+
193+
unique_agents = list(set(agents))
194+
logger.info(f"Found {len(unique_agents)} currently used agents")
195+
return unique_agents
196+
197+
except Exception as e:
198+
logger.error(f"Error getting currently used agents: {e}")
199+
return []
200+
201+
135202
def detect_ops_manager_changes() -> List[Tuple[str, str]]:
136203
"""Returns (has_changes, changed_agents_list)"""
137204
logger.info("=== Detecting OM Mapping Changes (Local vs Base) ===")

scripts/release/pipeline_main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def image_build_config_from_args(args) -> ImageBuildConfiguration:
124124
sign=sign,
125125
parallel_factor=args.parallel_factor,
126126
all_agents=args.all_agents,
127+
currently_used_agents=args.current_agents,
127128
)
128129

129130

@@ -257,6 +258,11 @@ def main():
257258
action="store_true",
258259
help="Build all agent images.",
259260
)
261+
parser.add_argument(
262+
"--current-agents",
263+
action="store_true",
264+
help="Build all currently used agent images.",
265+
)
260266

261267
args = parser.parse_args()
262268

0 commit comments

Comments
 (0)