osbuild: move result serialization from common
In the same way `osbuild.Manifest` is the input to the osbuild API, `osbuild.Result` is the output. Move it to the `osbuild` package where it belongs. This is not a functional change. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
360bf2aa04
commit
ac5f69e757
7 changed files with 23 additions and 18 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/awsupload"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/azure"
|
||||
|
|
@ -86,7 +87,7 @@ func openAsStreamOptimizedVmdk(imagePath string) (*os.File, error) {
|
|||
return f, err
|
||||
}
|
||||
|
||||
func RunJob(job *worker.Job, store string, uploadFunc func(uuid.UUID, string, io.Reader) error) (*common.ComposeResult, error) {
|
||||
func RunJob(job *worker.Job, store string, uploadFunc func(uuid.UUID, string, io.Reader) error) (*osbuild.Result, error) {
|
||||
outputDirectory, err := ioutil.TempDir("/var/tmp", "osbuild-worker-*")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating temporary output directory: %v", err)
|
||||
|
|
@ -279,7 +280,7 @@ func main() {
|
|||
// This can happen in cases when OSBuild crashes and doesn't produce
|
||||
// a meaningful output. E.g. when the machine runs of disk space.
|
||||
if result == nil {
|
||||
result = &common.ComposeResult{
|
||||
result = &osbuild.Result{
|
||||
Success: false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,20 +6,20 @@ import (
|
|||
"io"
|
||||
"os/exec"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
)
|
||||
|
||||
type OSBuildError struct {
|
||||
Message string
|
||||
Result *common.ComposeResult
|
||||
Result *osbuild.Result
|
||||
}
|
||||
|
||||
func (e *OSBuildError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func RunOSBuild(manifest distro.Manifest, store, outputDirectory string, errorWriter io.Writer) (*common.ComposeResult, error) {
|
||||
func RunOSBuild(manifest distro.Manifest, store, outputDirectory string, errorWriter io.Writer) (*osbuild.Result, error) {
|
||||
cmd := exec.Command(
|
||||
"osbuild",
|
||||
"--store", store,
|
||||
|
|
@ -50,7 +50,7 @@ func RunOSBuild(manifest distro.Manifest, store, outputDirectory string, errorWr
|
|||
// FIXME: handle or comment this possible error
|
||||
_ = stdin.Close()
|
||||
|
||||
var result common.ComposeResult
|
||||
var result osbuild.Result
|
||||
err = json.NewDecoder(stdout).Decode(&result)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding osbuild output: %#v", err)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package common
|
||||
package osbuild
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
@ -26,7 +26,7 @@ type build struct {
|
|||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type ComposeResult struct {
|
||||
type Result struct {
|
||||
TreeID string `json:"tree_id"`
|
||||
OutputID string `json:"output_id"`
|
||||
Build *build `json:"build"`
|
||||
|
|
@ -35,7 +35,7 @@ type ComposeResult struct {
|
|||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
func (cr *ComposeResult) Write(writer io.Writer) error {
|
||||
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")
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
package common
|
||||
package osbuild
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWriteFull(t *testing.T) {
|
||||
|
|
@ -30,7 +31,7 @@ func TestWriteFull(t *testing.T) {
|
|||
Output: "Done",
|
||||
}
|
||||
|
||||
testComposeResult := ComposeResult{
|
||||
testComposeResult := Result{
|
||||
TreeID: "TreeID",
|
||||
OutputID: "OutputID",
|
||||
Build: &testBuild,
|
||||
|
|
@ -71,7 +72,7 @@ Done
|
|||
|
||||
func TestWriteEmpty(t *testing.T) {
|
||||
|
||||
testComposeResult := ComposeResult{}
|
||||
testComposeResult := Result{}
|
||||
|
||||
var b bytes.Buffer
|
||||
assert.NoError(t, testComposeResult.Write(&b))
|
||||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
|
|
@ -165,7 +166,7 @@ type composeStatus struct {
|
|||
Queued time.Time
|
||||
Started time.Time
|
||||
Finished time.Time
|
||||
Result *common.ComposeResult
|
||||
Result *osbuild.Result
|
||||
}
|
||||
|
||||
// Returns the state of the image in `compose` and the times the job was
|
||||
|
|
@ -194,7 +195,7 @@ func (api *API) getComposeStatus(compose store.Compose) *composeStatus {
|
|||
Queued: compose.ImageBuild.JobCreated,
|
||||
Started: compose.ImageBuild.JobStarted,
|
||||
Finished: compose.ImageBuild.JobFinished,
|
||||
Result: &common.ComposeResult{},
|
||||
Result: &osbuild.Result{},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
)
|
||||
|
||||
|
|
@ -111,7 +112,7 @@ func (c *Client) JobCanceled(job *Job) bool {
|
|||
return jr.Canceled
|
||||
}
|
||||
|
||||
func (c *Client) UpdateJob(job *Job, status common.ImageBuildState, result *common.ComposeResult) error {
|
||||
func (c *Client) UpdateJob(job *Job, status common.ImageBuildState, result *osbuild.Result) error {
|
||||
var b bytes.Buffer
|
||||
err := json.NewEncoder(&b).Encode(&updateJobRequest{status, result})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
)
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ type OSBuildJob struct {
|
|||
}
|
||||
|
||||
type OSBuildJobResult struct {
|
||||
OSBuildOutput *common.ComposeResult `json:"osbuild_output,omitempty"`
|
||||
OSBuildOutput *osbuild.Result `json:"osbuild_output,omitempty"`
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -49,7 +50,7 @@ type jobResponse struct {
|
|||
|
||||
type updateJobRequest struct {
|
||||
Status common.ImageBuildState `json:"status"`
|
||||
Result *common.ComposeResult `json:"result"`
|
||||
Result *osbuild.Result `json:"result"`
|
||||
}
|
||||
|
||||
type updateJobResponse struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue