Skip to content
Merged
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,4 @@ print-release:
test:
@echo "Running quick static tests"
uv run pytest -m 'not buildonlytest'
@./scripts/check_dockerfile_alignment.sh
171 changes: 171 additions & 0 deletions scripts/check_dockerfile_alignment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/usr/bin/env bash
#=========================================================
# Script: dockerfile_diff_checker.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Script name mismatch in header comment.

Line 3 states the script name is dockerfile_diff_checker.sh, but the actual file is check_dockerfile_alignment.sh. Update the header to match the actual filename.

-# Script: dockerfile_diff_checker.sh
+# Script: check_dockerfile_alignment.sh
📝 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
# Script: dockerfile_diff_checker.sh
# Script: check_dockerfile_alignment.sh
🤖 Prompt for AI Agents
In scripts/check_dockerfile_alignment.sh around line 3 the header comment
incorrectly names the script as "dockerfile_diff_checker.sh"; update that
comment to the correct filename by changing the header to "Script:
check_dockerfile_alignment.sh" and scan for any other in-file references or
comments that mention the old name to update them as well.

# Purpose: Scan a directory tree for Dockerfile.konflux.*
# and compare each with its original Dockerfile,
# ignoring comments and multi-line LABEL instructions.
#=========================================================

set -euo pipefail

#---------------------------------------------------------
# Main script execution
#---------------------------------------------------------
main() {

# Define multiple starting directories
local start_dirs=("./jupyter" "./codeserver" "./runtimes")
echo "Scanning ${start_dirs[*]} for directories containing Dockerfile.konflux.*"
echo "Comparing Dockerfiles, ignoring comments and LABEL blocks..."

# Populate array of directories
local docker_dirs=()
for dir in "${start_dirs[@]}"; do
mapfile -t dirs < <(find_docker_dirs "$dir")
docker_dirs+=("${dirs[@]}")
done

# Process all directories and check for differences
if process_dirs "${docker_dirs[@]}"; then
echo "✅ All Dockerfiles are in sync."
else
echo "❌ Differences were found. Please inspect."
exit 1
fi
}

#---------------------------------------------------------
# Function: find_docker_dirs
# Description:
# Recursively search for directories containing files named
# "Dockerfile.konflux.*". Each directory is listed only once.
# Arguments:
# $1 - starting directory
# Returns:
# Prints each directory path containing at least one
# Dockerfile.konflux.* file
#---------------------------------------------------------
find_docker_dirs() {
local start_dir="$1"

# Use 'find' to locate matching files, then 'dirname' to extract directories, 'sort -u' to remove duplicates
find "$start_dir" -type f -name "Dockerfile.konflux.*" -exec dirname {} \; | sort -u
}

#---------------------------------------------------------
# Function: strip
# Description:
# Remove comments and ignore LABEL blocks from a Dockerfile.
# Useful for comparing Dockerfiles while ignoring cosmetic differences.
# Arguments:
# Reads from standard input
# Returns:
# Prints stripped Dockerfile to standard output
#---------------------------------------------------------
strip() {
awk '
BEGIN { in_label = 0 }

# Skip full-line comments
/^[[:space:]]*#/ { next }

# Skip lines inside multi-line LABEL blocks
in_label {
# End LABEL block if line does not end with backslash
if ($0 !~ /\\$/) in_label = 0
next
}

# Detect start of LABEL instruction
/^[[:space:]]*LABEL([ \t]|$)/ {
# Multi-line LABEL block
if ($0 ~ /\\$/) in_label = 1
next
}

# Print all other lines (trimmed)
{
# Trim leading and trailing whitespace
gsub(/^[ \t]+|[ \t]+$/, "", $0)
if (length($0) > 0) print $0
}
'
}

#---------------------------------------------------------
# Function: find_diff
# Description:
# Compare a Dockerfile with its corresponding konflux version,
# ignoring comments and LABEL blocks. Returns 1 if differences exist.
# Arguments:
# $1 - Directory containing the Dockerfiles
# $2 - Original Dockerfile name (basename)
# $3 - Konflux Dockerfile name (basename)
# Returns:
# 0 if no differences, 1 if differences exist
#---------------------------------------------------------
find_diff() {
local dir="$1"
local file_orig="$2"
local file_konflux="$3"

echo "---- diff $file_orig $file_konflux ----"

# Use process substitution to feed stripped files to diff
local diff_output
diff_output=$(diff --color=always <(strip <"$dir/$file_orig") <(strip <"$dir/$file_konflux") || true)

if [ -n "$diff_output" ]; then
echo "❌ Differences found between $file_orig and $file_konflux"
# Uncomment the next line to see detailed differences
echo "$diff_output"
Comment on lines +120 to +121
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove stale/misleading comment.

Line 120 says "Uncomment the next line" but line 121 is already active. The comment is stale; either remove it or update it if the behavior has changed. Since the script's purpose is to report differences, printing the diff output unconditionally makes sense.

-        # Uncomment the next line to see detailed differences
         echo "$diff_output"
📝 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
# Uncomment the next line to see detailed differences
echo "$diff_output"
echo "$diff_output"
🤖 Prompt for AI Agents
In scripts/check_dockerfile_alignment.sh around lines 120-121, the comment
"Uncomment the next line to see detailed differences" is stale because the echo
command on the following line is already active; remove or update the comment so
it reflects current behavior (e.g., delete the comment entirely or change it to
"Print detailed differences"); ensure the remaining code prints diff_output
unconditionally as intended.

return 1
else
echo "✅ No differences"
return 0
fi
}

#---------------------------------------------------------
# Function: process_dirs
# Description:
# Iterate over a list of directories, find konflux Dockerfiles
# in each, and compare them with their originals.
# Arguments:
# Array of directories
# Returns:
# 0 if all Dockerfiles match, 1 if any differences exist
#---------------------------------------------------------
process_dirs() {
local dirs=("$@")
local diff_found=0

# Iterate over each directory
for dir in "${dirs[@]}"; do
echo "=== Processing $dir ==="

# Iterate over each konflux Dockerfile
for konflux_file in "$dir"/Dockerfile.konflux.*; do
[ -e "$konflux_file" ] || continue

# Derive the original Dockerfile name by removing the .konflux
local dockerfile="${konflux_file/.konflux/}"

# Check if the original Dockerfile exists
if [ ! -f "$dockerfile" ]; then
echo "⚠️ $dockerfile not found in $dir" >&2
continue
fi

# Compare the files
if ! find_diff "$dir" "$(basename "$dockerfile")" "$(basename "$konflux_file")"; then
diff_found=1
fi
done
done

return $diff_found
}

# Call main with all script arguments
main "$@"
Loading