compose2quadlet

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT, MIT Imports: 10 Imported by: 0

README

compose2quadlet

Go library that transpiles Docker Compose files into Podman Quadlet unit files.

Not a CLI tool. This is a library designed to be consumed by comquad and other tools that need programmatic compose-to-quadlet conversion.

Heavily inspired by podlet, but designed for the Go ecosystem.

Motivation

Replaces the former podlet binary dependency with a native Go library. Eliminates the fragile text-based pipeline (preprocess → strip → transpile → cook → graft) with structured, type-safe quadlet output.

Usage

Quick pathTranspileFile loads the compose file with .env resolution and transpiles in one call:

import (
    c2q "github.com/Inoriol/comquad/compose2quadlet"
    "github.com/Inoriol/comquad/compose2quadlet/serialization"
)

func main() {
    units, _ := c2q.TranspileFile("compose.yaml",
        c2q.WithProjectName("myapp"),
        c2q.WithPortOffset(10000),
        c2q.WithAutoUpdate(),
        c2q.WithLabels(map[string]string{
            "com.myorg.managed": "true",
            "com.myorg.project": "myapp",
        }),
    )

    // Write all units to a directory
    serialization.WriteUnits("/etc/containers/systemd", units)
}

Full control — load the compose-go project yourself and call Transpile:

import (
    c2q "github.com/Inoriol/comquad/compose2quadlet"
    "github.com/Inoriol/comquad/compose2quadlet/serialization"
    "github.com/compose-spec/compose-go/v2/cli"
)

func main() {
    opts, _ := cli.NewProjectOptions(
        []string{"compose.yaml"},
        cli.WithOsEnv,
        cli.WithDotEnv,
    )
    project, _ := opts.LoadProject(context.Background())

    units, _ := c2q.Transpile(project,
        c2q.WithProjectName("myapp"),
        c2q.WithPortOffset(10000),
        c2q.WithAutoUpdate(),
        c2q.WithLabels(map[string]string{
            "com.myorg.managed": "true",
            "com.myorg.project": "myapp",
        }),
    )

    for _, u := range units {
        fmt.Printf("%s.%s\n", u.Name, u.Type)
    }

    // Serialize to ini format for writing to disk
    text := serialization.Marshal(units[0])
    fmt.Println(text)
}

Packages

  • RootTranspile(), TranspileFile(), ParseVersion(), core types (QuadletUnit, Section, Directive), option constructors
  • mapper/ — Field mapping: compose-go ServiceConfig / *Project → quadlet directives and units
    • container.go, healthcheck.go, security.go, ports.go — per-service container directives
    • service.go — systemd [Service] resource-control and restart directives
    • unit.godepends_on[Unit] dependencies and health polling hooks
    • image.go, build.go — companion .image and .build structural units
    • network.go, volume.go — top-level .network and .volume structural units
    • secrets.go — pre-mapping interceptor for secrets and configs
    • dockerfile.goPatchDockerfileFROM() normalizes bare image names in Dockerfile FROM lines
  • opinionated/ — Composable post-processing transforms (prefix, references including external resources, container name, SELinux relabeling, labels, default network, network aliases, port offset, auto-update, install section)
  • serialization/Marshal(), Write(), WriteUnits(), Unmarshal() for ini-format serialization

Warnings from degraded or skipped mappings are sent through the WithInfo callback when configured. Fatal mappings still return an error. Environment-secret and patched-Dockerfile write failures are reported as degraded warnings.

Dependencies

  • github.com/compose-spec/compose-go/v2 — canonical compose parsing
  • Standard library only otherwise

Determinism

Directive ordering is deterministic: all map iteration (labels, annotations, environment, sysctls, service networks, depends_on, logging options, driver opts, etc.) is sorted, so transpiling the same compose file always produces byte-identical output. This makes the library safe for golden-file testing and reproducible deploys.

License

MIT

Documentation

Index

Constants

View Source
const (
	WarningSkipped  = types.WarningSkipped
	WarningDegraded = types.WarningDegraded
	WarningFatal    = types.WarningFatal
)
View Source
const (
	UnitContainer = types.UnitContainer
	UnitNetwork   = types.UnitNetwork
	UnitVolume    = types.UnitVolume
	UnitImage     = types.UnitImage
	UnitBuild     = types.UnitBuild
)
View Source
const (
	SectionUnit      = types.SectionUnit
	SectionService   = types.SectionService
	SectionInstall   = types.SectionInstall
	SectionContainer = types.SectionContainer
	SectionNetwork   = types.SectionNetwork
	SectionVolume    = types.SectionVolume
	SectionImage     = types.SectionImage
	SectionBuild     = types.SectionBuild
)

Variables

This section is empty.

Functions

func PatchDockerfileFile

func PatchDockerfileFile(path string) (string, error)

func WithAutoUpdate

func WithAutoUpdate() types.Option

func WithBuildCacheDir

func WithBuildCacheDir(p string) types.Option

func WithDockerfileNormalization

func WithDockerfileNormalization() types.Option

func WithDryRun

func WithDryRun() types.Option

func WithImageRetry

func WithImageRetry(n int) types.Option

func WithImageRetryDelay

func WithImageRetryDelay(s int) types.Option

func WithInfo

func WithInfo(fn func(string)) types.Option

func WithLabels

func WithLabels(l map[string]string) types.Option

func WithPodmanVersion

func WithPodmanVersion(v Version) types.Option

func WithPortOffset

func WithPortOffset(o int) types.Option

func WithPrefix

func WithPrefix(p string) types.Option

func WithProjectName

func WithProjectName(n string) types.Option

func WithSecretsDirectory

func WithSecretsDirectory(p string) types.Option

func WithWorkingDirectory

func WithWorkingDirectory(p string) types.Option

func WithoutDefaultNetwork

func WithoutDefaultNetwork() types.Option

func WithoutInstallSection

func WithoutInstallSection() types.Option

func WithoutNetworkAliases

func WithoutNetworkAliases() types.Option

func WithoutPrefix

func WithoutPrefix() types.Option

func WithoutSELinux

func WithoutSELinux() types.Option

Types

type Directive

type Directive = types.Directive

type QuadletUnit

type QuadletUnit = types.QuadletUnit

func Transpile

func Transpile(project *types.Project, opts ...TranspileOption) ([]QuadletUnit, error)

func TranspileFile

func TranspileFile(composePath string, opts ...TranspileOption) ([]QuadletUnit, error)

type Section

type Section = types.Section

type TranspileOption

type TranspileOption = types.Option

type UnitType

type UnitType = types.UnitType

type Version

type Version = types.Version

func ParseVersion

func ParseVersion(s string) (Version, error)

type Warning

type Warning = types.Warning

type WarningLevel

type WarningLevel = types.WarningLevel

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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