Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/chainguard-dev/melange/llms.txt

Use this file to discover all available pages before exploring further.

melange query reads a melange YAML configuration file and evaluates a Go template expression against it, printing the result to stdout. This lets you extract any field from a package config — name, version, epoch, dependencies, or any other structured data — without writing a dedicated YAML parser. The output is plain text, making it easy to consume in shell scripts, CI pipelines, and automation tooling.

Usage

melange query <config.yaml> "<go-template>" [flags]
Both arguments are required. The template is evaluated against the top-level melange config structure, so fields are accessed via their Go struct paths (e.g. .Package.Name, .Package.Version).

Examples

# Print the full package version string (name-version-rEPOCH)
melange query crane.yaml "{{ .Package.Name }}-{{ .Package.Version }}-r{{ .Package.Epoch }}"
# Output: crane-0.19.1-r0

# Print just the version
melange query crane.yaml "{{ .Package.Version }}"
# Output: 0.19.1

# Print the package name
melange query crane.yaml "{{ .Package.Name }}"
# Output: crane

# Print the epoch
melange query crane.yaml "{{ .Package.Epoch }}"
# Output: 0

# Use in a shell script to tag a Docker image
VERSION=$(melange query crane.yaml "{{ .Package.Version }}")
docker tag crane:latest crane:${VERSION}

Template data model

The template receives the parsed melange config as its data object. Key top-level fields available in templates:
Template pathTypeDescription
.Package.NamestringPackage name
.Package.VersionstringPackage version
.Package.EpochintPackage epoch
.Package.DescriptionstringShort package description
.Package.Dependencies.Runtime[]stringRuntime dependencies
.EnvironmentstructBuild environment configuration
.Pipeline[]structBuild pipeline steps
.Subpackages[]structSubpackage definitions
The full data model mirrors the melange YAML schema. Any field that can appear in a melange YAML file can be accessed in a query template using Go template dot-notation.

Flags

melange query has no command-specific flags beyond the inherited global:
FlagDefaultDescription
--log-levelINFOLog verbosity: debug, info, warn, or error

Shorthand: package-version

For the common case of printing the full package version string, the melange package-version command provides a convenient shorthand:
# Equivalent to: melange query config.yaml '{{ .Package.Name }}-{{ .Package.Version }}-r{{ .Package.Epoch }}'
melange package-version crane.yaml
# Output: crane-0.19.1-r0

CI script usage

melange query is particularly useful in CI/CD workflows where build steps need to read metadata from the package config:
#!/usr/bin/env bash
set -euo pipefail

NAME=$(melange query mypackage.yaml "{{ .Package.Name }}")
VERSION=$(melange query mypackage.yaml "{{ .Package.Version }}")
EPOCH=$(melange query mypackage.yaml "{{ .Package.Epoch }}")

echo "Building ${NAME} ${VERSION} (epoch ${EPOCH})"

melange build mypackage.yaml \
  --signing-key local-melange.rsa \
  --arch x86_64,aarch64

# Upload to a GCS bucket named after the version
gsutil cp packages/x86_64/*.apk "gs://my-repo/${VERSION}/"
Go templates support the full range of template functions including printf, index, range, and if conditionals. For complex extractions, refer to the Go template documentation.

Build docs developers (and LLMs) love