Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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.
47 changes: 47 additions & 0 deletions auto_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment on lines +86 to +87
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Guard against unset install_docker (SC2154) and prefer = over ==

Avoid unbound var warnings and make the check robust when the key is missing in config.txt.

-    if [ "$install_docker" == "yes" ]; then
+    if [ "${install_docker:-no}" = "yes" ]; then
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ "$install_docker" == "yes" ]; then
echo "Installing Docker inside container: $container_id" | tee -a "$log_file"
if [ "${install_docker:-no}" = "yes" ]; then
echo "Installing Docker inside container: $container_id" | tee -a "$log_file"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 86-86: install_docker is referenced but not assigned.

(SC2154)

🤖 Prompt for AI Agents
In auto_verify.sh around lines 86 to 87, the if condition uses an unguarded
variable and the non-POSIX == operator; change the test to guard against unset
install_docker and use = by replacing the condition with a quoted
parameter-expansion default, e.g. if [ "${install_docker:-}" = "yes" ]; then, so
the script won't emit unbound-var warnings and will use the portable
string-equality operator.


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
Expand Down
3 changes: 2 additions & 1 deletion config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
patch_path="/home/test/patch.diff"
install_docker="no" #set yes or no