Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plume: add cosa2stream #2000

Merged
merged 9 commits into from
Jan 20, 2021
90 changes: 90 additions & 0 deletions mantle/cmd/plume/cosa2stream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"time"

"github.com/coreos/stream-metadata-go/release"
"github.com/coreos/stream-metadata-go/stream"
"github.com/spf13/cobra"
)

var (
cmdCosaBuildToStream = &cobra.Command{
Use: "cosa2stream [options]",
Short: "Generate stream JSON from a coreos-assembler build",
RunE: runCosaBuildToStream,

SilenceUsage: true,
}

streamBaseURL string
streamName string
)

func init() {
cmdCosaBuildToStream.Flags().StringVar(&streamBaseURL, "url", "", "Base URL for build")
cmdCosaBuildToStream.Flags().StringVar(&streamName, "name", "", "Stream name")
cmdCosaBuildToStream.MarkFlagRequired("name")
root.AddCommand(cmdCosaBuildToStream)
}

func runCosaBuildToStream(cmd *cobra.Command, args []string) error {
releaseTmpf, err := ioutil.TempFile("", "release")
if err != nil {
return err
}
childArgs := []string{"generate-release-meta", "--stream-name=" + streamName, "--output=" + releaseTmpf.Name()}
if streamBaseURL != "" {
childArgs = append(childArgs, "--stream-baseurl="+streamBaseURL)
}
for _, arg := range args {
childArgs = append(childArgs, fmt.Sprintf("--url="+arg))
}
c := exec.Command("cosa", childArgs...)
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
return err
}

var rel release.Release
buf, err := ioutil.ReadAll(releaseTmpf)
if err != nil {
return err
}
if err := json.Unmarshal(buf, &rel); err != nil {
return err
}

// Generate output stream from release
outStream := stream.Stream{
Stream: streamName,
Metadata: stream.Metadata{LastModified: time.Now().UTC().Format(time.RFC3339)},
Architectures: rel.ToStreamArchitectures(),
}

// Serialize to JSON
encoder := json.NewEncoder(os.Stdout)
if err := encoder.Encode(&outStream); err != nil {
return fmt.Errorf("Error while encoding: %v", err)
}
return nil
}
2 changes: 1 addition & 1 deletion mantle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/coreos/ignition/v2 v2.9.0
github.com/coreos/ioprogress v0.0.0-20151023204047-4637e494fd9b
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
github.com/coreos/stream-metadata-go v0.0.0-20210107232620-d808ce9d237c
github.com/coreos/stream-metadata-go v0.0.0-20210115160721-ba77d4e64952
github.com/digitalocean/go-libvirt v0.0.0-20200810224808-b9c702499bf7 // indirect
github.com/digitalocean/go-qemu v0.0.0-20200529005954-1b453d036a9c
github.com/digitalocean/godo v1.33.0
Expand Down
3 changes: 3 additions & 0 deletions mantle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbp
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/stream-metadata-go v0.0.0-20210107232620-d808ce9d237c h1:7VO10dpKljeaYJUQtObhqjNxpuTCUDELTviJsGy9OeM=
github.com/coreos/stream-metadata-go v0.0.0-20210107232620-d808ce9d237c/go.mod h1:RTjQyHgO/G37oJ3qnqYK6Z4TPZ5EsaabOtfMjVXmgko=
github.com/coreos/stream-metadata-go v0.0.0-20210112152733-52b38c241a3d h1:a65dhEcT+kL9Bf5pDpdoOMdT5w0VjwUXE+XO2MoFuSg=
github.com/coreos/stream-metadata-go v0.0.0-20210115160721-ba77d4e64952 h1:t7IgMcyflINfXWPISnHTXwa/F+NxLgWGRGejoyfHUII=
github.com/coreos/stream-metadata-go v0.0.0-20210115160721-ba77d4e64952/go.mod h1:RTjQyHgO/G37oJ3qnqYK6Z4TPZ5EsaabOtfMjVXmgko=
github.com/coreos/vcontext v0.0.0-20190529201340-22b159166068 h1:y2aHj7QqyAJ6YBBONTAr17YxHHiogDkYnTsJvFNhxwY=
github.com/coreos/vcontext v0.0.0-20190529201340-22b159166068/go.mod h1:E+6hug9bFSe0KZ2ZAzr8M9F5JlArJjv5D1JS7KSkPKE=
github.com/coreos/vcontext v0.0.0-20201120045928-b0e13dab675c h1:jA28WeORitsxGFVWhyWB06sAG2HbLHPQuHwDydhU2CQ=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading