gportage

module
v0.9.0-beta.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2025 License: MIT

README ΒΆ

GPortage - Next-generation Package Manager for Gentoo

Go Report Card Tests Go Version

GPortage is a modern reimplementation of Gentoo's Portage package manager in Go, designed to solve fundamental problems in dependency resolution while maintaining full compatibility with existing Gentoo ecosystems.

Why GPortage?

Gentoo's traditional package management faces challenges with long-term system upgrades. GPortage solves these problems with:

βœ… SAT-based dependency solver - Guarantees conflict-free upgrades
πŸš€ Transactional updates - Snapshot-based rollbacks using Btrfs/ZFS
πŸ” Incremental sync - Git-like repository updates
πŸ”„ Full Portage compatibility - Seamless transition from existing systems
⚑ Parallel processing - Optimized for modern multi-core systems

# Solve upgrade conflicts that traditional Portage can't handle
gportage resolve --deep-upgrade

Architecture Overview

v0.9.0: Single Binary with Daemon + DDD Architecture

graph TD
    subgraph "GPortage Binary"
        CLI[CLI Mode] -->|Auto-detect| DAEMON{Daemon Running?}
        DAEMON -->|Yes| GRPC[gRPC Client]
        DAEMON -->|No| STANDALONE[Standalone Mode]

        subgraph "Daemon Mode (DDD Layered Architecture)"
            subgraph "Interface Layer"
                GRPCS[gRPC Server<br/>Unix Socket]
                REST[REST API<br/>HTTP :8080]
            end

            subgraph "Application Layer"
                APP[PackageService<br/>Orchestration]
                DTO[DTOs<br/>Data Transfer]
            end

            subgraph "Domain Layer"
                PKG[Package<br/>Aggregate Root]
                DEPSVC[DependencyService<br/>Domain Logic]
            end

            subgraph "Infrastructure Layer"
                SOLVER[SAT Solver<br/>Resolution]
                REPO[Repository<br/>Package Data]
            end

            CACHE[Warm Cache<br/>Ebuilds/SAT]
            QUEUE[Job Queue<br/>Parallel Tasks]
            MONITOR[Background<br/>Monitoring]
        end

        GRPC -.->|RPC| GRPCS
        REST --> GRPCS
        GRPCS --> APP
        APP --> DTO
        APP --> DEPSVC
        APP --> SOLVER
        APP --> REPO
        DEPSVC --> PKG
        SOLVER --> REPO
        SOLVER --> PKG

        DAEMON_SERVICE[gportage daemon]
        DAEMON_SERVICE --> GRPCS
        DAEMON_SERVICE --> REST
        DAEMON_SERVICE --> MONITOR
        DAEMON_SERVICE --> CACHE
    end

    subgraph "Backend Data Sources"
        PORTAGE[Portage Tree<br/>/var/db/repos/gentoo]
        STATE[System State<br/>/var/db/pkg]
        BINPKG[Binary Packages<br/>.gpkg.tar]
    end

    STANDALONE --> APP
    REPO --> PORTAGE
    REPO --> STATE
    REPO --> BINPKG

Key Benefits:

  • ⚑ Instant CLI responses - Warm cache eliminates cold-start delays
  • πŸ”„ Job queue - Prevents package conflicts from concurrent operations
  • πŸ“‘ REST API - Web dashboards and monitoring tools
  • 🎯 Auto-detection - CLI automatically uses daemon when available
  • πŸ”Œ Fallback mode - Works standalone if daemon unavailable

DDD Architecture (Phase 3+):

  • Interface Layer - gRPC/REST adapters (thin, protocol conversion)
  • Application Layer - Use case orchestration (PackageService)
  • Domain Layer - Business logic (Package, DependencyService)
  • Infrastructure Layer - Technical concerns (SAT solver, Repository)

Benefits: Clean separation of concerns, testability, maintainability, future-proof for microservices migration.

Getting Started

Prerequisites
  • Go 1.25+ (for building from source)
  • Linux system (Gentoo recommended)
  • Git
Installation

Option 1: Download Binary (Recommended for testing v0.9.0-beta.1)

