melange2

command module
v0.0.0-...-fc57355 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

melange2

EXPERIMENTAL - This is an experimental fork of melange that uses BuildKit as the execution backend.

Build apk packages using declarative pipelines, powered by BuildKit.

What is melange2?

melange2 is an experimental reimplementation of melange's build execution layer using BuildKit instead of the traditional runner-based approach (bubblewrap, Docker, QEMU). This provides:

  • BuildKit-native execution - Leverages BuildKit's LLB (Low-Level Build) for efficient, cacheable builds
  • Better caching - BuildKit's content-addressable cache provides fine-grained layer caching
  • Progress visibility - Real-time build progress with step timing and cache hit information
  • Simplified architecture - Single execution backend instead of multiple runners

Key Differences from melange

Feature melange melange2
Execution backend bubblewrap/Docker/QEMU BuildKit
Multi-arch support QEMU emulation BuildKit cross-compilation
Build caching Limited BuildKit content-addressable cache
Progress output Basic logging Step-by-step with cache status

Status

This project is experimental and not intended for production use. It exists to explore BuildKit as an alternative execution backend for melange builds.

Current status:

  • Both build and test commands use BuildKit
  • Legacy runner code has been removed
  • Actively being validated against upstream melange (see #32)

Current limitations:

  • Some edge cases may not be fully supported
  • API and behavior may change without notice

Installation

go install github.com/dlorenc/melange2@latest

Prerequisites

melange2 requires a running BuildKit daemon:

# Start BuildKit with Docker
docker run -d --name buildkitd --privileged -p 1234:1234 \
  moby/buildkit:latest --addr tcp://0.0.0.0:1234

# Or use a local buildkitd
buildkitd --addr tcp://0.0.0.0:1234

Usage

# Build a package
melange2 build package.yaml --buildkit-addr tcp://localhost:1234

# Build with debug output (shows build logs)
melange2 build package.yaml --buildkit-addr tcp://localhost:1234 --debug

# Build for a specific architecture
melange2 build package.yaml --buildkit-addr tcp://localhost:1234 --arch x86_64
Example Output
INFO solving build graph
INFO [1/12] local://apko-mypackage
INFO   -> local://apko-mypackage (0.0s) [done]
INFO [3/12] copy apko rootfs
INFO   -> copy apko rootfs (0.0s) [CACHED]
INFO [7/12] uses: go/build
INFO     | go build -o /home/build/output ./cmd/...
INFO   -> uses: go/build (18.3s) [done]
INFO
INFO Build summary:
INFO   Total steps:  12
INFO   Cached:       5
INFO   Executed:     7
INFO   Duration:     45.2s

Build File Format

melange2 uses the same build file format as melange:

package:
  name: hello
  version: 1.0.0
  epoch: 0
  description: "Hello world package"

environment:
  contents:
    repositories:
      - https://packages.wolfi.dev/os
    keyring:
      - https://packages.wolfi.dev/os/wolfi-signing.rsa.pub
    packages:
      - busybox
      - build-base

pipeline:
  - runs: |
      echo "Hello from BuildKit!"
      mkdir -p ${{targets.destdir}}/usr/bin
      echo '#!/bin/sh' > ${{targets.destdir}}/usr/bin/hello
      echo 'echo Hello World' >> ${{targets.destdir}}/usr/bin/hello
      chmod +x ${{targets.destdir}}/usr/bin/hello

Architecture

melange2 converts melange pipelines to BuildKit LLB operations:

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  melange.yaml   │────▶│   LLB Builder   │────▶│    BuildKit     │
│  (pipelines)    │     │  (pkg/buildkit) │     │    Daemon       │
└─────────────────┘     └─────────────────┘     └─────────────────┘
                                                        │
                        ┌─────────────────┐            │
                        │   APK Output    │◀───────────┘
                        │  (packages/)    │
                        └─────────────────┘

The build process:

  1. apko creates the build environment as an OCI layer
  2. LLB Builder converts pipeline steps to BuildKit operations
  3. BuildKit executes the build with caching and exports results
  4. melange packages the output as APK files

Remote Build Server

melange2 includes melange-server, a remote build service for distributing builds across multiple BuildKit backends.

# Build and run the server
go build -o melange-server ./cmd/melange-server/
./melange-server --buildkit-addr tcp://localhost:1234

# Submit a remote build
melange2 remote submit package.yaml --server http://localhost:8080 --wait

Key features:

  • Multi-backend support - Route builds to different BuildKit instances by architecture
  • Job scheduling - Queue and execute builds with configurable concurrency
  • GCS storage - Store build artifacts in Google Cloud Storage for production deployments
  • Backend pools - Manage pools of BuildKit backends with labels and health checks

See docs/remote-builds/ for detailed documentation.

Development

Running Tests
# Unit tests
go test -short ./...

# E2E tests (requires Docker for testcontainers)
go test -v ./pkg/buildkit/...
Comparing Against Upstream Melange

melange2 includes a comparison test harness to validate builds against upstream melange:

# Clone wolfi-dev/os and build upstream melange
git clone https://github.com/wolfi-dev/os /tmp/wolfi-os
git clone https://github.com/chainguard-dev/melange /tmp/upstream-melange
cd /tmp/upstream-melange && go build -o /tmp/melange-upstream .

# Run comparison (from melange2 repo)
make compare \
  WOLFI_REPO=/tmp/wolfi-os \
  BASELINE_MELANGE=/tmp/melange-upstream \
  PACKAGES="jq xz zstd"

See make help for all available options.

Upstream

This is a fork of chainguard-dev/melange. For production use, please use the upstream project.

License

Apache License 2.0 - see LICENSE for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
apko-server command
Command apko-server runs the apko layer generation service.
Command apko-server runs the apko layer generation service.
melange-api command
Command melange-api runs the standalone API server for the melange service.
Command melange-api runs the standalone API server for the melange service.
melange-apko-manager command
Command melange-apko-manager runs the Apko Manager as a gRPC service.
Command melange-apko-manager runs the Apko Manager as a gRPC service.
melange-buildkit-manager command
Command melange-buildkit-manager runs the BuildKit Manager as a gRPC service.
Command melange-buildkit-manager runs the BuildKit Manager as a gRPC service.
melange-orchestrator command
Command melange-orchestrator runs the standalone orchestrator for the melange service.
Command melange-orchestrator runs the standalone orchestrator for the melange service.
melange-server command
Command melange-server runs the melange build service.
Command melange-server runs the melange build service.
e2e
Package e2e provides a fixture-driven end-to-end test framework.
Package e2e provides a fixture-driven end-to-end test framework.
harness
Package harness provides test infrastructure for e2e tests.
Package harness provides test infrastructure for e2e tests.
internal
gen-jsonschema command
pkg
build/sbom
Package sbom defines build-time SBOM structures and utilities.
Package sbom defines build-time SBOM structures and utilities.
build/sbom/spdx
Package spdx implements an SPDX SBOM generator for Melange builds.
Package spdx implements an SPDX SBOM generator for Melange builds.
buildkit
Package buildkit provides BuildKit integration for melange builds.
Package buildkit provides BuildKit integration for melange builds.
cli
convention
Package convention provides convention-based detection for melange builds.
Package convention provides convention-based detection for melange builds.
output
Package output provides post-build processing for melange packages.
Package output provides post-build processing for melange packages.
sbom
Package sbom captures the internal data model of the SBOMs melange produces into a private, generalized bill of materials model (with relationship data) designed to be converted to specific formats — for now, just SPDX.
Package sbom captures the internal data model of the SBOMs melange produces into a private, generalized bill of materials model (with relationship data) designed to be converted to specific formats — for now, just SPDX.
sca
service/api
Package api provides the HTTP API server for the melange service.
Package api provides the HTTP API server for the melange service.
service/buildkit
Package buildkit provides BuildKit backend pool management.
Package buildkit provides BuildKit backend pool management.
service/client
Package client provides an HTTP client for the melange service API.
Package client provides an HTTP client for the melange service API.
service/dag
Package dag provides dependency graph construction and topological sorting for multi-package builds.
Package dag provides dependency graph construction and topological sorting for multi-package builds.
service/errors
Package errors provides typed errors for the melange service.
Package errors provides typed errors for the melange service.
service/git
Package git provides git repository cloning and config file discovery for multi-package builds.
Package git provides git repository cloning and config file discovery for multi-package builds.
service/metrics
Package metrics provides Prometheus metrics for melange-server and apko-server.
Package metrics provides Prometheus metrics for melange-server and apko-server.
service/orchestrator
Package orchestrator provides build orchestration using HTTP client.
Package orchestrator provides build orchestration using HTTP client.
service/scheduler
Package scheduler provides build scheduling and execution.
Package scheduler provides build scheduling and execution.
service/storage
Package storage provides artifact and log storage backends.
Package storage provides artifact and log storage backends.
service/store
Package store provides build storage implementations.
Package store provides build storage implementations.
service/tracing
Package tracing provides OpenTelemetry tracing setup for melange-server.
Package tracing provides OpenTelemetry tracing setup for melange-server.
service/types
Package types defines the core types for the melange service.
Package types defines the core types for the melange service.

Jump to

Keyboard shortcuts

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