Skip to content

Add Alpine Linux package management tools for EVE OS #5179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2025

Conversation

rucoder
Copy link
Contributor

@rucoder rucoder commented Aug 14, 2025

Description

this PR addresses #5172

Add three new Python tools for managing Alpine Linux package lists in the EVE build system to handle Alpine version upgrades and package maintenance.

alpine_index.py: Core library providing shared utilities for APKINDEX parsing, dependency resolution, and package classification across branches and architectures.

alpine-migrate.py: Migrates complete package lists between Alpine versions (e.g. 3.16 → 3.21), handling package relocations between main/community branches, renamed packages, and changed dependencies.

alpine-pkg-add.py: Adds specific packages with full dependency resolution to existing Alpine package lists, useful for expanding the package cache with new tools or libraries.

Key features:

  • Automatic recursive dependency resolution with cycle detection
  • Support for x86_64, aarch64, riscv64 architectures
  • Handles virtual packages (so:, cmd:, pc: prefixes) and metapackages
  • Package relocation handling between main/community branches
  • Missing package reporting for manual review
  • Optional dependency chain analysis for debugging
  • Maintains alpine-base container package cache directory structure

These tools are essential for Alpine version upgrades where packages frequently move between branches, get renamed, or have dependency changes, ensuring complete and consistent package sets for reproducible EVE OS builds.

How to test and validate this PR

Basic functionality testing:

  1. Test alpine-migrate.py migration:
    cd eve
    # Test migration from existing version to new version
    python3 tools/alpine-tools/alpine-migrate.py 3.16 3.21 --path pkg/alpine/mirrors
    
    # Verify output files are created in pkg/alpine/mirrors/3.21/
    ls pkg/alpine/mirrors/3.21/
    # Should see: main, main.x86_64, main.aarch64, community, community.x86_64, etc.
    
    # Check for missing packages (expect some due to renames/removals)
    ls pkg/alpine/mirrors/3.21/MISSING.*
  2. Test alpine-pkg-add.py package addition:
    # Add a simple package
    python3 tools/alpine-tools/alpine-pkg-add.py 3.21 vim
    
    # Add multiple development tools
    python3 tools/alpine-tools/alpine-pkg-add.py 3.21 git curl wget build-base
    
    # Test with dependency chains
    python3 tools/alpine-tools/alpine-pkg-add.py 3.21 python3-pip --print-chains
  3. Test help and validation:
      # Verify help text displays correctly
    python3 tools/alpine-tools/alpine-migrate.py --help
    python3 tools/alpine-tools/alpine-pkg-add.py --help
    
    # Test version validation
    python3 tools/alpine-tools/alpine-migrate.py 3.15 3.21  # Should fail (3.15 not supported)
    python3 tools/alpine-tools/alpine-pkg-add.py invalid-version vim  # Should fail

Expected outcomes:**

  • Package lists should be properly organized by branch and architecture
  • Dependencies should be automatically resolved and included
  • Missing packages should be reported in MISSING.* files
  • New packages should be added to existing lists without removing current ones
  • Dependency chains should display resolution paths when requested

Architecture testing:

  • Tools should work identically on x86_64 and aarch64 systems
  • Cross-architecture package resolution should handle arch-specific packages correctly

Changelog notes

Add Alpine Linux package management tools for automated version migration and package list maintenance. These tools handle Alpine version upgrades by resolving package relocations, dependencies, and architecture-specific availability changes, ensuring complete package sets for reproducible container builds.

PR Backports

  • 14.5-stable: No, new tooling feature not required for stable releases.
  • 13.4-stable: No, new tooling feature not required for stable releases.

Checklist

  • I've provided a proper description
  • I've added the proper documentation
  • I've tested my PR on amd64 device
  • I've tested my PR on arm64 device
  • I've written the test verification instructions
  • I've set the proper labels to this PR

And the last but not least:

  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

@rene
Copy link
Contributor

rene commented Aug 15, 2025

@rucoder , thanks a lot for such great scripts, these will help a lot on upgrading Alpine and to fix all missed dependencies! Good job!

@deitch
Copy link
Contributor

deitch commented Aug 15, 2025

Um, holy cow? Wow? This is great!

@deitch
Copy link
Contributor

deitch commented Aug 15, 2025

