Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
hope I didn't break anything
Browse files Browse the repository at this point in the history
  • Loading branch information
christianh814 committed Nov 3, 2020
1 parent 28ef7fc commit a80711b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -93,4 +94,3 @@ func pullImages(){
utils.PullImage(v, "latest")
}
}

26 changes: 25 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
},
}

Expand All @@ -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)
}
}
}
16 changes: 14 additions & 2 deletions utils/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
}

//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)
}

}

0 comments on commit a80711b

Please sign in to comment.