Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.11.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybrad committed Apr 30, 2020
2 parents d2d0a30 + cc46706 commit 3c1adae
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 32 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Release Notes for Craft Nitro

## Unreleased
### Unreleased

## 0.11.0 - 2020-04-29
### 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

## Added
- Added the `rename` command to allow users to quickly rename sites.
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/hosts_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
},
Expand Down
37 changes: 21 additions & 16 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,31 @@ 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
}
cfg.Disk = disk

// 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
}
Expand All @@ -79,15 +78,15 @@ 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
}

// 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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/xdebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand Down

0 comments on commit 3c1adae

Please sign in to comment.