Skip to content

Commit

Permalink
Basic building with WIndows for ddev#196 (ddev#209)
Browse files Browse the repository at this point in the history
* Basic building with WIndows

* Improve error message when creating docker network

* Should not prepare directories when we already have .ddev and an app configured

* Don't try to add to hosts file if no sudo available

* Support docker TLSClient, not just http client

* circle: Build windows by default, provide as artifact

* Move prepLocalSiteDirs() to local in config, check error

* Minor fixup after multi-compose PR went in

* Remove assertion that is not valid now that .ddev and subdirs are created in config

* Use actual docker ip instead of just assuming localhost

* Improve prepLocalSiteDirs() so not dependent on text content of error

* Remove assertion of site directory existence because config creation makes it now

* Use filepath instead of path for getting base filename in importdb

* Improve host parsing out of tcp://192.168.99.100:2376

* Update to use filepath instead of path everywhere

* use NewClientFromEnv to return client

* update exec help to use double quotes around cmd vs single
  • Loading branch information
rfay authored May 11, 2017
1 parent 3ca5586 commit 8f10148
Show file tree
Hide file tree
Showing 59 changed files with 8,341 additions and 98 deletions.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- checkout

- run:
command: make linux
command: make linux darwin windows
name: Build the linux ddev executable binary

# Run the built-in ddev tests
Expand Down Expand Up @@ -83,3 +83,7 @@ jobs:
path: bin/linux/ddev
destination: linux/ddev
name: Upload ddev (linux)
- store_artifacts:
path: bin/windows/windows_amd64/ddev.exe
destination: windows/ddev.exe
name: Upload ddev (windows)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.push*
/linux
/darwin
/windows
/.dockerfile
/VERSION.txt
/.docker_image
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ All of the commands can be performed by explicitly specifying the sitename or, t
To view information about a specific site (such as URL, MySQL credentials, mailhog credentials), run `ddev describe` from within the working directory of the site. To view information for any site, use `ddev describe sitename`.

