From 70a8b0d1e5bc382307fa6552c0e4187fbf83cc48 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Sat, 2 Nov 2019 21:25:26 +0100 Subject: [PATCH] Ignore dot files and make command files executable, fixes #1822 (#1861) * Ignore dot files and make command files executable * Add info about command line endings to docs --- cmd/ddev/cmd/commands.go | 6 +++++- docs/users/extend/custom-commands.md | 1 + pkg/ddevapp/config.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/ddev/cmd/commands.go b/cmd/ddev/cmd/commands.go index 22891c624e8..1f8037ff96b 100644 --- a/cmd/ddev/cmd/commands.go +++ b/cmd/ddev/cmd/commands.go @@ -50,13 +50,17 @@ func addCustomCommands(rootCmd *cobra.Command) error { } for _, commandName := range commandFiles { - if strings.HasSuffix(commandName, ".example") || strings.HasPrefix(commandName, "README") { + if strings.HasSuffix(commandName, ".example") || strings.HasPrefix(commandName, "README") || strings.HasPrefix(commandName, ".") { continue } // Use path.Join() for the inContainerFullPath because it's about the path in the container, not on the // host; a Windows path is not useful here. inContainerFullPath := path.Join("/mnt/ddev_config/commands", service, commandName) onHostFullPath := filepath.Join(topCommandPath, service, commandName) + + // Any command we find will want to be executable on Linux + _ = os.Chmod(onHostFullPath, 0755) + description := findDirectiveInScript(onHostFullPath, "## Description") if description == "" { description = commandName diff --git a/docs/users/extend/custom-commands.md b/docs/users/extend/custom-commands.md index a54fc73a450..2b0c2710527 100644 --- a/docs/users/extend/custom-commands.md +++ b/docs/users/extend/custom-commands.md @@ -88,5 +88,6 @@ Useful variables for container scripts are: ## Known Windows OS issues +* **Line Endings**: If you are editing a custom command which will run in a container, it must have LF line endings (not traditional Windows CRLF line endings). Remember that a custom command in a container is a script that must execute in a Linux environmet. * If ddev can't find "bash" to execute it, then the commands can't be used. If you are running inside git-bash in most any terminal, this shouldn't be an issue, and ddev should be able to find git-bash if it's in "C:\Program Files\Git\bin" as well. But if neither of those is true, add the directory of bash.exe to your PATH environment variable. * If you're using Docker Toolbox, the IP address for things like `ddev mysql` is not 127.0.0.1, it's likely 192.168.99.100. diff --git a/pkg/ddevapp/config.go b/pkg/ddevapp/config.go index da66bd39f3e..85dd175b88a 100644 --- a/pkg/ddevapp/config.go +++ b/pkg/ddevapp/config.go @@ -908,7 +908,7 @@ func PrepDdevDirectory(dir string) error { } } - err := CreateGitIgnore(dir, "commands/*/*.example", "commands/*/README.txt", "homeadditions/*.example", "homeadditions/README.txt", "import.yaml", "docker-compose.yaml", "db_snapshots", "sequelpro.spf", "import-db", ".bgsync*", "config.*.y*ml", ".webimageBuild", ".dbimageBuild", ".bgsyncimageBuild", ".sshimageBuild", ".webimageExtra", ".dbimageExtra", "*-build/Dockerfile.example") + err := CreateGitIgnore(dir, "commands/*/*.example", "commands/*/README.txt", "commands/host/launch", "commands/db/mysql", "homeadditions/*.example", "homeadditions/README.txt", ".gitignore", "import.yaml", "docker-compose.yaml", "db_snapshots", "sequelpro.spf", "import-db", ".bgsync*", "config.*.y*ml", ".webimageBuild", ".dbimageBuild", ".bgsyncimageBuild", ".sshimageBuild", ".webimageExtra", ".dbimageExtra", "*-build/Dockerfile.example") if err != nil { return fmt.Errorf("failed to create gitignore in %s: %v", dir, err) }