Skip to content

Auto-update melange image if older than 30 days#30

Open
AmberArcadia wants to merge 2 commits intomainfrom
auto-update-melange-image-clean
Open

Auto-update melange image if older than 30 days#30
AmberArcadia wants to merge 2 commits intomainfrom
auto-update-melange-image-clean

Conversation

@AmberArcadia
Copy link
Copy Markdown
Member

@AmberArcadia AmberArcadia commented Mar 26, 2026

Automatically checks the age of the local melange Docker image and silently pulls an updated version if it's older than 30 days.

This helps ensure users have recent melange versions with the latest features and bug fixes, such as support for the test-resources field that was added in recent versions.

Changes:

  • Added check_and_update_melange_image() function that checks image creation date
  • If image is >30 days old, silently pulls the latest version in the background
  • If image doesn't exist locally, pulls it automatically
  • Handles errors gracefully and continues with existing image if update fails

The check runs at the start of the shellcheck hook, so users get updated images without manual intervention or delays.

Automatically checks the age of the local melange Docker image and pulls
an updated version if it's older than 30 days. Gives users a 15-second
window to abort with Ctrl+C before pulling.
@AmberArcadia AmberArcadia requested review from dannf and removed request for dannf March 27, 2026 00:02
@AmberArcadia
Copy link
Copy Markdown
Member Author

AmberArcadia commented Mar 27, 2026

Hmmm it won't show the prompt by default it seems, oh well.

● Bash(timeout 25 pre-commit try-repo /home/amber-arcadia/Documents/GitRepos/pre-commit-hooks shellcheck-run-steps --verbose --files os/aws-privateca-issuer.yaml 2>&1 | tail -50)                     
  ⎿  ===============================================================================                                                                                                                   
     Using config:                                                                                                                                                                                     
     ===============================================================================                                                                                                                   
     repos:                                                                                                                                                                                            
     -   repo: ../pre-commit-hooks                                                                                                                                                                     
         rev: be610949abd356e2daa4e4a9e9659b6dd1d845e2                                                                                                                                                 
         hooks:                                                                                                                                                                                        
         -   id: shellcheck-run-steps                                                                                                                                                                  
     ===============================================================================                                                                                                                   
     [INFO] Initializing environment for ../pre-commit-hooks.                                                                                                                                          
     [INFO] Installing environment for ../pre-commit-hooks.                                                                                                                                            
     [INFO] Once installed this environment will be reused.                                                                                                                                            
     [INFO] This may take a few minutes...                                                                                                                                                             
     shellcheck run steps.....................................................Passed                                                                                                                   
     - hook id: shellcheck-run-steps                                                                                                                                                                   
     - duration: 16.38s                                                                                                                                                                                
                                                                                                                                                                                                       
     ⚠️  Melange image is 0 days old (created 2026-03-26)                                                                                                                                              
     ⚠️  Pulling updated melange image: cgr.dev/chainguard/melange:latest                                                                                                                              
     ⚠️  Press Ctrl+C now to abort or wait 15 seconds to continue...                                                                                                                                   
     Pulling cgr.dev/chainguard/melange:latest...                                                                                                                                                      
     latest: Pulling from chainguard/melange                                                                                                                                                           
     Digest: sha256:6c53e6558fc69b516f5c5704fe6aead50d91bfc40ebe9163797a52a18627f1e1                                                                                                                   
     Status: Image is up to date for cgr.dev/chainguard/melange:latest                                                                                                                                 
     cgr.dev/chainguard/melange:latest                                                                                                                                                                 
     ✓ Melange image updated successfully                                                                                                                                                              
     2026/03/27 00:52:42 WARN unable to detect commit for build config file: opening git repository: repository does not exist                                                                         
     2026/03/27 00:52:42 WARN git repository URL for build config not provided                              

@AmberArcadia AmberArcadia requested a review from dannf March 27, 2026 01:25
Copy link
Copy Markdown
Member

@stevebeattie stevebeattie left a comment

Choose a reason for hiding this comment

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

Beyond one minor nit that doesn't necessarily need to block landing this looks good to me.

Comment on lines 119 to +122
def main(argv: Sequence[str] | None = None) -> int:
# Check and update melange image if needed
check_and_update_melange_image(MelangeImage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By performing this before the argument parser checking, the melange image check happens even if one does shellcheck_run_steps.py --help which might be unexpected or take a bit to show the help information.

Copy link
Copy Markdown
Contributor

@dannf dannf left a comment

Choose a reason for hiding this comment

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

Great idea!

now = datetime.now(timezone.utc)
age_days = (now - created_date).days

if age_days > 30:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

personally, I'd prefer once a day since we typically don't worry too much about backwards compat in melange changes. It might be cool to make this a config option.

subprocess.run(
["docker", "pull", image],
check=True,
capture_output=True,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another option would be to make this melange_image_outdated() check that returns True if the image is missing or out of date. We can use that to decide if we should add --pull always to the docker run command below. I think that would avoid having the 2 different docker pull code paths here.

Or, if we made it docker_image_outdated(img, age), we could re-use it for the shellcheck image as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants