debian-forge-composer/cmd/osbuild-pipeline/main.go
Tom Gundersen d33fc5f010 composer: add provisional multi-arch support
The pipeline generation now takes the architecture as an argument.
Currently only x86_64 is supported. The architecture is detected
at start-up, and passed down to each pipeline translation.

For osbuild-pipeline we now requrie the architecture to be passed
in.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-12-11 15:23:24 +01:00

71 lines
1.8 KiB
Go

package main
import (
"encoding/json"
"flag"
"io/ioutil"
"os"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
func main() {
var format string
var blueprintArg string
var archArg string
var distroArg string
flag.StringVar(&format, "output-format", "", "output format")
flag.StringVar(&blueprintArg, "blueprint", "", "blueprint to translate")
flag.StringVar(&archArg, "arch", "", "architecture to create image for")
flag.StringVar(&distroArg, "distro", "", "distribution to create")
flag.Parse()
blueprint := &blueprint.Blueprint{}
if blueprintArg != "" {
file, err := ioutil.ReadFile(blueprintArg)
if err != nil {
panic("Could not find blueprint: " + err.Error())
}
err = json.Unmarshal([]byte(file), &blueprint)
if err != nil {
panic("Could not parse blueprint: " + err.Error())
}
}
d := distro.New(distroArg)
if d == nil {
panic("unknown distro: " + distroArg)
}
packages := make([]string, len(blueprint.Packages))
for i, pkg := range blueprint.Packages {
packages[i] = pkg.Name
// If a package has version "*" the package name suffix must be equal to "-*-*.*"
// Using just "-*" would find any other package containing the package name
if pkg.Version != "" && pkg.Version != "*" {
packages[i] += "-" + pkg.Version
} else if pkg.Version == "*" {
packages[i] += "-*-*.*"
}
}
rpmmd := rpmmd.NewRPMMD()
_, checksums, err := rpmmd.Depsolve(packages, d.Repositories())
if err != nil {
panic(err.Error())
}
pipeline, err := d.Pipeline(blueprint, checksums, archArg, format)
if err != nil {
panic(err.Error())
}
bytes, err := json.Marshal(pipeline)
if err != nil {
panic("could not marshal pipeline into JSON")
}
os.Stdout.Write(bytes)
}