From a85a77f4651e99821bea6d3fcc17ac276a13a329 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Wed, 29 Apr 2020 15:09:30 -0700 Subject: [PATCH 1/4] Cleanup --- internal/cmd/add.go | 6 +++--- internal/cmd/hosts_remove.go | 2 +- internal/cmd/import.go | 6 +++--- internal/cmd/remove.go | 4 ++-- internal/cmd/rename.go | 2 +- internal/cmd/root.go | 4 ++-- internal/cmd/xdebug.go | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/cmd/add.go b/internal/cmd/add.go index deb97002..80178729 100644 --- a/internal/cmd/add.go +++ b/internal/cmd/add.go @@ -16,7 +16,7 @@ import ( var addCommand = &cobra.Command{ Use: "add", - Short: "Add site to machine", + Short: "Add a site to a machine", RunE: func(cmd *cobra.Command, args []string) error { // load the config var configFile config.Config @@ -89,7 +89,7 @@ var addCommand = &cobra.Command{ skipSite := true site := config.Site{Hostname: hostname, Webroot: webRootPath} if configFile.SiteExists(site) { - fmt.Println(site.Hostname, "has already been set") + fmt.Println(site.Hostname, "has already been set.") } else { if err := configFile.AddSite(site); err != nil { return err @@ -116,7 +116,7 @@ var addCommand = &cobra.Command{ } if !applyChanges { - fmt.Println("You can apply new nitro.yaml changes later by running `nitro apply`.") + fmt.Println("You can apply new config file changes later by running `nitro apply`.") return nil } diff --git a/internal/cmd/hosts_remove.go b/internal/cmd/hosts_remove.go index 53de6604..c124185e 100644 --- a/internal/cmd/hosts_remove.go +++ b/internal/cmd/hosts_remove.go @@ -13,7 +13,7 @@ import ( var hostsRemoveCommand = &cobra.Command{ Use: "remove", - Short: "Remove an entry from your hosts file", + Short: "Remove a site from your hosts file", Hidden: true, Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/cmd/import.go b/internal/cmd/import.go index b91bda82..1f4a4971 100644 --- a/internal/cmd/import.go +++ b/internal/cmd/import.go @@ -20,7 +20,7 @@ import ( var importCommand = &cobra.Command{ Use: "import", - Short: "Import database into machine", + Short: "Import database into a machine", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { machine := flagMachineName @@ -59,7 +59,7 @@ var importCommand = &cobra.Command{ return errors.New("there are no databases that we can import the file into") } - containerName, _, err := prompt.Select(ui, "Select a database engine to import the file into", dbs[0], dbs) + containerName, _, err := prompt.Select(ui, "Select a database engine to import the backup into", dbs[0], dbs) databaseName, err := prompt.Ask(ui, "What is the database name?", "", true) if err != nil { @@ -95,7 +95,7 @@ var importCommand = &cobra.Command{ return err } - fmt.Println("Successfully imported the database file into", containerName) + fmt.Println("Successfully imported the database backup into", containerName) return nil }, diff --git a/internal/cmd/remove.go b/internal/cmd/remove.go index deacf82b..35a0cd8b 100644 --- a/internal/cmd/remove.go +++ b/internal/cmd/remove.go @@ -17,7 +17,7 @@ import ( var removeCommand = &cobra.Command{ Use: "remove", - Short: "Manage your nitro sites", + Short: "Remove site from a machine", RunE: func(cmd *cobra.Command, args []string) error { var configFile config.Config if err := viper.Unmarshal(&configFile); err != nil { @@ -91,7 +91,7 @@ var removeCommand = &cobra.Command{ } if applyChanges { - fmt.Println("Ok, applying changes from the config file...") + fmt.Println("Applying changes from the config file...") return applyCommand.RunE(cmd, args) } diff --git a/internal/cmd/rename.go b/internal/cmd/rename.go index 55f21c18..b0667ec6 100644 --- a/internal/cmd/rename.go +++ b/internal/cmd/rename.go @@ -69,7 +69,7 @@ var renameCommand = &cobra.Command{ } if applyChanges { - fmt.Println("Ok, applying changes from the config file...") + fmt.Println("Applying changes from the config file...") return applyCommand.RunE(cmd, args) } diff --git a/internal/cmd/root.go b/internal/cmd/root.go index dc91fe20..dc210dc9 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -19,8 +19,8 @@ func init() { cobra.OnInitialize(loadConfig) // set persistent flags on the root command - rootCmd.PersistentFlags().StringVarP(&flagMachineName, "machine", "m", "", "Name of the machine.") - rootCmd.PersistentFlags().BoolVarP(&flagDebug, "debug", "d", false, "Bypass executing the commands.") + rootCmd.PersistentFlags().StringVarP(&flagMachineName, "machine", "m", "", "Name of a machine.") + rootCmd.PersistentFlags().BoolVarP(&flagDebug, "debug", "d", false, "Show command output and do not execute.") // add commands to root rootCmd.AddCommand( diff --git a/internal/cmd/xdebug.go b/internal/cmd/xdebug.go index 36753284..308717c8 100644 --- a/internal/cmd/xdebug.go +++ b/internal/cmd/xdebug.go @@ -6,7 +6,7 @@ import ( var xdebugCommand = &cobra.Command{ Use: "xdebug", - Short: "Manage Xdebug on machine", + Short: "Manage Xdebug on a machine", RunE: func(cmd *cobra.Command, args []string) error { return cmd.Help() }, From c3480e4c4c390ced7aaf37a4edf4c8cab9d23568 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Wed, 29 Apr 2020 15:33:16 -0700 Subject: [PATCH 2/4] Clean up and add CPU core prompt in on init --- CHANGELOG.md | 3 +++ internal/cmd/init.go | 37 +++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a831b628..13b6042d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +## Changed +- The `init` command now prompts for how many CPU cores should be assigned to the machine. + ## 0.11.0 - 2020-04-29 ## Added diff --git a/internal/cmd/init.go b/internal/cmd/init.go index 9ee0633c..b2db193f 100644 --- a/internal/cmd/init.go +++ b/internal/cmd/init.go @@ -38,24 +38,23 @@ var initCommand = &cobra.Command{ // set the config file var cfg config.Config - // hardcode the CPUs until this issue is resolved - // https://github.com/craftcms/nitro/issues/65 - hardCodedCpus := "2" - cpuInt, err := strconv.Atoi(hardCodedCpus) + // TODO validate with https://golang.org/pkg/runtime/#NumCPU + // ask how many cores + cpuCores, err := prompt.Ask(ui, "How many CPU cores?", "2", true) if err != nil { return err } - cfg.CPUs = hardCodedCpus + cfg.CPUs = cpuCores // ask how much memory - memory, err := prompt.Ask(ui, "How much memory should we assign?", "4G", true) + memory, err := prompt.Ask(ui, "How much memory?", "4G", true) if err != nil { return err } cfg.Memory = memory // how much disk space - disk, err := prompt.Ask(ui, "How much disk space should the machine have?", "40G", true) + disk, err := prompt.Ask(ui, "How much disk space??", "40G", true) if err != nil { return err } @@ -63,7 +62,7 @@ var initCommand = &cobra.Command{ // which version of PHP if !existingConfig { - php, _, err := prompt.Select(ui, "Which version of PHP should we install?", "7.4", nitro.PHPVersions) + php, _, err := prompt.Select(ui, "Which version of PHP?", "7.4", nitro.PHPVersions) if err != nil { return err } @@ -79,7 +78,7 @@ var initCommand = &cobra.Command{ if !existingConfig { // what database engine? - engine, _, err := prompt.Select(ui, "Which database engine should we setup?", "mysql", nitro.DBEngines) + engine, _, err := prompt.Select(ui, "Which database engine?", "mysql", nitro.DBEngines) if err != nil { return err } @@ -87,7 +86,7 @@ var initCommand = &cobra.Command{ // which version should we use? versions := nitro.DBVersions[engine] defaultVersion := versions[0] - version, _, err := prompt.Select(ui, "Select a version of "+engine+" to use:", defaultVersion, versions) + version, _, err := prompt.Select(ui, "Select a version of "+engine+"?", defaultVersion, versions) if err != nil { return err } @@ -144,7 +143,13 @@ var initCommand = &cobra.Command{ } } - actions, err := createActions(machine, memory, disk, cpuInt, cfg.PHP, cfg.Databases, mounts, sites) + cpuCoresInt := 0 + cpuCoresInt, err = strconv.Atoi(cpuCores) + if err != nil { + return err + } + + actions, err := createActions(machine, memory, disk, cpuCoresInt, cfg.PHP, cfg.Databases, mounts, sites) if err != nil { return err } @@ -158,17 +163,17 @@ var initCommand = &cobra.Command{ return nil } - fmt.Println("Ok, applying the changes now") + fmt.Println("Applying the changes now...") return nitro.Run(nitro.NewMultipassRunner("multipass"), actions) }, } func init() { - // initCommand.Flags().IntVar(&flagCPUs, "cpus", 0, "Number of CPUs to allocate") - initCommand.Flags().StringVar(&flagMemory, "memory", "", "Amount of memory to allocate") - initCommand.Flags().StringVar(&flagDisk, "disk", "", "Amount of disk space to allocate") - initCommand.Flags().StringVar(&flagPhpVersion, "php-version", "", "Which version of PHP to make default") + initCommand.Flags().IntVar(&flagCPUs, "cpus", 0, "Number of CPU cores for machine") + initCommand.Flags().StringVar(&flagMemory, "memory", "", "Amount of memory for machine") + initCommand.Flags().StringVar(&flagDisk, "disk", "", "Amount of disk space for machine") + initCommand.Flags().StringVar(&flagPhpVersion, "php-version", "", "Version of PHP to make default") } func createActions(machine, memory, disk string, cpus int, phpVersion string, databases []config.Database, mounts []config.Mount, sites []config.Site) ([]nitro.Action, error) { From 1192109638bbdccf8b54ab8ad3ac50a1435ad1c6 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Wed, 29 Apr 2020 17:15:34 -0700 Subject: [PATCH 3/4] little less agressive on the polling --- internal/cmd/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/config.go b/internal/cmd/config.go index 884807d8..2cf367b5 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -60,7 +60,7 @@ write_files: fi if [ "$engine" == "mysql" ]; then - docker exec "$container" bash -c "while ! mysqladmin ping -h 127.0.0.1 -uroot -pnitro; do echo 'waiting...'; sleep 1; done" + docker exec "$container" bash -c "while ! mysqladmin ping -h 127.0.0.1 -uroot -pnitro; do echo 'waiting...'; sleep 3; done" docker exec "$container" mysql -uroot -pnitro -e "GRANT ALL ON *.* TO 'nitro'@'%';" docker exec "$container" mysql -uroot -pnitro -e "FLUSH PRIVILEGES;" echo "setting root permissions on user nitro" From cc46706a1ba6483001a83c83bb1e65a7b296d5ae Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Wed, 29 Apr 2020 17:17:45 -0700 Subject: [PATCH 4/4] 0.11.2 changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13b6042d..5c5db615 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Release Notes for Craft Nitro -## Unreleased +### Unreleased + +### 0.11.2 - 2020-04-09 ## Changed - The `init` command now prompts for how many CPU cores should be assigned to the machine. -## 0.11.0 - 2020-04-29 +### 0.11.0 - 2020-04-29 ## Added - Added the `rename` command to allow users to quickly rename sites.