# Download latest beta release
wget https://github.com/kolkov/gportage/releases/download/v0.9.0-beta.1/gportage_0.9.0-beta.1_linux_x86_64.tar.gz

# Verify checksum
wget https://github.com/kolkov/gportage/releases/download/v0.9.0-beta.1/checksums.txt
sha256sum -c checksums.txt --ignore-missing

# Extract and install
tar -xzf gportage_0.9.0-beta.1_linux_x86_64.tar.gz
sudo install -m 0755 gportage /usr/bin/gportage

# Verify installation
gportage version

Other platforms:

  • ARM64: gportage_0.9.0-beta.1_linux_arm64.tar.gz
  • ARMv7: gportage_0.9.0-beta.1_linux_arm_7.tar.gz
  • ARMv6: gportage_0.9.0-beta.1_linux_arm_6.tar.gz
  • 32-bit: gportage_0.9.0-beta.1_linux_386.tar.gz

See all releases

Option 2: Build from Source

git clone https://github.com/kolkov/gportage.git
cd gportage
make build
sudo make install
Migrating from Portage
# Convert existing Portage installation
gportage init --convert-portage

# Perform initial system scan
gportage scan-system

# Test upgrade solution
gportage update --dry-run
Basic Usage

Daemon Mode (Recommended):

# Start daemon (OpenRC)
sudo rc-service gportaged start
sudo rc-update add gportaged default

# OR systemd
sudo systemctl start gportaged
sudo systemctl enable gportaged

# Check daemon status
gportage status

# CLI now uses daemon automatically
gportage install www-servers/nginx  # ⚑ Instant via daemon
gportage update --create-snapshot
gportage search firefox

Standalone Mode (No Daemon):

# Stop daemon
sudo rc-service gportaged stop

# CLI falls back to standalone mode
gportage status  # Shows: "Daemon: not running, Mode: standalone"
gportage install www-servers/nginx  # Still works, slower cold-start

Common Operations:

# Sync repository (native Go rsync)
gportage sync

# Install packages
gportage install www-servers/nginx

# Update system with snapshot protection
gportage update --create-snapshot

# Query package information
gportage info dev-lang/go

# Remove package with dependency cleanup
gportage remove net-misc/curl

# Search packages
gportage search firefox

# Show system status
gportage status

Key Features

Advanced Dependency Resolution
// Example constraint solving
solution, err := solver.Resolve(pkg.Constraint{
    Name: "dev-lang/go",
    Version: ">=1.22",
    Slot: "0/1.22",
    UseFlags: []string{"ssl", "-pie"},
})
if err != nil {
    log.Fatal("Resolution failed:", err)
}
Transactional Safety
# Create pre-upgrade snapshot
gportage snapshot create --tag pre-upgrade-2025

# Rollback if update fails
gportage snapshot restore pre-upgrade-2025

# List available snapshots
gportage snapshot list
Portage Compatibility Layer
// Convert traditional ebuild to native format
pkg, err := compat.ConvertEbuild(
    "/var/db/repos/gentoo/sys-kernel/gentoo-sources/gentoo-sources-6.9.1.ebuild"
)
if err != nil {
    return fmt.Errorf("ebuild conversion failed: %w", err)
}

Development Setup (GoLand)

  1. Clone repository:

    git clone https://github.com/kolkov/gportage.git
    
  2. Open in GoLand: File > Open > Select project directory

  3. Setup build configuration:

    • Go Build configuration
    • Build command: make dev-build
    • Run command: ./bin/gportage --dev-mode
  4. Enable tests:

    make test       # Run all tests
    make coverage   # Generate coverage report
    make benchmark  # Run performance benchmarks
    
  5. Debugging:

    • Use the built-in debugger with debug build tag
    • Example launch configuration:
    {
      "name": "Test Resolver",
      "type": "go",
      "request": "launch",
      "mode": "test",
      "program": "${workspaceFolder}/solver",
      "args": ["-test.run", "TestComplexResolution"]
    }
    

Contributing

We welcome contributions! Please follow our workflow:

  1. Fork the repository
  2. Create feature branch (feat/your-feature)
  3. Commit using Conventional Commits
  4. Submit a PR with detailed description

