Esempio n. 1
0
func NewCmdPull(f *cmdutil.Factory) *cobra.Command {
	cmd := &cobra.Command{
		Use:   "pull [templateNames]",
		Short: "Pulls the docker images for the given templates",
		Long:  `Performs a docker pull on all the docker images referenced in the given templates to preload the local docker registry with images`,
		PreRun: func(cmd *cobra.Command, args []string) {
			showBanner()
		},
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) < 1 {
				util.Error("No template names specified!")
				cmd.Usage()
			} else {
				_, cfg := client.NewClient(f)
				oc, _ := client.NewOpenShiftClient(cfg)
				ns, _, err := f.DefaultNamespace()
				if err != nil {
					util.Fatal("No default namespace")
				} else {
					for _, template := range args {
						util.Info("Downloading docker images for template ")
						util.Success(template)
						util.Info("\n\n")

						r, err := downloadTemplateDockerImages(cmd, ns, oc, f, template)
						printResult("Download Docker images", r, err)
					}
				}
			}
		},
	}
	return cmd
}
Esempio n. 2
0
// lets find the executable on the PATH or in the fabric8 directory
func resolveBinaryLocation(executable string) string {
	path, err := exec.LookPath(executable)
	if err != nil || fileNotExist(path) {
		home := os.Getenv("HOME")
		if home == "" {
			util.Error("No $HOME environment variable found")
		}
		writeFileLocation := getFabric8BinLocation()

		// lets try in the fabric8 folder
		path = filepath.Join(writeFileLocation, executable)
		if fileNotExist(path) {
			path = executable
			// lets try in the folder where we found the gofabric8 executable
			folder, err := osext.ExecutableFolder()
			if err != nil {
				util.Errorf("Failed to find executable folder: %v\n", err)
			} else {
				path = filepath.Join(folder, executable)
				if fileNotExist(path) {
					util.Infof("Could not find executable at %v\n", path)
					path = executable
				}
			}
		}
	}
	util.Infof("using the executable %s\n", path)
	return path
}
Esempio n. 3
0
func NewClient(f *cmdutil.Factory) (*client.Client, *restclient.Config) {
	var err error
	cfg, err := f.ClientConfig()
	if err != nil {
		util.Error("Could not initialise a client - is your server setting correct?\n\n")
		util.Fatalf("%v", err)
	}
	c, err := client.New(cfg)
	if err != nil {
		util.Fatalf("Could not initialise a client: %v", err)
	}

	return c, cfg
}
Esempio n. 4
0
// NewCmdInstall installs the dependencies to run the fabric8 microservices platform
func NewCmdInstall(f *cmdutil.Factory) *cobra.Command {
	cmd := &cobra.Command{
		Use:   "install",
		Short: "Installs the dependencies to locally run the fabric8 microservices platform",
		Long:  `Installs the dependencies to locally run the fabric8 microservices platform`,

		Run: func(cmd *cobra.Command, args []string) {

			if runtime.GOOS == "windows" {
				util.Errorf("%s is not yet supported by gofabric8 install", runtime.GOOS)
			}

			isMinishift := cmd.Flags().Lookup(minishiftFlag).Value.String() == "true"

			home := os.Getenv("HOME")
			if home == "" {
				util.Error("No $HOME environment variable found")
			}
			writeFileLocation = home + binLocation

			err := os.MkdirAll(writeFileLocation, 0700)
			if err != nil {
				util.Errorf("Unable to create directory to download files %s %v\n", writeFileLocation, err)
			}

			err = downloadDriver()
			if err != nil {
				util.Warnf("Unable to download driver %v\n", err)
			}

			err = downloadKubernetes(isMinishift)
			if err != nil {
				util.Warnf("Unable to download kubernetes distro %v\n", err)
			}

			err = downloadClient(isMinishift)
			if err != nil {
				util.Warnf("Unable to download client %v\n", err)
			}

		},
	}
	cmd.PersistentFlags().Bool(minishiftFlag, false, "Install minishift rather than minikube")
	return cmd
}
Esempio n. 5
0
func printStatus(exitStatus int) {
	if exitStatus != 0 {
		util.Error(fmt.Sprintf("%d", exitStatus))
	}
}