diff --git a/docker/ecs/images/Dockerfile b/docker/ecs/images/Dockerfile index 8bf173ee403e1..34f028efc0231 100644 --- a/docker/ecs/images/Dockerfile +++ b/docker/ecs/images/Dockerfile @@ -1,21 +1,21 @@ -FROM python:latest +FROM python:3.10 RUN apt-get update && \ - apt-get upgrade && \ - apt-get install \ - git \ - jq && \ - apt-get clean \ && \ + apt-get upgrade -y && \ + apt-get install -y git jq && \ + apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ git clone https://github.com/elastic/ecs.git && \ pip install -r ecs/scripts/requirements.txt && \ - mkdir /wazuh-indexer + mkdir -p /source/ecs # Change this to a volume -ADD docker/ecs/images/generate.sh ecs/generate.sh +ADD docker/ecs/images/generate.sh /ecs/generate.sh #ADD docker/ecs/images/entrypoint.sh entrypoint.sh ADD ecs/ /wazuh-indexer/ecs -WORKDIR ecs/ +RUN chmod +x /ecs/generate.sh -ENTRYPOINT ["generate.sh"] +WORKDIR /ecs + +ENTRYPOINT ["/bin/bash", "/ecs/generate.sh"] diff --git a/docker/ecs/images/generate.sh b/docker/ecs/images/generate.sh index cc5bb58964540..e09c7a9361a8a 100755 --- a/docker/ecs/images/generate.sh +++ b/docker/ecs/images/generate.sh @@ -8,18 +8,25 @@ set -euo pipefail # compatible open source license. # Default values -DEFAULT_ECS_VERSION="v8.11.0" -DEFAULT_INDEXER_PATH="/wazuh-indexer" +ECS_VERSION="${ECS_VERSION:-v8.11.0}" +INDEXER_PATH="${INDEXER_PATH:-/source}" # Function to display usage information show_usage() { - echo "Usage: $0 [] []" - echo " * ECS_MODULE: Module to generate mappings for" - echo " * INDEXER_PATH: Path to the Wazuh indexer repository (default: /wazuh-indexer)" - echo " * ECS_VERSION: ECS version to generate mappings for (default: v8.11.0)" - echo "Example: $0 vulnerability-detector ~/wazuh-indexer v8.11.0" + echo "Usage: $0" + echo "Environment Variables:" + echo " * ECS_MODULE: Module to generate mappings for" + echo " * INDEXER_PATH: (Optional) Path to the Wazuh indexer repository (default: /source)" + echo " * ECS_VERSION: (Optional) ECS version to generate mappings for (default: v8.11.0)" + echo "Example: docker run -e ECS_MODULE=vulnerability-detector -e INDEXER_PATH=/source -e ECS_VERSION=v8.11.0 ecs-generator" } +# Ensure ECS_MODULE is provided +if [ -z "${ECS_MODULE:-}" ]; then + show_usage + exit 1 +fi + # Function to remove multi-fields from the generated index template remove_multi_fields() { local in_file="$1" @@ -86,15 +93,5 @@ generate_mappings() { echo "Mappings saved to $out_dir" } -# Parse command line arguments -if [ -z "${1:-}" ]; then - show_usage - exit 1 -fi - -ECS_MODULE="$1" -INDEXER_PATH="${2:-$DEFAULT_INDEXER_PATH}" -ECS_VERSION="${3:-$DEFAULT_ECS_VERSION}" - # Generate mappings generate_mappings "$ECS_MODULE" "$INDEXER_PATH" "$ECS_VERSION"