See our Contribution Guidelines for details.

Roadmap

Version Status Features Target
v0.1.0 βœ… Done Architecture foundation, SAT solver Q1 2025
v0.2.0 βœ… Done Portage compatibility layer Q2 2025
v0.3.0 βœ… Done USE flag resolution Q3 2025
v0.4.0 βœ… Done Dependency graph solver Q4 2025
v0.5.0 βœ… Done System integration (5 phases) Oct 2025
v0.6.0 βœ… Done Binary packages (core) Oct 2025
v0.7.0 βœ… Done Binary packages (building) Oct 2025
v0.9.0 πŸ“‹ Next Daemon + API/CLI Q1 2026
v0.8.0 πŸ“‹ Planned GoReleaser (optional) TBD
v1.0.0 🎯 Target Production-ready release Q2 2026
Current Status: v0.9.0-beta.1 βœ… RELEASED

v0.9.0-beta.1 - Daemon + API/CLI + DDD Architecture + Job Queue + Conflict Detection

Phase 1 - Foundation (Week 1-2) βœ… COMPLETE

  • βœ… Single binary with mode detection (gportage / gportage daemon)
  • βœ… Daemon core with gRPC + REST servers
  • βœ… CLI client with auto-daemon detection
  • βœ… Version injection via ldflags (Git commit, build date)
  • βœ… Unix socket communication (/var/run/gportage.sock)
  • βœ… REST API health check (/health, /api/v1/status)
  • βœ… Graceful shutdown handling (SIGTERM, SIGINT)
  • βœ… Professional Makefile with build targets

Phase 2 - gRPC Service (Week 3-4) βœ… COMPLETE

  • βœ… Protocol Buffers service definition
  • βœ… Package operations (Ping, GetStatus, InstallPackage, etc.)
  • βœ… Streaming progress for long operations
  • βœ… Full gRPC client-server implementation
  • βœ… PID file management (cross-platform)
  • βœ… Daemon detection and health checks

Phase 3 - Application Services (Week 5-6) βœ… COMPLETE

  • βœ… DDD Layered Architecture implementation
  • βœ… Application Service layer (PackageService)
    • ResolvePackage (SAT solver integration)
    • SearchPackages (repository queries)
    • GetPackageInfo (detailed package data)
    • InstallPackage (streaming progress)
  • βœ… DTOs for clean layer boundaries
  • βœ… Domain integration (Package, DependencyService)
  • βœ… Infrastructure integration (Solver, Repository)
  • βœ… All tests passing + linter clean

Phase 4 - Job Queue (Week 7) βœ… COMPLETE

  • βœ… Job Queue implementation (Worker pool pattern)
    • Concurrent job execution with configurable workers
    • Priority support (High/Normal/Low)
    • Job types: Install, Remove, Update, Sync
    • Status tracking: Pending β†’ Running β†’ Completed/Failed/Canceled
    • Progress callbacks for real-time updates
    • Graceful shutdown with timeout
    • Thread-safe operations
  • βœ… Daemon integration
    • Auto-start with daemon
    • Graceful stop with daemon
    • Statistics API (active workers, queue length, jobs by status)
  • βœ… gRPC Job management API
    • GetJobStatus(job_id) - query job status
    • ListJobs(filter) - list all jobs with optional filtering
    • CancelJob(job_id) - cancel running/pending jobs
    • InstallPackage now uses Job Queue (streaming + job_id)
  • βœ… Comprehensive tests (11 tests for Job Queue)
    • Job lifecycle tests
    • Concurrent execution tests
    • Cancellation tests
    • Graceful shutdown tests
  • βœ… Context-aware cancellation
    • Proper handling of canceled vs failed jobs
    • Context propagation through job execution
    • Graceful degradation on timeout
  • βœ… Package Conflict Detection (CRITICAL FOR SAFETY!)
    • SAT solver-based dependency analysis
    • Prevents parallel operations on same package
    • Detects shared dependency conflicts
    • Version-aware package name matching
    • Automatic job rejection with clear error messages
    • Examples:
      • βœ— dev-lang/go + dev-lang/go-1.22 β†’ CONFLICT (same package)
      • βœ— pkg1 (requires glibc-2.38) + pkg2 (updates glibc) β†’ CONFLICT (shared dep)
      • βœ… dev-lang/go + dev-lang/python β†’ OK (different packages)

