Skip to content

Commit

Permalink
Issue minishift#2469 Break up copy the oc binary and pulling the image
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumar authored and LalatenduMohanty committed Jun 29, 2018
1 parent 81c6e08 commit 4bf03ab
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
11 changes: 3 additions & 8 deletions cmd/minishift/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,13 @@ func runStart(cmd *cobra.Command, args []string) {
fmt.Println("-- OpenShift cluster will be configured with ...")
fmt.Println(" Version:", requestedOpenShiftVersion)

fmt.Printf("-- Copying oc binary from the OpenShift container image to VM ")
progressDots := progressdots.New()
progressDots.Start()
err = clusterup.CopyOcBinaryFromImageToVM(dockerCommander, minishiftConstants.GetOpenshiftImageName(requestedOpenShiftVersion), minishiftConstants.OcPathInsideVM)
err := cmdUtil.PullOpenshiftImageAndCopyOcBinary(dockerCommander, requestedOpenShiftVersion)
if err != nil {
atexit.ExitWithMessage(1, fmt.Sprintf("Error copying the oc binary to %s: %v", minishiftConstants.OcPathInsideVM, err))
atexit.ExitWithMessage(1, err.Error())
}
progressDots.Stop()
fmt.Println(" OK")

fmt.Printf("-- Starting OpenShift cluster ")
progressDots = progressdots.New()
progressDots := progressdots.New()
progressDots.Start()
out, err := clusterup.ClusterUp(clusterUpConfig, clusterUpParams)
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions cmd/minishift/cmd/util/oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ import (
"github.com/minishift/minishift/cmd/minishift/state"
"github.com/minishift/minishift/pkg/minikube/constants"
"github.com/minishift/minishift/pkg/minishift/cache"
"github.com/minishift/minishift/pkg/minishift/clusterup"
minishiftConfig "github.com/minishift/minishift/pkg/minishift/config"
minishiftConstants "github.com/minishift/minishift/pkg/minishift/constants"
"github.com/minishift/minishift/pkg/minishift/docker"
"github.com/minishift/minishift/pkg/minishift/oc"
profileActions "github.com/minishift/minishift/pkg/minishift/profile"
utils "github.com/minishift/minishift/pkg/util"
"github.com/minishift/minishift/pkg/util/os/atexit"
"github.com/minishift/minishift/pkg/util/progressdots"
)

// CacheOc ensures that the oc binary matching the requested OpenShift version is cached on the host
Expand Down Expand Up @@ -143,3 +146,30 @@ func GetOcPathForProfile(profileName string) (error, string) {
}
return nil, instanceCfg.OcPath
}

// PullOpenshiftImageAndCopyOcBinary pull the openshift image if not available and then copy the client binary to Remote/VM machine
// Any occurring error is also returned.
func PullOpenshiftImageAndCopyOcBinary(dockerCommander docker.DockerCommander, requestedOpenShiftVersion string) error {
fmt.Printf("-- Pulling the Openshift Container Image ")
progressDots := progressdots.New()
progressDots.Start()
// We need to make sure if images are already exist from the cache then don't pull it again.
imageExist, err := dockerCommander.IsImageExist(minishiftConstants.GetOpenshiftImageName(requestedOpenShiftVersion))
if !imageExist {
_, err = dockerCommander.Pull(minishiftConstants.GetOpenshiftImageName(requestedOpenShiftVersion))
if err != nil {
return fmt.Errorf("Error pulling the openshift container image: %v", err)
}
progressDots.Stop()
fmt.Println(" OK")
} else {
fmt.Println(" EXISTS")
}
fmt.Printf("-- Copying oc binary from the OpenShift container image to VM ...")
err = clusterup.CopyOcBinaryFromImageToVM(dockerCommander, minishiftConstants.GetOpenshiftImageName(requestedOpenShiftVersion), minishiftConstants.OcPathInsideVM)
if err != nil {
return fmt.Errorf("Error copying the oc binary to %s: %v", minishiftConstants.OcPathInsideVM, err)
}
fmt.Println(" OK")
return nil
}
28 changes: 28 additions & 0 deletions pkg/minishift/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type DockerCommander interface {
// and exited. See also https://docs.docker.com/engine/api/v1.21/
Status(container string) (string, error)

// Pull the specified container image. Returns output in case the run was successful.
// Any occurring error is also returned.
Pull(image string) (string, error)

// Runs the specified container. Returns true in case the run was successful, false otherwise.
// Any occurring error is also returned.
Run(options string, container string) (bool, error)
Expand Down Expand Up @@ -75,6 +79,10 @@ type DockerCommander interface {
// command and arguments. The output of the command is returned as well as any occurring error.
Exec(options string, container string, command string, args string) (string, error)

// IsImageExist provide a bool value if an image exist.
// Any occurring error is also returned.
IsImageExist(image string) (bool, error)

// LocalExec runs the specified command on the Docker host
LocalExec(cmd string) (string, error)
}
Expand Down Expand Up @@ -234,3 +242,23 @@ func (c VmDockerCommander) GetID(container string) (string, error) {
out = strings.TrimSpace(out)
return out, err
}

func (c VmDockerCommander) Pull(image string) (string, error) {
cmd := fmt.Sprintf("docker pull %s", image)
c.logCommand(cmd)
out, err := c.commander.SSHCommand(cmd)
out = strings.TrimSpace(out)
return out, err
}

func (c VmDockerCommander) IsImageExist(image string) (bool, error) {
cmd := fmt.Sprintf("docker images -q %s", image)
var exist bool
c.logCommand(cmd)
out, err := c.commander.SSHCommand(cmd)
out = strings.TrimSpace(out)
if out != "" {
exist = true
}
return exist, err
}

0 comments on commit 4bf03ab

Please sign in to comment.