From a8ece81864611808c9af908c21fe2ac8f60ac011 Mon Sep 17 00:00:00 2001 From: Sudip Roy Date: Mon, 25 Aug 2025 22:00:05 +0530 Subject: [PATCH 1/7] Update config.txt --- config.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.txt b/config.txt index 4a9e571..04df8e0 100644 --- a/config.txt +++ b/config.txt @@ -3,4 +3,5 @@ test=false # set true if you want to execute test user=test # User to run the script (root or test) build_script="/home/sudip/Desktop/auditScript/build_script.sh" # Path to the build script to be tested patch_available="no" # set yes or no -patch_path="/home/test/patch.diff" \ No newline at end of file +patch_path="/home/test/patch.diff" +install_docker="no" #set yes or no From 0ec374c0ab88bcb3e34e7f0151db520faf7403ab Mon Sep 17 00:00:00 2001 From: Sudip Roy Date: Wed, 27 Aug 2025 07:25:54 +0530 Subject: [PATCH 2/7] add docker installation --- README.md | 42 ++++++++++++++++++++++++++--------------- auto_verify.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ config.txt | 2 +- 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 79907b3..e11a2b7 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ A Docker-based automated verification tool for testing build scripts across mult ## Overview -auditScript is a tool designed to simplify the process of testing build scripts across different Docker environments. It automates the creation of Docker containers, copying build scripts and patches into them, executing the scripts, and collecting logs for analysis. +auditScript simplifies testing build scripts across different Docker environments. It automates container creation, script and patch copying, optional Docker installation inside containers, script execution, and log collection. ## Prerequisites - Docker installed and running - Bash shell environment -- Proper permissions to execute scripts and create Docker containers +- Permissions to execute scripts and create Docker containers ## Installation @@ -29,14 +29,15 @@ auditScript is a tool designed to simplify the process of testing build scripts All configuration is done through the `config.txt` file. The following options are available: -| Option | Description | Example Value | -|--------|-------------|---------------| -| `images` | Array of Docker images to test your script on | `("ubuntu:20.04" "ubuntu:22.04")` | -| `test` | Enable test execution mode | `false` or `true` | -| `user` | User context to run the script within the container | `test` or `root` | -| `build_script` | Full path to the build script on the host machine | `/home/user/auditScript/build_script.sh` | -| `patch_available` | Indicates whether a patch file should be applied | `no` or `yes` | -| `patch_path` | Full path to the patch file on the host machine | `/home/test/patch.diff` | +| Option | Description | Example Value | +|------------------|-----------------------------------------------------------|-----------------------------------------------| +| `images` | Array of Docker images to test your script on | `("ubuntu:20.04" "ubuntu:22.04")` | +| `test` | Enable test execution mode | `false` or `true` | +| `user` | User context to run the script within the container | `test` or `root` | +| `build_script` | Full path to the build script on the host machine | `/home/user/auditScript/build_script.sh` | +| `patch_available`| Indicates whether a patch file should be applied | `no` or `yes` | +| `patch_path` | Full path to the patch file on the host machine | `/home/test/patch.diff` | +| `install_docker` | Install Docker inside the container before running script | `no` or `yes` | ## Usage @@ -48,6 +49,7 @@ All configuration is done through the `config.txt` file. The following options a build_script="/path/to/your/build_script.sh" # Path to the build script patch_available="no" # set yes if you want to apply a patch patch_path="/path/to/your/patch.diff" # Path to the patch file + install_docker="no" # set yes to install Docker inside the container ``` 2. Run the verification script: @@ -60,28 +62,35 @@ All configuration is done through the `config.txt` file. The following options a 1. The script reads the configuration from `config.txt` 2. For each Docker image specified: - Creates a container + - Optionally installs Docker inside the container (`install_docker="yes"`) - Copies your build script into the container - If patch is enabled, copies the patch file - Executes the build script inside the container - Collects and saves logs - Cleans up the container -## Patch Handling (New Feature) +## Patch Handling -The script now supports applying patches during verification: +The script supports applying patches during verification: 1. Set `patch_available="yes"` in your config.txt 2. Specify the path to your patch file using `patch_path` -3. When the script runs, it will: +3. The script will: - Validate the patch file exists - Copy the patch to the container - The patch will be placed in the same directory as the build script -This feature is useful for testing temporary fixes or modifications without altering the original build script. +This is useful for testing temporary fixes or modifications without altering the original build script. + +## Docker Installation Inside Container + +If `install_docker="yes"` is set, the script will attempt to install Docker inside each container before running your build script. This is useful for build scripts that require Docker commands inside the container. + +Supported distros: Ubuntu, RHEL/CentOS, SLES/SUSE. ## Log Files -Logs for each container execution are saved in the `/root/logs/` directory with filenames derived from the Docker image name (with special characters converted to underscores). +Logs for each container execution are saved in the `/root/logs/` directory with filenames derived from the Docker image name (special characters converted to underscores). ## Troubleshooting @@ -103,3 +112,6 @@ Logs for each container execution are saved in the `/root/logs/` directory with 5. **"Build script execution failed"** - Check the generated log file for script-specific errors + +6. **"Unsupported distro for Docker install"** + - The script only supports Docker installation for Ubuntu, RHEL/CentOS, and SLES/SUSE. Ensure your Docker image is based on one of these distros if you want to use the Docker installation feature. diff --git a/auto_verify.sh b/auto_verify.sh index 7d1106f..0bd7ee6 100644 --- a/auto_verify.sh +++ b/auto_verify.sh @@ -82,6 +82,57 @@ run_verification() { fi fi + #install docker + if [ "$install_docker" == "yes" ]; then + echo "Installing Docker inside container: $container_id" | tee -a "$log_file" + + distro=$(docker exec "$container_id" sh -c 'grep "^ID=" /etc/os-release | cut -d= -f2' | tr -d '"') + + case "$distro" in + ubuntu) + docker exec "$container_id" bash -c " + apt-get update && + apt-get install -y ca-certificates curl gnupg sudo && + install -m 0755 -d /etc/apt/keyrings && + curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && + chmod a+r /etc/apt/keyrings/docker.asc && + echo \"deb [arch=\$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \$(. /etc/os-release && echo \${UBUNTU_CODENAME:-\$VERSION_CODENAME}) stable\" > /etc/apt/sources.list.d/docker.list && + apt-get update && + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && + sudo usermod -aG docker $USER && newgrp docker + sudo dockerd & && + sleep 30 + " + ;; + rhel|centos) + docker exec "$container_id" bash -c " + sudo dnf -y install dnf-plugins-core sudo && + sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo && + sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && + sudo usermod -aG docker $USER && newgrp docker + sudo dockerd & && + sleep 30 + " + ;; + sles|suse) + docker exec "$container_id" bash -c " + sudo zypper addrepo https://download.docker.com/linux/sles/docker-ce.repo && + sudo zypper install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo && + sudo usermod -aG docker $USER && newgrp docker + sudo dockerd & && + sleep 30 + " + ;; + *) + echo "Unsupported distro for Docker install: $distro" | tee -a "$log_file" + ;; + esac + + # # Start Docker daemon + # docker exec -d "$container_id" sh -c "dockerd &" + # sleep 5 + fi + # Execute build script inside the container and save logs if [ "$user" == "test" ]; then docker exec "$container_id" su - test -c "bash $script_path -$build_arg" &> "$log_file" diff --git a/config.txt b/config.txt index 04df8e0..ce76b39 100644 --- a/config.txt +++ b/config.txt @@ -4,4 +4,4 @@ user=test # User to run the script (root or test) build_script="/home/sudip/Desktop/auditScript/build_script.sh" # Path to the build script to be tested patch_available="no" # set yes or no patch_path="/home/test/patch.diff" -install_docker="no" #set yes or no +install_docker="yes" #set yes or no From 3cbb7528d6826550963ecf2dbfbe0adde45899e3 Mon Sep 17 00:00:00 2001 From: Sudip Roy Date: Wed, 3 Sep 2025 21:25:57 +0530 Subject: [PATCH 3/7] update docker start --- auto_verify.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/auto_verify.sh b/auto_verify.sh index 0bd7ee6..b6f14f6 100644 --- a/auto_verify.sh +++ b/auto_verify.sh @@ -100,9 +100,8 @@ run_verification() { apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && sudo usermod -aG docker $USER && newgrp docker - sudo dockerd & && - sleep 30 " + docker exec "$container_id" sh -c "sudo dockerd" ;; rhel|centos) docker exec "$container_id" bash -c " @@ -110,18 +109,16 @@ run_verification() { sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo && sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && sudo usermod -aG docker $USER && newgrp docker - sudo dockerd & && - sleep 30 " + docker exec "$container_id" sh -c "sudo dockerd" ;; sles|suse) docker exec "$container_id" bash -c " sudo zypper addrepo https://download.docker.com/linux/sles/docker-ce.repo && sudo zypper install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo && sudo usermod -aG docker $USER && newgrp docker - sudo dockerd & && - sleep 30 " + docker exec "$container_id" sh -c "sudo dockerd" ;; *) echo "Unsupported distro for Docker install: $distro" | tee -a "$log_file" From 7398a112e2682aec4e58f9ad357823b69ce1bc30 Mon Sep 17 00:00:00 2001 From: Sudip Roy Date: Wed, 3 Sep 2025 21:29:38 +0530 Subject: [PATCH 4/7] add a text --- auto_verify.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/auto_verify.sh b/auto_verify.sh index b6f14f6..15e016c 100644 --- a/auto_verify.sh +++ b/auto_verify.sh @@ -131,6 +131,7 @@ run_verification() { fi # Execute build script inside the container and save logs + echo "Started executing the provided script..." if [ "$user" == "test" ]; then docker exec "$container_id" su - test -c "bash $script_path -$build_arg" &> "$log_file" else From 7d1e71a349b44fc82d33ad341dc261718ca93ffc Mon Sep 17 00:00:00 2001 From: Sudip Roy Date: Wed, 3 Sep 2025 21:32:03 +0530 Subject: [PATCH 5/7] set default docker install no --- config.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.txt b/config.txt index ce76b39..04df8e0 100644 --- a/config.txt +++ b/config.txt @@ -4,4 +4,4 @@ user=test # User to run the script (root or test) build_script="/home/sudip/Desktop/auditScript/build_script.sh" # Path to the build script to be tested patch_available="no" # set yes or no patch_path="/home/test/patch.diff" -install_docker="yes" #set yes or no +install_docker="no" #set yes or no From 0a297014df02fba267b362c09afa973d74c09454 Mon Sep 17 00:00:00 2001 From: Sudip Roy Date: Wed, 3 Sep 2025 21:37:59 +0530 Subject: [PATCH 6/7] remove centos and suse --- auto_verify.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_verify.sh b/auto_verify.sh index 15e016c..3299454 100644 --- a/auto_verify.sh +++ b/auto_verify.sh @@ -103,7 +103,7 @@ run_verification() { " docker exec "$container_id" sh -c "sudo dockerd" ;; - rhel|centos) + rhel) docker exec "$container_id" bash -c " sudo dnf -y install dnf-plugins-core sudo && sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo && @@ -112,7 +112,7 @@ run_verification() { " docker exec "$container_id" sh -c "sudo dockerd" ;; - sles|suse) + sles) docker exec "$container_id" bash -c " sudo zypper addrepo https://download.docker.com/linux/sles/docker-ce.repo && sudo zypper install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo && From a628adcb4b61a07374c98fe89e3ba88125b99234 Mon Sep 17 00:00:00 2001 From: Sudip Roy Date: Wed, 3 Sep 2025 21:40:45 +0530 Subject: [PATCH 7/7] update --- auto_verify.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/auto_verify.sh b/auto_verify.sh index 3299454..5cb08ca 100644 --- a/auto_verify.sh +++ b/auto_verify.sh @@ -101,7 +101,6 @@ run_verification() { apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && sudo usermod -aG docker $USER && newgrp docker " - docker exec "$container_id" sh -c "sudo dockerd" ;; rhel) docker exec "$container_id" bash -c " @@ -110,7 +109,6 @@ run_verification() { sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && sudo usermod -aG docker $USER && newgrp docker " - docker exec "$container_id" sh -c "sudo dockerd" ;; sles) docker exec "$container_id" bash -c " @@ -118,16 +116,16 @@ run_verification() { sudo zypper install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo && sudo usermod -aG docker $USER && newgrp docker " - docker exec "$container_id" sh -c "sudo dockerd" ;; *) echo "Unsupported distro for Docker install: $distro" | tee -a "$log_file" ;; esac - # # Start Docker daemon - # docker exec -d "$container_id" sh -c "dockerd &" - # sleep 5 + # Start Docker daemon + echo "Starting dockerker..." + docker exec -d "$container_id" sh -c "sudo dockerd" + sleep 5 fi # Execute build script inside the container and save logs