Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oakrizan committed Oct 17, 2024
1 parent 50d3e6a commit 517f461
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
70 changes: 40 additions & 30 deletions .buildkite/scripts/agentbeat/setup_agentbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
import tarfile

PATH = 'x-pack/agentbeat/build/distributions'
PLATFORMS = {
'windows': {
'x86_64': 'x86_64',
},
'linux': {
'x86_64': 'x86_64',
'arm64': 'arm64',
},
'darwin': {
'x86_64': 'x86_64',
'arm64': 'aarch64',
}
}


class Archive:
def __init__(self, os, arch, ext):
self.os = os
self.arch = arch
self.ext = ext


def log(msg):
Expand All @@ -18,38 +38,28 @@ def log_err(msg):
sys.stderr.flush()


def get_os() -> str:
return platform.system().lower()
def get_archive_params() -> Archive:
system = platform.system().lower()
machine = platform.machine().lower()
arch = PLATFORMS.get(system, {}).get(machine)
ext = get_artifact_extension(system)

return Archive(system, arch, ext)

def get_arch() -> str:
arch = platform.machine().lower()

if arch == 'amd64':
return 'x86_64'
else:
if get_os() == 'darwin':
return 'aarch64'
else:
return arch


def get_artifact_extension(agent_os) -> str:
if agent_os == 'windows':
def get_artifact_extension(system) -> str:
if system == 'windows':
return 'zip'
else:
return 'tar.gz'


def get_artifact_pattern() -> str:
agent_os = get_os()
agent_arch = get_arch()
extension = get_artifact_extension(agent_os)
print('Artifact params: ' + agent_os + ' ' + agent_arch + ' ' + extension)
return f'{PATH}/agentbeat-*-{agent_os}-{agent_arch}.{extension}'
def get_artifact_pattern(archive_obj) -> str:
return f'{PATH}/agentbeat-*-{archive_obj.os}-{archive_obj.arch}.{archive_obj.ext}'


def download_agentbeat(pattern, path) -> str:
def download_agentbeat(archive_obj) -> str:
pattern = get_artifact_pattern(archive_obj)
try:
subprocess.run(
['buildkite-agent', 'artifact', 'download', pattern, '.',
Expand All @@ -59,16 +69,16 @@ def download_agentbeat(pattern, path) -> str:
except subprocess.CalledProcessError:
exit(1)

return get_filename(path)
return get_full_filename()


def get_filename(path) -> str:
def get_full_filename() -> str:
try:
out = subprocess.run(
['ls', '-p', path],
['ls', '-p', PATH],
check=True, capture_output=True, text=True)
print("--- ls -p: " + out.stdout)
return out.stdout.strip()
filename = out.stdout.strip()
return filename
except subprocess.CalledProcessError:
exit(1)

Expand Down Expand Up @@ -109,10 +119,10 @@ def get_path_to_executable(filepath) -> str:
path = f'../../{match.group(1)}/agentbeat'
return path
else:
log_err("No agentbeat executable found")
log_err('No agentbeat executable found')
exit(1)

artifact_pattern = get_artifact_pattern()
archive = download_agentbeat(artifact_pattern, PATH)
archive_params = get_archive_params()
archive = download_agentbeat(archive_params)
extract_agentbeat(archive)
log(get_path_to_executable(archive))
2 changes: 1 addition & 1 deletion .buildkite/x-pack/pipeline.xpack.agentbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ steps:
provider: "orka"
imagePrefix: "${IMAGE_MACOS_X86_64}"

- label: ":macos: Agentbeat/Integration tests macOS arm64"
- label: ":macos: x-pack/agentbeat: macOS arm64 Spec tests"
key: "agentbeat-it-macos-arm64"
depends_on:
- agentbeat-package-linux
Expand Down

0 comments on commit 517f461

Please sign in to comment.