osbuild support returning metadata about each of the stages/assembler runs. Parse the results from the rpm stage, which contains the header fields from the installed RPMs, in particular the MD5 sum of the RPMs in question. This information is needed to be passed as metadata to koji when uploading images. Signed-off-by: Tom Gundersen <teg@jklm.no>
125 lines
3 KiB
Go
125 lines
3 KiB
Go
package osbuild
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
type rawAssemblerResult struct {
|
|
Name string `json:"name"`
|
|
Options json.RawMessage `json:"options"`
|
|
Success bool `json:"success"`
|
|
Output string `json:"output"`
|
|
}
|
|
|
|
type StageResult struct {
|
|
Name string `json:"name"`
|
|
Options json.RawMessage `json:"options"`
|
|
Success bool `json:"success"`
|
|
Output string `json:"output"`
|
|
Metadata StageMetadata `json:"metadata"`
|
|
}
|
|
|
|
// StageMetadata specify the metadata of a given stage-type.
|
|
type StageMetadata interface {
|
|
isStageMetadata()
|
|
}
|
|
|
|
type rawStageResult struct {
|
|
Name string `json:"name"`
|
|
Options json.RawMessage `json:"options"`
|
|
Success bool `json:"success"`
|
|
Output string `json:"output"`
|
|
Metadata json.RawMessage `json:"metadata"`
|
|
}
|
|
|
|
type buildResult struct {
|
|
Stages []StageResult `json:"stages"`
|
|
TreeID string `json:"tree_id"`
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
type Result struct {
|
|
TreeID string `json:"tree_id"`
|
|
OutputID string `json:"output_id"`
|
|
Build *buildResult `json:"build"`
|
|
Stages []StageResult `json:"stages"`
|
|
Assembler *rawAssemblerResult `json:"assembler"`
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (result *StageResult) UnmarshalJSON(data []byte) error {
|
|
var rawStageResult rawStageResult
|
|
err := json.Unmarshal(data, &rawStageResult)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var metadata StageMetadata
|
|
switch rawStageResult.Name {
|
|
case "org.osbuild.rpm":
|
|
metadata = new(RPMStageMetadata)
|
|
err = json.Unmarshal(rawStageResult.Metadata, metadata)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
default:
|
|
metadata = nil
|
|
}
|
|
|
|
result.Name = rawStageResult.Name
|
|
result.Options = rawStageResult.Options
|
|
result.Success = rawStageResult.Success
|
|
result.Output = rawStageResult.Output
|
|
result.Metadata = metadata
|
|
|
|
return nil
|
|
}
|
|
|
|
func (cr *Result) Write(writer io.Writer) error {
|
|
if cr.Build == nil && len(cr.Stages) == 0 && cr.Assembler == nil {
|
|
fmt.Fprintf(writer, "The compose result is empty.\n")
|
|
}
|
|
|
|
if cr.Build != nil {
|
|
fmt.Fprintf(writer, "Build pipeline:\n")
|
|
|
|
for _, stage := range cr.Build.Stages {
|
|
fmt.Fprintf(writer, "Stage %s\n", stage.Name)
|
|
enc := json.NewEncoder(writer)
|
|
enc.SetIndent("", " ")
|
|
err := enc.Encode(stage.Options)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintf(writer, "\nOutput:\n%s\n", stage.Output)
|
|
}
|
|
}
|
|
|
|
if len(cr.Stages) > 0 {
|
|
fmt.Fprintf(writer, "Stages:\n")
|
|
for _, stage := range cr.Stages {
|
|
fmt.Fprintf(writer, "Stage: %s\n", stage.Name)
|
|
enc := json.NewEncoder(writer)
|
|
enc.SetIndent("", " ")
|
|
err := enc.Encode(stage.Options)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintf(writer, "\nOutput:\n%s\n", stage.Output)
|
|
}
|
|
}
|
|
|
|
if cr.Assembler != nil {
|
|
fmt.Fprintf(writer, "Assembler %s:\n", cr.Assembler.Name)
|
|
enc := json.NewEncoder(writer)
|
|
enc.SetIndent("", " ")
|
|
err := enc.Encode(cr.Assembler.Options)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintf(writer, "\nOutput:\n%s\n", cr.Assembler.Output)
|
|
}
|
|
|
|
return nil
|
|
}
|