Skip to content

Conversation

@ionphractal
Copy link

While addressing cloudfoundry/bosh-agent#337 I was in the need to build stemcells for Jammy and was limited in where I build them (with limited disk space). Hence I had to add/adjust a few things to this script.

  • Add support for both jammy and noble
  • Add version bumping to a specific version
  • Add env var for specifying a temp path in case your normal temp directory is too small
  • Add env var for specifying an output path for the stemcell
  • Add automatic version bumping if the output stemcell exists
  • Cleanup more directories when exitting via trap
  • Speed up version detection by specifying the order of files to be compressed

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the stemcell repack debugger script by implementing intelligent version bumping functionality and adding support for custom output paths. The version bumping now uses semantic versioning with dev suffixes (e.g., 1.0.0+dev.1) instead of timestamp-based versions, and can automatically detect and increment existing dev versions.

Key changes:

  • Implements semantic dev versioning that increments on each repack of the same stemcell
  • Adds support for OUT environment variable to specify custom output paths
  • Optimizes tar file ordering to speed up version detection
  • Adds support for TMPDIR environment variable documentation
Comments suppressed due to low confidence (7)

scripts/stemcell-repack-debugger.sh:146

  • The command substitution in the tar command could fail if filenames contain special characters or spaces. The du -b * | sort -n | awk '{print $2}' pattern doesn't properly handle filenames with spaces. Consider using null-terminated strings:
du -b * | sort -n | awk '{print $2}' | tr '\n' '\0' | xargs -0 tar czvf ${OUT:-$stemcell_tgz}

Or use an array to store filenames safely:

readarray -t files < <(du -b * | sort -n | awk '{print $2}')
tar czvf ${OUT:-$stemcell_tgz} "${files[@]}"

scripts/stemcell-repack-debugger.sh:108

  • The regex pattern 's/dev[.]//' is missing the bracket closing. It should be 's/dev\.//' to properly escape the dot, or if you're trying to match "dev." as a prefix, use 's/^dev\.//'. The current pattern matches "dev" followed by any single character in the set containing only a dot, which is effectively just a dot.
    scripts/stemcell-repack-debugger.sh:117
  • The backreference \1 in the replacement string may need to be escaped as \\1 to work correctly within double quotes when using the -r flag. The -r flag is also not portable (BSD/macOS use -E). Consider using:
sed -r -i "s/^([[:space:]]*)version: .*/\\1version: ${new_version}/" $stemcell_dir/stemcell.MF

Or for better portability:

sed -E -i "s/^([[:space:]]*)version: .*/\\1version: ${new_version}/" $stemcell_dir/stemcell.MF

scripts/stemcell-repack-debugger.sh:14

  • Spelling error: "als" should be "also".
    scripts/stemcell-repack-debugger.sh:57
  • The use of -a for AND in the test command is deprecated. Use && or -a with proper quoting. The preferred modern syntax would be:
if [ -n "$OUT" ] && [ -f "$OUT" ]; then

This improves readability and avoids potential issues with the deprecated -a operator.
scripts/stemcell-repack-debugger.sh:100

  • Missing quotes around variable $DISK_NAME could cause issues if the variable contains spaces or special characters. Should be:
device=$(sudo kpartx -sav "$DISK_NAME" | grep '^add' | tail -n1 | cut -d' ' -f3)

scripts/stemcell-repack-debugger.sh:116

  • These lines have two issues:
  1. They appear to be leftover debugging statements that print the stemcell version before and after modification. Consider removing them or redirecting to stderr if the output is intentional for user feedback.
  2. The indentation is inconsistent - these lines should be indented to match line 115 since they're inside the if block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ramonskie
Copy link
Contributor

ramonskie commented Nov 7, 2025

i worked on this a while ago but never made a PR see https://github.com/cloudfoundry/bosh-linux-stemcell-builder/tree/helper-script

Please note that warden stemcells are packaged differently

aramprice
aramprice previously approved these changes Nov 7, 2025
@aramprice aramprice requested a review from ramonskie November 13, 2025 15:58
@beyhan beyhan moved this from Pending Review | Discussion to Waiting for Changes | Open for Contribution in Foundational Infrastructure Working Group Nov 20, 2025
@ionphractal
Copy link
Author

@Alphasite replaced all yq usage now.
@ramonskie would've been nice to have your version earlier. Maybe we should use the time to integrate all in one improvement... though it is hard for me to spare that atm and I'm on vac the next 2 weeks.

@beyhan beyhan requested a review from aramprice November 27, 2025 15:38
@beyhan beyhan moved this from Waiting for Changes | Open for Contribution to Pending Review | Discussion in Foundational Infrastructure Working Group Nov 27, 2025
@rkoster rkoster requested a review from Alphasite December 4, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending Review | Discussion

Development

Successfully merging this pull request may close these issues.

4 participants