debian-forge-composer/cmd/osbuild-pipeline/main.go
Lars Karlitski f9cbc8593f distro: add DetectHost
lorax-composer uses the host's repositories for building images. This is
prone to accidental configuration errors and duplicates functionality
(adding custom repositories via the source API is much more explicit).

However, blueprints don't specify the distribution they're based on.
This is something they should do in the future to enable cross-distro
image builds. Until then, read `/etc/os-release` to detect the host OS
and use that as the base distro for a blueprint.

Detection works by concatenating the ID field with a `-` and the
VERSION_ID field. This mandates how additional distributions should
register themselves to the `distro` package.

If composer cannot build the detected distro, fall back to fedora-30.

Use this detection everywhere that fedora-30 was hard-coded before.
2019-11-10 17:23:14 +01:00

46 lines
989 B
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/distro/fedora30"
)
func main() {
var format string
var blueprintArg string
flag.StringVar(&format, "output-format", "qcow2", "output format")
flag.StringVar(&blueprintArg, "blueprint", "", "blueprint to translate")
flag.Parse()
blueprint := &blueprint.Blueprint{}
if blueprintArg != "" {
file, err := ioutil.ReadFile(blueprintArg)
if err != nil {
panic("Colud not find blueprint")
}
err = json.Unmarshal([]byte(file), &blueprint)
if err != nil {
panic("Colud not parse blueprint")
}
}
d := distro.New("")
pipeline, err := d.Pipeline(blueprint, 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)
}