Commit 06e199eb authored by Christopher Harm's avatar Christopher Harm

Adding defaults for CI build/deploy phases if no config exists

parent 6c68284e
Pipeline #29557 passed with stages
in 42 seconds
......@@ -15,6 +15,11 @@
package cmd
import (
"os"
"git.psu.edu/k8s/devtool/config"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
......@@ -50,3 +55,17 @@ func init() {
// is called directly, e.g.:
// configCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
func getCiConfiguration() config.Config {
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgRed).Printf("WARN: configuration file: %s doesn't exist, using defaults\n", configFile)
conf.Name = os.Getenv("CI_PROJECT_NAME")
deployable := config.Deployable{
Name: os.Getenv("CI_PROJECT_NAME"),
}
conf.Deployables = []config.Deployable{deployable}
}
return conf
}
......@@ -32,13 +32,9 @@ var ciBuildCmd = &cobra.Command{
Use: "build",
Short: "build the application within the CI system",
RunE: func(cmd *cobra.Command, args []string) error {
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgRed).Printf("Error reading configuration file: %s\n", configFile)
return err
}
conf := getCiConfiguration()
err = buildCiDocker(conf)
err := buildCiDocker(conf)
if err != nil {
color.Red("Failed to build docker image.")
return err
......
......@@ -28,13 +28,9 @@ var ciDeployCmd = &cobra.Command{
Use: "deploy",
Short: "deploy the application within the CI system",
RunE: func(cmd *cobra.Command, args []string) error {
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgRed).Printf("Error reading configuration file: %s\n", configFile)
return err
}
conf := getCiConfiguration()
err = fluxDeployCi(conf)
err := fluxDeployCi(conf)
if err != nil {
color.Red("Failed to build docker image.")
return err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment