diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e7a9796..dcec307f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,21 @@ # Release Notes for Craft Nitro +## 2.0.6 - 2021-03-17 + +### Fixed +- Fixed an error where `initset` was not updating opcache settings. [#298](https://github.com/craftcms/nitro/issues/298) +- Fixed an error preventing Linux users from using Xdebug. [#288](https://github.com/docker/for-linux/issues/288) +- Fixed a display error for Windows users when using the `trust` command. [#291](https://github.com/craftcms/nitro/issues/291) +- Fixed a bug where command completion was not working in a zsh shell. [#295](https://github.com/craftcms/nitro/issues/295) + ## 2.0.5 - 2021-03-09 ### Added -- Added the `php` command to execute PHP commands in a site container [#276](https://github.com/craftcms/nitro/issues/276). +- Added the `php` command to execute PHP commands in a site container. [#276](https://github.com/craftcms/nitro/issues/276) ### Fixed -- Fixed an error where mysql permissions were not being set properly [#275](https://github.com/craftcms/nitro/issues/275). -- Fixed an error that could occur when paths included spaces [#277](https://github.com/craftcms/nitro/issues/277). +- Fixed an error where mysql permissions were not being set properly. [#275](https://github.com/craftcms/nitro/issues/275) +- Fixed an error that could occur when paths included spaces. [#277](https://github.com/craftcms/nitro/issues/277) - Fixed certificate installations for POP!_OS Linux. ## 2.0.4 - 2021-03-04 @@ -16,13 +24,13 @@ - Nitro will now verify and start containers if not running. ### Fixed -- Fixed an error that could occur when running `version` before `init` [#270](https://github.com/craftcms/nitro/issues/270). -- Fixed an error that could occur when Nitro is unable to detect the database engine from a backup [#269](https://github.com/craftcms/nitro/issues/269). +- Fixed an error that could occur when running `version` before `init`. [#270](https://github.com/craftcms/nitro/issues/270) +- Fixed an error that could occur when Nitro is unable to detect the database engine from a backup. [#269](https://github.com/craftcms/nitro/issues/269) ## 2.0.3 - 2021-03-03 ### Fixed -- Fixed a bug where the `iniset` command was not updating PHP settings for sites [#268](https://github.com/craftcms/nitro/issues/268). +- Fixed a bug where the `iniset` command was not updating PHP settings for sites. [#268](https://github.com/craftcms/nitro/issues/268) ## 2.0.2 - 2021-03-02 diff --git a/Makefile b/Makefile index b7f1b948..08137951 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: docker docs -VERSION ?= 2.0.4 +VERSION ?= 2.0.6 build: go build -trimpath -ldflags="-s -w -X 'github.com/craftcms/nitro/command/version.Version=${VERSION}'" -o nitro ./cmd/nitro diff --git a/command/apply/internal/match/match.go b/command/apply/internal/match/match.go index 3b8e40e5..4399336d 100644 --- a/command/apply/internal/match/match.go +++ b/command/apply/internal/match/match.go @@ -161,7 +161,7 @@ func checkEnvs(site config.Site, blackfire config.Blackfire, envs []string) bool return false } case "PHP_OPCACHE_ENABLE": - if site.PHP.OpcacheEnable && val == config.DefaultEnvs[env] { + if (site.PHP.OpcacheEnable && val == config.DefaultEnvs[env]) || (!site.PHP.OpcacheEnable && val != config.DefaultEnvs[env]) { return false } case "PHP_OPCACHE_REVALIDATE_FREQ": diff --git a/command/apply/internal/match/match_test.go b/command/apply/internal/match/match_test.go index 0c6ce5f0..523a2cf7 100644 --- a/command/apply/internal/match/match_test.go +++ b/command/apply/internal/match/match_test.go @@ -116,6 +116,20 @@ func Test_checkEnvs(t *testing.T) { }, want: false, }, + { + name: "opcache_disable returns false", + args: args{ + site: config.Site{ + PHP: config.PHP{ + OpcacheEnable: false, + }, + }, + envs: []string{ + "PHP_OPCACHE_ENABLE=1", + }, + }, + want: false, + }, { name: "opcache_enable returns false", args: args{ diff --git a/command/apply/internal/sitecontainer/sitecontainer.go b/command/apply/internal/sitecontainer/sitecontainer.go index acaccab2..3f831dc9 100644 --- a/command/apply/internal/sitecontainer/sitecontainer.go +++ b/command/apply/internal/sitecontainer/sitecontainer.go @@ -5,12 +5,14 @@ import ( "context" "fmt" "os" + "runtime" "strings" "github.com/craftcms/nitro/command/apply/internal/match" "github.com/craftcms/nitro/command/apply/internal/nginx" "github.com/craftcms/nitro/pkg/config" "github.com/craftcms/nitro/pkg/containerlabels" + "github.com/craftcms/nitro/pkg/wsl" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" @@ -109,6 +111,11 @@ func create(ctx context.Context, docker client.CommonAPIClient, home, networkID extraHosts = append(extraHosts, fmt.Sprintf("%s:%s", s, "127.0.0.1")) } + // check if this is linux specific + if runtime.GOOS == "linux" && !wsl.IsWSL() { + extraHosts = append(extraHosts, fmt.Sprintf("%s:%s", "host.docker.internal", "host-gateway")) + } + // get the sites environment variables envs := site.AsEnvs("host.docker.internal") diff --git a/command/completion/bash.go b/command/completion/bash.go deleted file mode 100644 index df1bc29c..00000000 --- a/command/completion/bash.go +++ /dev/null @@ -1,34 +0,0 @@ -package completion - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" -) - -// bashCompletionCommand represents the completion command -var bashCompletionCommand = &cobra.Command{ - Use: "bash", - Short: "Generates bash completion scripts", - Long: `To load completion run - -Bash: - -$ source <(nitro completion bash) - -# To load completions for each session, execute once: -Linux: - $ nitro completion bash > /etc/bash_completion.d/nitro -MacOS: - $ nitro completion bash > /usr/local/etc/bash_completion.d/nitro - -# You will need to start a new shell for this setup to take effect. -`, - Run: func(cmd *cobra.Command, args []string) { - err := cmd.Parent().Parent().GenBashCompletion(os.Stdout) - if err != nil { - fmt.Println(err) - } - }, -} diff --git a/command/completion/completion.go b/command/completion/completion.go index 69c0c2b5..388c4cc6 100644 --- a/command/completion/completion.go +++ b/command/completion/completion.go @@ -2,15 +2,11 @@ package completion import ( "fmt" + "os" "github.com/spf13/cobra" ) -var ( - // ErrExample is used when we want to share an error - ErrExample = fmt.Errorf("not implemented") -) - const exampleText = `To load completions: Bash: @@ -36,18 +32,29 @@ $ nitro completion zsh > "${fpath[1]}/_nitro" # You will need to start a new shell for this setup to take effect. ` -// New is used for scaffolding new commands -func New() *cobra.Command { +// NewCommand returns the command used for generating completion shells +func NewCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "completion", - Short: "Enable shell completion", - Example: exampleText, + Use: "completion", + Short: "Enable shell completion", + ValidArgs: []string{"bash", "zsh"}, + Example: exampleText, RunE: func(cmd *cobra.Command, args []string) error { - return cmd.Help() + // print the help if not defined + if len(args) == 0 { + return cmd.Help() + } + + switch args[0] { + case "zsh": + return cmd.Root().GenZshCompletion(os.Stdout) + case "bash": + return cmd.Root().GenBashCompletion(os.Stdout) + } + + return fmt.Errorf("unknown shell requested") }, } - cmd.AddCommand(bashCompletionCommand, zshCompletionCommand) - return cmd } diff --git a/command/completion/zsh.go b/command/completion/zsh.go deleted file mode 100644 index 81f9e3aa..00000000 --- a/command/completion/zsh.go +++ /dev/null @@ -1,32 +0,0 @@ -package completion - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" -) - -// zshCompletionCommand represents the completion command for zsh -var zshCompletionCommand = &cobra.Command{ - Use: "zsh", - Short: "Generates zsh completion scripts", - Long: `To load zsh completion: - -# If shell completion is not already enabled in your environment you will need -# to enable it. You can execute the following once: - -$ echo "autoload -U compinit; compinit" >> ~/.zshrc - -# To load completions for each session, execute once: -$ nitro complete zsh > "${fpath[1]}/_nitro" - -# You will need to start a new shell for this setup to take effect. -`, - Run: func(cmd *cobra.Command, args []string) { - err := cmd.GenZshCompletion(os.Stdout) - if err != nil { - fmt.Println(err) - } - }, -} diff --git a/command/nitro/nitro.go b/command/nitro/nitro.go index acf440ea..074080b8 100644 --- a/command/nitro/nitro.go +++ b/command/nitro/nitro.go @@ -79,11 +79,6 @@ func NewCommand() *cobra.Command { log.Fatal(err) } - // if _, err := docker.Ping(contextpkg.Background()); err != nil { - // fmt.Println("Unable to talk to Docker, it appears it is not running…") - // os.Exit(2) - // } - // get the port for the nitrod API apiPort := "5000" if os.Getenv("NITRO_API_PORT") != "" { @@ -110,7 +105,7 @@ func NewCommand() *cobra.Command { blackfire.NewCommand(home, docker, term), bridge.NewCommand(home, docker, term), clean.NewCommand(home, docker, term), - completion.New(), + completion.NewCommand(), composer.NewCommand(docker, term), container.NewCommand(home, docker, term), context.NewCommand(home, docker, term), diff --git a/pkg/certinstall/certinstall.go b/pkg/certinstall/certinstall.go index 2c0c1bc7..56781c03 100644 --- a/pkg/certinstall/certinstall.go +++ b/pkg/certinstall/certinstall.go @@ -48,7 +48,7 @@ func Install(file, system string) error { } // find the linux distro - dist, err := findDistro(buf.String()) + dist, err := identify(buf.String()) if err != nil { return err } @@ -78,7 +78,7 @@ func Install(file, system string) error { if dist, exists := os.LookupEnv("WSL_DISTRO_NAME"); exists { user := os.Getenv("USER") fmt.Println("Users on WSL will need to open an elevated (run as administrator) Command Prompt or terminal on Windows and run the following command:") - fmt.Printf(`certutil -addstore -f "Root" \\wsl$\%s\home\%s\.nitro\nitro.crt\n`, dist, user) + fmt.Println(fmt.Printf(`certutil -addstore -f "Root" \\wsl$\%s\home\%s\.nitro\nitro.crt`, dist, user)) } default: // add the certificate to the macOS keychain @@ -90,14 +90,14 @@ func Install(file, system string) error { return nil } -func findDistro(description string) (string, error) { +func identify(description string) (string, error) { // detect arch systems if strings.Contains(description, "Manjaro") || strings.Contains(description, "Arch Linux") { return "arch", nil } // detect debian systems - if strings.Contains(description, "Ubuntu") || strings.Contains(description, "Pop!_OS") { + if strings.Contains(description, "Ubuntu") || strings.Contains(description, "Pop!_OS") || strings.Contains(description, "Mint") { return "debian", nil } diff --git a/pkg/config/config.go b/pkg/config/config.go index 0b938424..040a68d3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -236,17 +236,10 @@ func (s *Site) GetContainerPath() string { func (s *Site) AsEnvs(addr string) []string { var envs []string - if addr == "" { - addr = "host.docker.internal" - } - // set the php vars envs = append(envs, phpVars(s.PHP, s.Version)...) - // get the xdebug vars - envs = append(envs, xdebugVars(s.PHP, s.Xdebug, s.Version, s.Hostname, addr)...) - - return envs + return append(envs, xdebugVars(s.PHP, s.Xdebug, s.Version, s.Hostname, addr)...) } // SetPHPBoolSetting is used to set php settings that are bool. It will look