Skip to content

Commit 9f165af

Browse files
authored
Testing fix for is_stage in ova build (#783)
1 parent 14fde1f commit 9f165af

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ All notable changes to this project will be documented in this file.
1313

1414
### Fixed
1515

16-
- None
16+
- Testing fix for is_stage in ova build. ([#783](https://github.com/wazuh/wazuh-virtual-machines/pull/783))
1717

1818
### Deleted
1919

ova/workflow_assets/ova_configurer.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
from pathlib import Path
5+
import re
56
import shutil
67
import subprocess
78

@@ -31,6 +32,39 @@ def clone_repositories(wia_branch, wvm_branch):
3132
for repo in repos:
3233
subprocess.run(f"git clone {repo['branch']} {repo['url']} {repo['dest']}", shell=True, check=True)
3334

35+
def extract_stage_from_branch(wia_branch):
36+
"""
37+
Extracts the stage (rc1, beta1, etc.) from the branch name if present.
38+
39+
Args:
40+
wia_branch (str): Branch name of the wazuh-installation-assistant repository
41+
42+
Returns:
43+
str: Stage name (e.g., "rc1", "beta1") or empty string if no stage found
44+
"""
45+
# Pattern to match stage indicators: -rc1, -beta1, -rc2, etc.
46+
pattern = r'-(rc\d+|beta\d+|alpha\d+)'
47+
match = re.search(pattern, wia_branch, re.IGNORECASE)
48+
49+
if match:
50+
return match.group(1)
51+
return ""
52+
53+
def update_wazuh_install_stage(wazuh_install_path, stage):
54+
"""
55+
Updates the last_stage variable in wazuh-install.sh file.
56+
57+
Args:
58+
wazuh_install_path (str): Path to the wazuh-install.sh file
59+
stage (str): Stage name (e.g., "rc1", "beta1")
60+
"""
61+
if not stage or not os.path.exists(wazuh_install_path):
62+
return
63+
64+
# Use sed to replace last_stage="" with last_stage="<stage>"
65+
sed_command = f'sudo sed -i \'s/last_stage=""/last_stage="{stage}"/g\' {wazuh_install_path}'
66+
subprocess.run(sed_command, shell=True, check=True)
67+
3468
def build_wazuh_install(repo_path, wia_branch):
3569
"""
3670
Builds the wazuh-install.sh script and moves it to /tmp
@@ -45,15 +79,22 @@ def build_wazuh_install(repo_path, wia_branch):
4579
os.chdir(repo_path)
4680
subprocess.run(f"git checkout {wia_branch}", shell=True, check=True)
4781
subprocess.run("sudo bash builder.sh -i", shell=True, check=True)
82+
4883
if os.path.exists("wazuh-install.sh"):
4984
subprocess.run("sudo mv wazuh-install.sh /tmp/wazuh-install.sh", shell=True, check=True)
5085

86+
# Check if wia_branch contains a stage indicator and update the wazuh-install.sh file
87+
stage = extract_stage_from_branch(wia_branch)
88+
if stage:
89+
update_wazuh_install_stage("/tmp/wazuh-install.sh", stage)
90+
5191

5292
def run_provision_script(wvm_branch, repository, debug):
5393
"""
5494
Runs the provision.sh script
5595
5696
Args:
97+
wvm_branch (str): Branch of the wazuh-virtual-machines repository
5798
repository (str): Production or development repository
5899
debug (str): Debug mode
59100
"""

0 commit comments

Comments
 (0)