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..5cb08ca 100644 --- a/auto_verify.sh +++ b/auto_verify.sh @@ -82,7 +82,54 @@ 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 + " + ;; + 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 && + sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && + sudo usermod -aG docker $USER && newgrp docker + " + ;; + 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 && + sudo usermod -aG docker $USER && newgrp docker + " + ;; + *) + echo "Unsupported distro for Docker install: $distro" | tee -a "$log_file" + ;; + esac + + # 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 + 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 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