Implementation Stats (Phases 1-4):

  • Code: ~3,500 lines (daemon + gRPC + Application + Job Queue + Conflict Detection)
  • Files: 21+ new files
  • Tests: 50+ tests (including 11 Job Queue + 10 Conflict Detection tests)
  • Test Coverage: 43.5% overall (72.5% daemon, 89.3% resolver)
  • Architecture: Clean DDD + Worker Pool + Conflict Detection pattern
  • Build: Single binary with version injection
  • Linter: 0 issues (golangci-lint)
  • Safety: Production-ready conflict prevention βœ…
  • Race Conditions: 0 detected (verified with race detector)
  • Release: Automated via GoReleaser + GitHub Actions

Next: Phase 5+

  • CLI commands integration (status, job management)
  • Persistent cache system
  • Background monitoring service
  • Full integration testing

Previous Achievement: v0.7.0 βœ… Complete

  • βœ… Binary package builder (source β†’ .gpkg.tar / .tbz2)
  • βœ… Package signing (GPG/SSH/RSA)
  • βœ… Local binhost manager + remote uploader
  • βœ… 1,533 lines of tests (29 tests + 6 benchmarks)

Test Coverage (Overall):

  • Domain layer: 92.3% βœ…
  • Application layer: Tested via integration βœ…
  • Solver layer: 75%+ βœ…
  • Config layer: 100% βœ…
  • Binpkg layer: 32.3% βœ…
  • Daemon layer: Full integration tests βœ…
  • gRPC layer: Streaming + RPC tests βœ…

See ROADMAP.md for detailed plans and CHANGELOG.md for full history.

CI/CD & Release Process

Current Setup:

  • βœ… GitHub Actions for automated testing (Go 1.25, Linux)
  • βœ… GolangCI-Lint v2 for code quality
  • βœ… Automated releases via GoReleaser
  • βœ… Multi-platform binaries (amd64, arm64, arm, 386)

Release Workflow:

See RELEASE_GUIDE.md for complete release process documentation.

Quick Reference:

# Beta releases (testing, API may change)
git tag -a v0.9.0-beta.X -m "[Release notes]"
git push origin v0.9.0-beta.X

# Release candidates (API frozen, bugfixes only)
git tag -a v0.9.0-rc.X -m "[Release notes]"
git push origin v0.9.0-rc.X

# Stable releases (production-ready)
git tag -a v0.9.0 -m "[Release notes]"
git push origin v0.9.0

Automated Build Pipeline:

  1. Tag push triggers GitHub Actions (.github/workflows/release.yml)
  2. Runs full test suite
  3. GoReleaser builds binaries for all platforms:
    • linux/amd64 (primary target)
    • linux/arm64 (ARM servers)
    • linux/386 (32-bit)
    • linux/arm/6 and arm/7 (Raspberry Pi, embedded)
  4. Creates GitHub Release with:
    • Multi-platform archives
    • SHA256 checksums
    • Auto-generated changelog
    • Pre-release flag (for beta/rc)

Build Time: ~2-3 minutes for full multi-platform build

Current Release: v0.9.0-beta.1

License

GPortage is licensed under the GNU General Public License v2.0 - the same as original Portage.

Directories ΒΆ

Path Synopsis
api
cmd
gportage command
internal
binpkg
Package binpkg implements local binhost management.
Package binpkg implements local binhost management.
cli
config
Package config implements Portage configuration management.
Package config implements Portage configuration management.
ebuild
Package ebuild implements ebuild execution engine.
Package ebuild implements ebuild execution engine.
install
Package install implements package installation engine.
Package install implements package installation engine.
pkg
profile
Package profile implements Gentoo profile system support.
Package profile implements Gentoo profile system support.
state
Package state implements system state tracking for installed packages.
Package state implements system state tracking for installed packages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL