Skip to content

Commit

Permalink
chore: updated docker testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-segning committed Aug 19, 2024
1 parent 374b7f3 commit 4693b43
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 58 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test install script

on: [ push, pull_request ]

jobs:
test_script:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: QEMU
id: qemu
uses: docker/setup-qemu-action@v3

- name: Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ steps.qemu.outputs.platforms }}

- name: Test script
run: |
docker run --rm -v "$PWD:/app" bats/bats:latest /app/scripts/tests/test-script.bats
2 changes: 1 addition & 1 deletion scripts/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ case "$OS_NAME" in
"Darwin")
info_message "Detected macOS"
if command_exists brew; then
maybe_sudo brew install curl jq
brew install curl jq
else
error_message "Homebrew is not installed. Please install Homebrew first."
exit 1
Expand Down
50 changes: 25 additions & 25 deletions scripts/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ else
set -eu
fi

# Function for logging with timestamp
log() {
local LEVEL="$1"
shift
local MESSAGE="$*"
local TIMESTAMP
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
if [ "$LEVEL" = "ERROR" ] || { [ "$LEVEL" = "WARNING" ] && [ "$LOG_LEVEL" != "ERROR" ]; } || { [ "$LEVEL" = "INFO" ] && [ "$LOG_LEVEL" = "INFO" ]; }; then
echo "$TIMESTAMP [$LEVEL] $MESSAGE"
fi
}

# Logging helpers
info_message() {
log INFO "$*"
}

error_message() {
log ERROR "$*"
}

success_message() {
log INFO "$*"
}

# Variables
LOG_LEVEL=${LOG_LEVEL:-INFO}
WAZUH_MANAGER=${WAZUH_MANAGER:-'master.wazuh.adorsys.team'}
Expand Down Expand Up @@ -45,31 +70,6 @@ else
exit 1
fi

# Function for logging with timestamp
log() {
local LEVEL="$1"
shift
local MESSAGE="$*"
local TIMESTAMP
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
if [ "$LEVEL" = "ERROR" ] || { [ "$LEVEL" = "WARNING" ] && [ "$LOG_LEVEL" != "ERROR" ]; } || { [ "$LEVEL" = "INFO" ] && [ "$LOG_LEVEL" = "INFO" ]; }; then
echo "$TIMESTAMP [$LEVEL] $MESSAGE"
fi
}

# Logging helpers
info_message() {
log INFO "$*"
}

error_message() {
log ERROR "$*"
}

success_message() {
log INFO "$*"
}

# Ensure root privileges, either directly or through sudo
maybe_sudo() {
if [ "$(id -u)" -ne 0 ]; then
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ WAZUH_AGENT_VERSION=${WAZUH_AGENT_VERSION:-'4.8.0-1'}
WAZUH_AGENT_NAME=${WAZUH_AGENT_NAME:-}

# Step 0: Ensure Curl and JQ are installed
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh/main/scripts/deps.sh | sh) >/dev/null 2>&1; then
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-agent/main/scripts/deps.sh | sh) >/dev/null 2>&1; then
echo "Failed to ensure deps"
exit 1
fi

# Step 1: Download and install Wazuh agent
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh/main/scripts/install.sh | sh) >/dev/null 2>&1; then
if ! (curl -SL --progress-bar https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-agent/main/scripts/install.sh | sh) >/dev/null 2>&1; then
echo "Failed to install wazuh-agent"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Tests are written using docker
```bash
TARGET_OS=ubuntu
docker build -f tests/$TARGET_OS/Dockerfile .
```
```
10 changes: 0 additions & 10 deletions scripts/tests/alpine/Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions scripts/tests/debian/Dockerfile

This file was deleted.

13 changes: 13 additions & 0 deletions scripts/tests/test-script.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bats

WAZUH_MANAGER="10.0.0.2"

chmod +x /app/scripts/install.sh

# Test if the script runs without errors
@test "script runs without errors" {
export WAZUH_AGENT_NAME="test-agent-123"
/app/scripts/install.sh
[ "$status" -eq 0 ]
}

10 changes: 0 additions & 10 deletions scripts/tests/ubuntu/Dockerfile

This file was deleted.

0 comments on commit 4693b43

Please sign in to comment.