BTW, at the request of @christoph-zededa , linuxkit recently got the ability to reference other packages automatically used build-args. So we actually could replace all of the explicit FROM lfedge/eve-alpine:12345aabbccdd in each pkg/*/Dockerfile with a build arg that automatically gets populated.

I know, not a big thing compared to this, but another piece to help ease building. I was going to add a PR for it, but I prefer to let a real user (hint hint @christoph-zededa ) do it, so we can see how well it works for someone who did not build it.

Add three new tools for managing Alpine package lists in the EVE build system:
- alpine_index.py: Core library for APKINDEX parsing and dependency resolution
- alpine-migrate.py: Migrate package lists between Alpine versions (e.g. 3.16 → 3.21)
- alpine-pkg-add.py: Add specific packages with dependencies to existing lists

Features:
- Automatic dependency resolution with cycle detection
- Support for x86_64, aarch64, riscv64 architectures
- Handle package relocations between main/community branches
- Virtual package support (so:, cmd:, pc: prefixes)
- Missing package reporting and dependency chain analysis
- Maintains alpine-base container package cache structure

These tools handle Alpine version upgrades where packages move between branches,
get renamed, or have changed dependencies, ensuring complete package sets
for reproducible EVE OS builds.

Signed-off-by: Mikhail Malyshev <[email protected]>
@rucoder rucoder force-pushed the rucoder/alpine-tools branch from fc2e860 to 4f06969 Compare August 15, 2025 12:10
@github-actions github-actions bot requested a review from deitch August 15, 2025 12:10
@OhmSpectator OhmSpectator requested a review from Copilot August 15, 2025 12:20
Copy link

@Copilot 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 adds three new Python tools for managing Alpine Linux package lists in the EVE build system to handle Alpine version upgrades and package maintenance. The tools provide automated migration between Alpine versions, dependency resolution, and package addition capabilities with support for multiple architectures and repository branches.

  • Core library (alpine_index.py) providing APKINDEX parsing, dependency resolution, and package classification utilities
  • Migration tool (alpine_migrate.py) for complete package list migrations between Alpine versions with handling of package relocations and dependency changes
  • Package addition tool (alpine_pkg_add.py) for adding specific packages with full dependency resolution to existing package lists

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tools/alpine-tools/alpine_index.py Core library providing APKINDEX parsing, dependency resolution, and package classification utilities
tools/alpine-tools/alpine_migrate.py Migration tool for migrating package lists between Alpine versions with dependency resolution
tools/alpine-tools/alpine_pkg_add.py Tool for adding specific packages to existing Alpine package lists with dependency resolution
docs/ALPINE.md Documentation updates describing the new Alpine package management tools and their usage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

for provide in provides:
# Split on '=' to ignore version part
# e.g., 'pc:znc=1.9.1' becomes 'pc:znc'
# Note: Consider keeping versions for more precise dependency resolution
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

This TODO comment suggests an incomplete implementation. Version constraints in provides should either be preserved for precise dependency resolution or this comment should be removed if the current approach is intentional.

Suggested change
# Note: Consider keeping versions for more precise dependency resolution

Copilot uses AI. Check for mistakes.

print(f"🚀 Starting migration from Alpine {args.old_version} "
f"to {args.new_version}")
print(f"📁 Package directory: {args.path}")

Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

This check for same-version migration is duplicated (line 262 and 274). The logic should be consolidated to avoid redundant code and improve maintainability.

Suggested change

Copilot uses AI. Check for mistakes.

# pylint: disable=unbalanced-tuple-unpacking
classified, missing_by_branch_arch = result
chains_by_branch_arch = None

Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The pylint disable comment for 'unbalanced-tuple-unpacking' suggests a potential issue with tuple unpacking. The function resolve_and_classify_packages() returns different tuple lengths based on collect_chains parameter, which could lead to runtime errors if not handled correctly.

Suggested change
result = resolve_and_classify_packages(
packages_to_add, apk_indexes, provides_indexes, available_archs, collect_chains=print_chains
)
# Always unpack three values; chains_by_branch_arch may be None if not collected
if print_chains:
classified, missing_by_branch_arch, chains_by_branch_arch = result
else:
classified, missing_by_branch_arch, chains_by_branch_arch = result

Copilot uses AI. Check for mistakes.

@rucoder
Copy link
Contributor Author

rucoder commented Aug 18, 2025

@rene @OhmSpectator are we merging it? eden is not required here at all

@christoph-zededa
Copy link
Contributor

@rene @OhmSpectator are we merging it? eden is not required here at all

Famous last words before EVE crash ;-)

@famleebob
Copy link
Contributor

Looks good! I look forward to using the scripts

Copy link
Contributor

@famleebob famleebob left a comment

Choose a reason for hiding this comment

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

Looks good to me, nice clean scripts.

@rene
Copy link
Contributor

rene commented Aug 18, 2025

These are just script tools, it has nothing with the execution of pillar, I think it's fine to merge...

@rene rene merged commit 099e0f1 into lf-edge:master Aug 18, 2025
39 of 45 checks passed
@rucoder rucoder deleted the rucoder/alpine-tools branch August 19, 2025 12:54
@christoph-zededa
Copy link
Contributor

BTW, at the request of @christoph-zededa , linuxkit recently got the ability to reference other packages automatically used build-args. So we actually could replace all of the explicit FROM lfedge/eve-alpine:12345aabbccdd in each pkg/*/Dockerfile with a build arg that automatically gets populated.

I know, not a big thing compared to this, but another piece to help ease building. I was going to add a PR for it, but I prefer to let a real user (hint hint @christoph-zededa ) do it, so we can see how well it works for someone who did not build it.

for reference: #5190

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.

5 participants