### Executing Commands
To run a command against your site use `ddev exec`. e.g. `ddev exec 'drush core-status'` would execute `drush core-status` against your site root. Commands ran in this way are executed in the webserver docroot. You are free to use any of [the tools included in the container](#tools-included-in-the-container).
To run a command against your site use `ddev exec`. e.g. `ddev exec "drush core-status"` would execute `drush core-status` against your site root. Commands ran in this way are executed in the webserver docroot. You are free to use any of [the tools included in the container](#tools-included-in-the-container).

### SSH Into The Container
The `ddev ssh` command will open a bash shell session to the web container of your site. You can also access the database container with `ddev ssh -s db`.
Expand Down
4 changes: 2 additions & 2 deletions cmd/ddev/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// LocalDevExecCmd allows users to execute arbitrary bash commands within a container.
var LocalDevExecCmd = &cobra.Command{
Use: "exec '[cmd]'",
Use: "exec \"[cmd]\"",
Short: "Execute a Linux shell command in the webserver container.",
Long: `Execute a Linux shell command in the webserver container.`,
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -41,7 +41,7 @@ var LocalDevExecCmd = &cobra.Command{
},
PreRun: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatalf("Invalid arguments detected. Please use a command in the form of `ddev exec '[cmd]'`")
log.Fatalf("Invalid arguments detected. Please use a command in the form of `ddev exec \"[cmd]\"`")
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/ddev/cmd/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"log"
"path"
"path/filepath"
"testing"

"github.com/drud/drud-go/utils/system"
Expand All @@ -19,7 +19,7 @@ func TestImportTilde(t *testing.T) {

usr, err := homedir.Dir()
assert.NoError(err)
err = system.DownloadFile(path.Join(usr, "files.tar.gz"), site.FileURL)
err = system.DownloadFile(filepath.Join(usr, "files.tar.gz"), site.FileURL)
assert.NoError(err)

// this ~ should be expanded by shell
Expand Down
4 changes: 2 additions & 2 deletions cmd/ddev/cmd/logs_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"path"
"path/filepath"
"testing"

"os"
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestDevLogs(t *testing.T) {
cleanup := v.Chdir()

confByte := []byte("<?php trigger_error(\"Fatal error\", E_USER_ERROR);")
err := ioutil.WriteFile(path.Join(v.Dir, "docroot", "index.php"), confByte, 0644)
err := ioutil.WriteFile(filepath.Join(v.Dir, "docroot", "index.php"), confByte, 0644)
assert.NoError(err)

o := network.NewHTTPOptions("http://127.0.0.1/index.php")
Expand Down
4 changes: 2 additions & 2 deletions cmd/ddev/cmd/sequelpro.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"

"runtime"

Expand Down Expand Up @@ -51,7 +51,7 @@ func handleSequelProCommand(appLocation string) (string, error) {

dbPort := appports.GetPort("db")

tmpFilePath := path.Join(app.AppRoot(), ".ddev/sequelpro.spf")
tmpFilePath := filepath.Join(app.AppRoot(), ".ddev/sequelpro.spf")
tmpFile, err := os.Create(tmpFilePath)
if err != nil {
log.Fatalln(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ddev/cmd/sequelpro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"testing"

"path"
"path/filepath"

"github.com/drud/ddev/pkg/testcommon"
"github.com/drud/drud-go/utils/system"
Expand All @@ -28,7 +28,7 @@ func TestSequelproOperation(t *testing.T) {

dir, err := getActiveAppRoot()
assert.NoError(err)
assert.Equal(true, system.FileExists(path.Join(dir, ".ddev/sequelpro.spf")))
assert.Equal(true, system.FileExists(filepath.Join(dir, ".ddev/sequelpro.spf")))

cleanup()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ddev/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var StartCmd = &cobra.Command{

err := util.EnsureNetwork(client, netName)
if err != nil {
log.Fatal(err)
log.Fatalf("Unable to create/ensure docker network %s, error: %v", netName, err)
}

},
Expand Down
8 changes: 4 additions & 4 deletions pkg/appimport/appimport_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package appimport

import (
"path"
"path/filepath"
"testing"

"strings"
Expand All @@ -20,7 +20,7 @@ import (
func TestValidateAsset(t *testing.T) {
assert := assert.New(t)

testArchivePath := path.Join(testcommon.CreateTmpDir("appimport"), "db.tar.gz")
testArchivePath := filepath.Join(testcommon.CreateTmpDir("appimport"), "db.tar.gz")

testFile, err := os.Create(testArchivePath)
if err != nil {
Expand All @@ -38,7 +38,7 @@ func TestValidateAsset(t *testing.T) {

// test tilde expansion
userDir, err := homedir.Dir()
testDir := path.Join(userDir, "testpath")
testDir := filepath.Join(userDir, "testpath")
assert.NoError(err)
err = os.Mkdir(testDir, 0755)
assert.NoError(err)
Expand Down Expand Up @@ -71,6 +71,6 @@ func TestValidateAsset(t *testing.T) {
assert.Error(err)
assert.Contains(err.Error(), "provided path is not a directory or archive")

err = os.RemoveAll(path.Dir(testArchivePath))
err = os.RemoveAll(filepath.Dir(testArchivePath))
util.CheckErr(err)
}
40 changes: 33 additions & 7 deletions pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"html/template"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -50,7 +49,9 @@ type Config struct {
func NewConfig(AppRoot string) (*Config, error) {
// Set defaults.
c := &Config{}
c.ConfigPath = path.Join(AppRoot, ".ddev", "config.yaml")
err := prepLocalSiteDirs(AppRoot)
util.CheckErr(err)
c.ConfigPath = filepath.Join(AppRoot, ".ddev", "config.yaml")
c.AppRoot = AppRoot
c.APIVersion = CurrentAppVersion

Expand All @@ -64,7 +65,7 @@ func NewConfig(AppRoot string) (*Config, error) {

// Load from file if available. This will return an error if the file doesn't exist,
// and it is up to the caller to determine if that's an issue.
err := c.Read()
err = c.Read()
if err != nil {
return c, err
}
Expand Down Expand Up @@ -115,7 +116,7 @@ func (c *Config) Read() error {

// If any of these values aren't defined in the config file, set them to defaults.
if c.Name == "" {
c.Name = path.Base(c.AppRoot)
c.Name = filepath.Base(c.AppRoot)
}
if c.WebImage == "" {
c.WebImage = version.WebImg + ":" + version.WebTag
Expand Down Expand Up @@ -152,7 +153,7 @@ func (c *Config) Config() error {
if c.Name == "" {
dir, err := os.Getwd()
if err == nil {
c.Name = path.Base(dir)
c.Name = filepath.Base(dir)
}
}

Expand All @@ -179,7 +180,7 @@ func (c *Config) Config() error {

// DockerComposeYAMLPath returns the absolute path to where the docker-compose.yaml should exist for this app configuration.
func (c *Config) DockerComposeYAMLPath() string {
return path.Join(c.AppRoot, ".ddev", "docker-compose.yaml")
return filepath.Join(c.AppRoot, ".ddev", "docker-compose.yaml")
}

// Hostname returns the hostname to the app controlled by this config.
Expand Down Expand Up @@ -330,7 +331,7 @@ func determineAppType(basePath string) (string, error) {
}

for k, v := range defaultLocations {
fp := path.Join(basePath, k)
fp := filepath.Join(basePath, k)
log.WithFields(log.Fields{
"file": fp,
}).Debug("Looking for app fingerprint.")
Expand All @@ -346,3 +347,28 @@ func determineAppType(basePath string) (string, error) {

return "", errors.New("determineAppType() couldn't determine app's type")
}

// prepLocalSiteDirs creates a site's directories for local dev in .ddev
func prepLocalSiteDirs(base string) error {
dirs := []string{
".ddev",
".ddev/data",
}
for _, d := range dirs {
dirPath := filepath.Join(base, d)
fileInfo, err := os.Stat(dirPath)

if os.IsNotExist(err) { // If it doesn't exist, create it.
err := os.MkdirAll(dirPath, os.FileMode(int(0774)))
if err != nil {
return fmt.Errorf("Failed to create directory %s, err: %v", dirPath, err)
}
} else if err == nil && fileInfo.IsDir() { // If the directory exists, we're fine and don't have to create it.
continue
} else { // But otherwise it must have existed as a file, so bail
return fmt.Errorf("Error where trying to create directory %s, err: %v", dirPath, err)
}
}

return nil
}
7 changes: 1 addition & 6 deletions pkg/ddevapp/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -117,10 +116,6 @@ func TestWriteDockerComposeYaml(t *testing.T) {
config.AppType = AllowedAppTypes[0]
config.Docroot = testcommon.RandString(16)

err = config.WriteDockerComposeConfig()
// We should get an error here since no config or directory path exists.
assert.Error(err)

// Write a config to create/prep necessary directories.
err = config.Write()
assert.NoError(err)
Expand Down Expand Up @@ -201,7 +196,7 @@ func TestRead(t *testing.T) {

// This closely resembles the values one would have from NewConfig()
c := &Config{
ConfigPath: path.Join("testing", "config.yaml"),
ConfigPath: filepath.Join("testing", "config.yaml"),
AppRoot: "testing",
APIVersion: CurrentAppVersion,
Platform: DDevDefaultPlatform,
Expand Down
Loading

0 comments on commit 8f10148

Please sign in to comment.