diff --git a/cmd/init.go b/cmd/init.go index 46aab28..09e3f1e 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -31,12 +31,13 @@ var pxe string = "quay.io/helpernode/pxe" // A map value containing some key-value pairs. -var images= map[string]string{ +var images = map[string]string{ "dns": "quay.io/helpernode/dns", "dhcp": "quay.io/helpernode/dhcp", "http": "quay.io/helpernode/http", "loadbalancer": "quay.io/helpernode/loadbalancer", - "pxe": "quay.io/helpernode/pxe"} + "pxe": "quay.io/helpernode/pxe", + } // initCmd represents the init command var initCmd = &cobra.Command{ @@ -93,4 +94,3 @@ func pullImages(){ utils.PullImage(v, "latest") } } - diff --git a/cmd/start.go b/cmd/start.go index 8909a4f..96a7073 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -17,8 +17,12 @@ package cmd import ( "fmt" - "github.com/spf13/cobra" + "github.com/robertsandoval/ocp4-helpernode/utils" + "os" + "bufio" + "encoding/base64" + "io/ioutil" ) // startCmd represents the start command @@ -33,6 +37,7 @@ This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("start called") + runContianers() }, } @@ -49,3 +54,22 @@ func init() { // is called directly, e.g.: // startCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } + +func runContianers() { + // Check to see if file exists + if _, err := os.Stat(cfgFile); os.IsNotExist(err) { + fmt.Println("File " + cfgFile + " does not exist") + } else { + // Open file on disk + f, _ := os.Open(cfgFile) + // Read file into a byte slice + reader := bufio.NewReader(f) + content, _ := ioutil.ReadAll(reader) + //Encode to base64 + encoded := base64.StdEncoding.EncodeToString(content) + // run the containers using the encoding + for k, v := range images { + utils.StartImage(v, "latest", encoded, k) + } + } +} diff --git a/utils/container.go b/utils/container.go index 55948f1..9619e3a 100644 --- a/utils/container.go +++ b/utils/container.go @@ -17,8 +17,20 @@ func PullImage(image string, version string){ //TODO Need to write the output for the image pull cmd, err := exec.Command(containerRuntime, "pull", image + ":" + version).Output() if err != nil { - fmt.Println("here") fmt.Println(cmd) } -} \ No newline at end of file +} + +//going to covert this to use the podman module in the future +func StartImage(image string, version string, encodedyaml string, containername string){ + + fmt.Println("Running: " + image) + //TODO Need to write the output for the image run + cmd, err := exec.Command(containerRuntime, "run", "-d", "--env=HELPERPOD_CONFIG_YAML=" + encodedyaml, "--net=host", "--name=helpernode-" + containername, image + ":" + version).Output() + if err != nil { + fmt.Println(err) + fmt.Println(cmd) + } + +}