spud/cli/build.go

44 lines
984 B
Go
Raw Normal View History

package cli
import (
"fmt"
"github.com/spf13/cobra"
"log"
podman "spud/podman"
service_definition "spud/service_definition"
)
func getBuildCommand() *cobra.Command {
build := &cobra.Command{
Use: "build",
Short: "Build service images.",
RunE: func(cmd *cobra.Command, args []string) error {
pathProvided, err := cmd.PersistentFlags().GetString("definition")
if err != nil {
return fmt.Errorf("%+v", err)
}
def, err := service_definition.NewDefinitionFetcher().GetDefinition(pathProvided)
if err != nil {
return fmt.Errorf("Failed to read service definition from file: %+v", err)
}
imagesToBuild := def.Build.Images
if len(imagesToBuild) == 0 {
log.Print("No images defined - nothing to build!")
}
for _, imageDef := range imagesToBuild {
podman.Build(imageDef)
}
return nil
},
}
build.PersistentFlags().StringP("definition", "d", "./service.yml", "Path to the service definition to use.")
return build
}