Skip to content

Commit

Permalink
updated scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
oakrizan committed Oct 9, 2024
1 parent 160a0a7 commit 2ce56c0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-packetbeat" && "$BUILDKITE_STEP
export PRIVATE_CI_GCS_CREDENTIALS_SECRET
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-agentbeat" ]]; then
AGENTBEAT_PATH=$(.buildkite/scripts/agentbeat/setup_agentbeat.py)
export AGENTBEAT_PATH
fi

CPU_ARCH=$(uname -m)
PLATFORM_TYPE=$(uname)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import subprocess
import sys
import tarfile
import os
import re

PATH = 'x-pack/agentbeat/build/distributions'
Expand Down Expand Up @@ -46,7 +45,6 @@ def get_artifact_pattern() -> str:


def download_agentbeat(pattern, path) -> str:
log('--- Downloading agentbeat')
try:
subprocess.run(
['buildkite-agent', 'artifact', 'download', pattern, '.',
Expand All @@ -70,14 +68,12 @@ def get_filename(path) -> str:


def extract_agentbeat(filename):
log('~~~ Extracting agentbeat')
filepath = PATH + '/' + filename

if filepath.endswith('.zip'):
unzip_agentbeat(filepath)
else:
untar_agentbeat(filepath)
log('Successfully extracted agentbeat')


def unzip_agentbeat(filepath):
Expand All @@ -100,33 +96,18 @@ def untar_agentbeat(filepath):
exit(1)


def add_to_path(filepath):
def get_path_to_executable(filepath) -> str:
pattern = r'(.*)(?=\.zip|.tar\.gz)'
match = re.match(pattern, filepath)
if match:
path = f'../build/distributions/{match.group(1)}/agentbeat'
log("--- PATH: " + str(path))
os.environ['AGENTBEAT_PATH'] = str(path)
return path
else:
log_err("No agentbeat executable found")
exit(1)


def install_synthetics():
log('--- Installing @elastic/synthetics')

try:
subprocess.run(
['npm', 'install', '-g', '@elastic/synthetics'],
check=True
)
except subprocess.CalledProcessError:
log_err('Failed to install @elastic/synthetics')
exit(1)


artifact_pattern = get_artifact_pattern()
archive = download_agentbeat(artifact_pattern, PATH)
extract_agentbeat(archive)
add_to_path(archive)
install_synthetics()
log(get_path_to_executable(archive))
7 changes: 2 additions & 5 deletions .buildkite/x-pack/pipeline.xpack.agentbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ steps:
# depends_on:
# - agentbeat-package-linux
command: |
set -euo pipefail
./.buildkite/scripts/agentbeat/prepare_env.py
cd x-pack/agentbeat
mage -v testWithSpec
agents:
Expand All @@ -126,7 +124,6 @@ steps:
# depends_on:
# - agentbeat-package-linux
command: |
./.buildkite/scripts/agentbeat/prepare_env.py
cd x-pack/agentbeat
mage -v testWithSpec
agents:
Expand All @@ -142,7 +139,7 @@ steps:
# - agentbeat-package-linux
# command: |
# set -euo pipefail
# ./.buildkite/scripts/agentbeat/prepare_env.py
# ./.buildkite/scripts/agentbeat/setup_agentbeat.py
# agents:
# provider: "orka"
# imagePrefix: "${IMAGE_MACOS_X86_64}"
Expand All @@ -153,7 +150,7 @@ steps:
# - agentbeat-package-linux
# command: |
# set -euo pipefail
# ./.buildkite/scripts/agentbeat/prepare_env.py
# ./.buildkite/scripts/agentbeat/setup_agentbeat.py
# agents:
# provider: "orka"
# imagePrefix: "${IMAGE_MACOS_ARM}"
12 changes: 1 addition & 11 deletions dev-tools/mage/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,7 @@ type command struct {
}

// SpecCommands parses agent.beat.spec.yml and collects commands for tests
func SpecCommands() []string {
specPath := os.Getenv("AGENTBEAT_SPEC")
if specPath == "" {
log.Fatal("AGENTBEAT_SPEC is not defined")
}

platform := os.Getenv("PLATFORM")
if platform == "" {
log.Fatal("PLATFORM is not defined")
}

func SpecCommands(specPath string, platform string) []string {
spec, _ := parseToObj(specPath)

filteredInputs := filter(spec.Inputs, func(input input) bool {
Expand Down
13 changes: 12 additions & 1 deletion x-pack/agentbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package main
import (
"context"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -217,7 +218,17 @@ func PythonIntegTest(ctx context.Context) error {

// TestWithSpec executes unique commands from agentbeat.spec.yml and validates that app haven't exited with non-zero
func TestWithSpec(ctx context.Context) {
var commands = devtools.SpecCommands()
specPath := os.Getenv("AGENTBEAT_SPEC")
if specPath == "" {
log.Fatal("AGENTBEAT_SPEC is not defined")
}

platform := os.Getenv("PLATFORM")
if platform == "" {
log.Fatal("PLATFORM is not defined")
}

var commands = devtools.SpecCommands(specPath, platform)

agentbeatPath := os.Getenv("AGENTBEAT_PATH")
fmt.Printf("--- AGENTBEAT_PATH: %s", agentbeatPath)
Expand Down

0 comments on commit 2ce56c0

Please sign in to comment.