Skip to content

API/json implementation and interaction with ddev, fixes #477 - #499

Merged
rfay merged 11 commits into
ddev:masterfrom
rfay:20171005_start_log_output_conversion
Nov 8, 2017
Merged

rfay merged 11 commits into
ddev:masterfrom
rfay:20171005_start_log_output_conversion

Conversation

@rfay

@rfay rfay commented Oct 5, 2017 •

Copy link
Copy Markdown
Member

The Problem/Issue/Bug:

OP #477: It will be done in several sections:

Work to do from #477:

  • Add a UserOut logger (just a logrus.New())
  • Set a custom formatter like UserTextFormatter to the UserOut - it will drop the timestamp and loglevel, can do other things as well. This is a fork of the logrus TextFormatter.
  • Add a ddev command flag to specify json output, like --json. This would cause setting the UserOut formatter to log.JSONFormatter
  • Use logrus (UserOut) for all output aimed at the user
  • Remove all imports of the stdlib log
  • Remove all usage of log in tests, they should be using t.log and family
  • Remove all usages of fmt.Print* and the like
  • ddev list and ddev describe need more attention than this because they painstakingly build the text as a simple output buffer. We'll need to refactor them so that they build a data structure and then either output the data structure as json or render the table and output it.
  • Retest all interactive prompts to make sure they still look right. For example, database import and files import interactive prompts
  • Automated tests for json output

Note that ddev logs turns output responsibility over to docker, so can't currently output in json. We need to consider whether we want to be able to turn container logs into json.

Design and Structure

This PR changes ddev to use a single output mechanism for all user-destined output. The UserOut log object (based on spf13/logrus) has been modified to output directly to the user, except when the --json flag is provided, in which case it outputs a json response to the same command. So for example, ddev list gives traditional output (but using UserOut, not direct stdout), but ddev list --json or ddev list -j gives the same a machine-readable json version.

JSON output

For the json ddev list and ddev describe commands a field named "raw" is added. This is what should be consumed by ddev-ui. The normal msg is there, but it's intended for non-json uses, and would be inappropriate to parse.

For all other commands, the normal response (or error response) is just wrapped in a json envelope with severity, etc.

Manual Testing Instructions:

Try all commands. Try the commands with --json (or -j). The json output is pretty-printed when output to a terminal, to make it easier to analyze.

Automated Testing Overview:

Related Issue Link(s):

Release/Deployment notes:

@rfay
rfay force-pushed the 20171005_start_log_output_conversion branch 3 times, most recently from ef29020 to c73bbd4 Compare October 17, 2017 22:05
@rfay

rfay commented Oct 24, 2017

Copy link
Copy Markdown
Member Author

This still needs tests for the json output, and I'll be doing a walkthrough of the interactive prompts like ddev config, but the basics are in place and it passes tests. I'd really appreciate a review of the code and approach and of the json output. I'm updating the OP to describe what's been done and what it means, and the structure of the json ouput.

@rfay
rfay requested a review from tannerjfco October 24, 2017 13:35
@rfay rfay assigned beeradb and rfay and unassigned beeradb Oct 24, 2017
@rfay
rfay requested a review from beeradb October 24, 2017 13:35

@tannerjfco tannerjfco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a first pass through the code here... there's a bit to review, so this isn't a thorough pass by any means.

I'm kind of surprised at how much utility function this has required. When I did some fancier logging with logrus in asset-manager, I was able to keep using log.Print et al as usual, and direct the output the way I needed to at the end. However, I didn't have to alter my output or deal w/ json (though i expect I will before long there), so I expect there's plenty more complications you've faced on this than I did on that other project. Not sure what I'm after here, perhaps a bit of explanation could help, but mostly just reacting to how much this effort ended up taking.

I haven't run this yet, but I'll take a stab at it tomorrow or the next with fresher eyes. Overall my initial gut reaction is that this approach seems fine, just surprising how much of the details we're having to address on our own.

Comment thread cmd/ddev/cmd/root.go Outdated
}

func init() {
RootCmd.PersistentFlags().BoolVarP(&util.JSONOutput, "json", "j", false, "If true, iser-oriented output will be in JSON format.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about output-json or json-output? Not sure we need a shorthand flag since users are unlikely to use this flag, though it doesn't hurt either.

Typo: s/iser-oriented/user-oriented

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to --json-output. -j is in fact nice for testing.

Comment thread pkg/ddevapp/config.go Outdated
func (c *Config) WarnIfConfigReplace() {
if c.ConfigExists() {
util.Warning("You are re-configuring the app at %s. \nThe existing configuration will be updated and replaced.\n\n", c.AppRoot)
util.Warning("You are re-configuring %s. The existing configuration will be replaced.\n\n", c.AppRoot)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need one of these :) First or last ones look best to me.

Comment thread pkg/plugins/platform/local.go Outdated
}

// ExecWithTty executes a given command in the container of given type. It allocates a pty for interactive work.
// Returns ComposeCmd results of err, stdout, stderr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment line seems inaccurate for this function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7eb90e2

Comment thread pkg/plugins/platform/local.go Outdated
@@ -667,7 +661,7 @@ func (l *LocalApp) DockerEnv() {
// @ TODO: I have no idea what a Setenv error would even look like, so I'm not sure what

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, we can probably lose this TODO. I think we're doing all that's reasonable to be done here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey we've had that in there so long it's an old friend!


stdout := testcommon.CaptureStdOut()
err = app.Exec("db", true, "mysql", "-e", "SHOW TABLES;")
out, _, err := app.Exec("db", "mysql", "-e", "SHOW TABLES;")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the 2nd returned var actually used anywhere we're calling app.Exec? (stderr output i think) I don't think I've seen it in use.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the tests now use it instead of trying to capture output in the fancy output-capture way.

Comment thread pkg/util/log_support.go
return true
}
for _, ch := range text {
if !((ch >= 'a' && ch <= 'z') ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm having a hard time grokking these conditions

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah copied from logrus. No idea.

Comment thread pkg/util/log_support.go Outdated
if !f.DisableTimestamp {
f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat))
}
//f.appendKeyValue(b, "level", entry.Level.String())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, cleanup - this and a couple lines later

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fa6049a

Comment thread pkg/util/log_support.go Outdated
}
}

// Below is from logus json_formatter.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be useful to reference a commit/file this is adapted from, and to highlight any of our customizations

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 634f884

Comment thread pkg/util/utils.go
func Failed(format string, a ...interface{}) {
Error(format, a...)
os.Exit(1)
if a != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i understand the reason for condition check here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRc, log.Fatalf("some format string", nil) makes ugly output, pointing out the nil to the end user and calling it bad.

Comment thread pkg/util/utils.go Outdated
func Error(format string, a ...interface{}) {
color.Red(format, a...)
if a != nil {
UserOut.Fatalf(format, a...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fatal doesn't seem right here

@rfay rfay Oct 25, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed in 210a22b

@rfay
rfay force-pushed the 20171005_start_log_output_conversion branch 3 times, most recently from 7a53cfa to 40b59f0 Compare October 26, 2017 01:48
@rfay

rfay commented Oct 26, 2017

Copy link
Copy Markdown
Member Author

This now has tests for ddev list -j, ddev describe -j, and ddev restart -j. Mostly "list" and "describe" are special, so deserve tests; restart is just random output, so we're only testing to see if we have some reasonable json.

@rfay
rfay force-pushed the 20171005_start_log_output_conversion branch from 29bb61e to 04c3d9b Compare October 26, 2017 13:13

@beeradb beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a first pass on the code. Things look like they are moving the right direction but I did have some feedback. Thanks for the work so far on this.

Comment thread pkg/util/log_support.go Outdated
@@ -0,0 +1,347 @@
package util

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably feel better to me as it's own package. It feels sort of weird to see util.UserOut everywhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions for package name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger, output, format

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There goes Brad wanting a package for every function :)

Comment thread cmd/ddev/cmd/describe.go
func describeApp(appName string) (string, error) {
var err error
// renderAppDescribe takes the map describing the app and renders it for plain-text output
func renderAppDescribe(desc map[string]interface{}) (string, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this functionality probably deserves a life outside of our cobra commands.

I'd probably prefer output format as an argument to site.Describe().

@rfay rfay Oct 31, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move this. However, it's only a text formatting element, the same as what was here before, and it would only be used by this cobra command. It takes the authoritative description (a map) and turns it into a text table (which would only be used by the cobra command).

As far as the usage of site.Describe() I guess I disagree. It now gives an authoritative machine-usable response (a map), which can be turned into a text table. Having it provide both a textual representation and a map would require extra processing for every call (no big deal) and have 2 returns (odd). But the only place it gets turned into a table is here.

Comment thread cmd/ddev/cmd/list.go Outdated
platform.RenderAppRow(table, desc)
}

util.UserOut.WithField("raw", appDescs).Print(table)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above, it feels like would be better served with a single output flag to CreateAppTable(). If we ever consume those packages from another source. JSON output could very well be important to what we are doing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table is unrelated to the actual json that is output here. There's a kind of a trick going on with this output: The 'raw' field is for the json consumer, and the table is for the plain-text consumer.

Comment thread cmd/ddev/cmd/list_test.go

// Look through list results in json for this site.
found := false
for _, listitem := range raw {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be easier/more clear to just define the struct you are looking here and compare to the values in raw using reflect.DeepEqual()? https://golang.org/pkg/reflect/#DeepEqual

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good suggestion for a thorough test. My opinion is that this is just a one-off test and whatever works is OK here. This is "good enough" for now. It's a slight improvement on what we had.

Comment thread pkg/ddevapp/providerPantheon.go Outdated
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a log.Fatalf in this file which I believe should use the new output logger?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1367ee

}
appTable := CreateAppTable()
shortRoot := RenderHomeRootedDir(l.AppRoot())
appDesc := make(map[string]interface{})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would feel a lot better if were a real type rather than map[string]interface. The same struct could be used (or we could use a trimmed down version and rely on composition) for the ddev list values.

fmt.Println("Provide the path to the database you wish to import.")
fmt.Println("Import path: ")
util.UserOut.Println("Provide the path to the database you wish to import.")
fmt.Print("Import path: ")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be util.UserOut, right?

@rfay rfay Oct 26, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the logrus system always seems to emit a CR, so I used fmt.Print() on the prompts for config and import commands. Open to other solutions. The reality is we need to use one of many prompter libraries. Opened #523 for this.

fmt.Println("You provided an archive. Do you want to extract from a specific path in your archive? You may leave this blank if you wish to use the full archive contents")
fmt.Println("Archive extraction path:")
util.UserOut.Println("You provided an archive. Do you want to extract from a specific path in your archive? You may leave this blank if you wish to use the full archive contents")
fmt.Print("Archive extraction path:")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be util.UserOut, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, same reason, apparently no way to get Logrus to not emit a CR, so prompting looks weird.

Comment thread pkg/util/log_support.go Outdated
}

// LogSetUp sets up UserOut and log loggers as needed by ddev
func LogSetUp() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This feels more like "output" than "logs" to me. I'm not sure why. Maybe there's no difference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the perspective of Logrus, it's log setup. From the perspective of the end user it's output.

Comment thread cmd/ddev/cmd/root.go Outdated
}

func init() {
RootCmd.PersistentFlags().BoolVarP(&util.JSONOutput, "json-output", "j", false, "If true, user-oriented output will be in JSON format.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to leave the door open to future output formats. I'd probably prefer one of the following methods here:

  • Drush style: --format=json
  • kubectl/helm golang style: -o/--output=json

@rfay

rfay commented Oct 31, 2017 •

Copy link
Copy Markdown
Member Author

I think all the small feedback is accounted for. Now we have decisions to make on larger feedback:

  • Brad would like to change the json format flag from a boolean on/off to a --format=xxx. I would prefer doing this when it's called for. Right now, the flag is a simple bool and does what is called for in this issue.
  • Brad would like to use a struct to describe an app instead of the more free-form map approach I've taken. This is a valid comment, but the map approach is also valid. I would argue that it doesn't deserve that level of effort or disruption at this time.
  • Brad would like to move log_support.go to its own package. I'm fine with it in util. We always disagree about package organization :)
  • Tanner suggested that we might be able to make the util.UserOut.xxx() statements easier by just using log as is, and only having one output format at a time. This does make for simpler lines of code, but it means that we can't use log() separately. sirupsen logging is a bit of an oddity for our CLI anyway, it's intended for a daemon or long-running process with output, not for something that interacts with the user. However, that's where we are and what we've done for a long time. So I could consolidate everything back into log, it's not that hard. The few remaining log() statements would no longer have timestamps and such, and would be formatted differently.

We should have a quick chat or meeting to resolve these, and I think this will be ready for a final pass when it's green (I seem to have broken something in a few trivial commits).

@rfay
rfay force-pushed the 20171005_start_log_output_conversion branch from d2a785b to d279609 Compare October 31, 2017 18:59
@rickmanelius

Copy link
Copy Markdown
Contributor

Regarding the 4 open items in #499 (comment), for items 1 and 2 I'm all in favor of simplicity for now and expanding when necessary. So if we decide to just keep it a boolean as a toggle and use the existing structure, for now, that probably makes sense unless/until we need the additional effort.

I have no opinion on items 3 and 4.

@rfay

rfay commented Oct 31, 2017

Copy link
Copy Markdown
Member Author

There is one more test fix for windows required on this. It affects nothing for review or decisionmaking.

@tannerjfco tannerjfco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took this for a spin and mostly saw things working as expected. Thanks for all the work on this so far. I did find some areas where normal text output wasn't what I expected:

  • I have to confess, I miss the container output during startup. We don't have any new output until the site is fully ready, and it makes the wait rather uncomfortable.

  • ddev rm and ddev stop give no output until they return successful (or not). Empty newline after the success message on rm.

  • ddev start output was all white text. Previously success messages were colored blue.

  • unexpected newline after ddev exec output

  • ddev hostname error outputs as "FATA[0000] Could not add hostname"

  • Seems like success messages in general are not output as colored text

Comment thread pkg/testcommon/testcommon.go Outdated
// Capturing starts when it is called. It returns an anonymous function that
// when called, will return a string containing the output during capture, and
// revert once again to the original value of os.StdOut.
func CaptureUserOutOutput() func() string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name really stutters. CaptureUserOut would be fine IMO

Comment thread pkg/util/log_support.go
levelColor = nocolor
}

fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m ", levelColor, entry.Message)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be helpful to have explanations like this in code comments. I still don't have a firm grasp of what's copied as-is from logrus vs what's been modified, and it'd help to be able to make this determination quickly months later when we've forgotten this discussion.

@rfay

rfay commented Nov 1, 2017

Copy link
Copy Markdown
Member Author

@tannerjfco Item #4 was based on an earlier discussion in this issue, #499 (comment) - do you want to pursue that at all? We could just use log and lose the "native" capabilities/format of log.Debug() and such. It would make the code less verbose, which would be nice. But then log() is also a kind of not doing log() things at all.

@beeradb beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent about an hour with this today in both JSON and standard output modes. I was able to find a few issues, but nothing that wasn't covered in @tannerjfco's feedback.

I'm good with this once that feedback is addressed.

@rfay
rfay force-pushed the 20171005_start_log_output_conversion branch from 42863d3 to 80ed3bc Compare November 2, 2017 21:00
@rfay
rfay force-pushed the 20171005_start_log_output_conversion branch from 80ed3bc to 4f35405 Compare November 2, 2017 21:28
@rickmanelius

Copy link
Copy Markdown
Contributor

@rfay Acknowledged that this is a request for me to weigh in. Attempting to get a test on this today...

@rickmanelius
rickmanelius self-requested a review November 7, 2017 22:55

@rickmanelius rickmanelius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference

Testing

Performed by Rick Manelius as of 2017-11-07

Hardware Setup

I’m using a laptop with the following high-level specifications:

  • MacBook Pro: Retina 15-inch Mid 2015
  • 2.2 Ghz Intel Core i7
  • 16 GB 1600 MHz DDR3 RAM
  • 250 GB Hard Drive
  • macOS Sierra 10.12.4

Software Setup

  • Xcode
  • Go 1.8.1
  • Docker 17.06.0-ce-rc1
  • Git 2.11.0

Repositories Used

Setup

  • git fetch --all
  • git checkout 0d16773
  • make clean && make darwin
  • ddev version outputs v0.9.3-14-g0d167733

Results

  • Testing json output
    • ddev list => works
    • ddev describe => works
    • ddev stop => works and provides more info as it's available
  • Testing standard output
    • For ddev start/stop/restart, I fall on the side of wanting to see the docker compose output. Three reasons:
      1. Basic debugging and alerting the end-user to containers being created/removed.
      2. Showing progress. This is particularly true for longer operations. Seeing absoultely nothing for up to say a minute can make it feel longer or makes me think something may be stuck.
      3. Verbosity. If we rely on DRUD_DEBUG, then I anticipate many will leave on by default and get overwhelmed.

Recommendations

  • I vote for bringing back that docker compose output that we used to have for start/stop/rm/restart.
  • I agree that the success message coloration was used to have is preferrable, but I do believe there are related issues that we can address color consistency #363. To be explicit, I don't think this should hold up this PR from acceptance.

@rfay

rfay commented Nov 8, 2017

Copy link
Copy Markdown
Member Author

Unblocked me!

Just so you know @rickmanelius I don't think the color issues here are related to #363. The problem here is that we don't have any way in the logging platform to distinguish between "informational" and "success". And since we're using consistent output techniques, we don't want to be randomly coloring things, but rather use the chosen output to do that. That said, it's probably possible to randomly and manually color a few outputs.

@rfay

rfay commented Nov 8, 2017

Copy link
Copy Markdown
Member Author

I re-enabled output of docker-compose output.
And (silly me) I found a simple way of coloring success output in util.Success() of all places.

There is a newline (sometimes) output in the docker-compose output that I've been unable to track down and work on.

@tannerjfco tannerjfco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work on this @rfay. I think we're good to go here 👍

@rickmanelius
rickmanelius requested review from rickmanelius and removed request for rickmanelius November 8, 2017 16:27

@rickmanelius rickmanelius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turn! 👍

@rfay
rfay merged commit d7b5745 into ddev:master Nov 8, 2017
@rfay
rfay deleted the 20171005_start_log_output_conversion branch November 8, 2017 16:40
@rickmanelius rickmanelius mentioned this pull request Nov 20, 2017
6 tasks done
rfay added a commit to rfay/ddev that referenced this pull request Nov 3, 2026
…ainer gaps, for ddev#7372

Each skip names its cause: hostname uniqueness on Compose recreate,
socktainer#497 (volume nocopy), ddev#498 (network names), ddev#493 (exit code),
ddev#499 (exec working directory, only that check in TestCmdExec), the
single-writer volume, and the server OS socktainer reports. The
stale-dbimage subtest builds with --load, since socktainer's builder is
buildx's docker-container driver. Adds the repros for ddev#497-ddev#499.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 3, 2026
rfay added a commit to rfay/ddev that referenced this pull request Nov 3, 2026
…ainer gaps, for ddev#7372

Each skip names its cause: hostname uniqueness on Compose recreate,
socktainer#497 (volume nocopy), ddev#498 (network names), ddev#493 (exit code),
ddev#499 (exec working directory, only that check in TestCmdExec), the
single-writer volume, and the server OS socktainer reports. The
stale-dbimage subtest builds with --load, since socktainer's builder is
buildx's docker-container driver. Adds the repros for ddev#497-ddev#499.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 3, 2026
rfay added a commit to rfay/ddev that referenced this pull request Nov 4, 2026
…ainer gaps, for ddev#7372

Each skip names its cause: hostname uniqueness on Compose recreate,
socktainer#497 (volume nocopy), ddev#498 (network names), ddev#493 (exit code),
ddev#499 (exec working directory, only that check in TestCmdExec), the
single-writer volume, and the server OS socktainer reports. The
stale-dbimage subtest builds with --load, since socktainer's builder is
buildx's docker-container driver. Adds the repros for ddev#497-ddev#499.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 4, 2026
rfay added a commit to rfay/ddev that referenced this pull request Nov 5, 2026
…ainer gaps, for ddev#7372

Each skip names its cause: hostname uniqueness on Compose recreate,
socktainer#497 (volume nocopy), ddev#498 (network names), ddev#493 (exit code),
ddev#499 (exec working directory, only that check in TestCmdExec), the
single-writer volume, and the server OS socktainer reports. The
stale-dbimage subtest builds with --load, since socktainer's builder is
buildx's docker-container driver. Adds the repros for ddev#497-ddev#499.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 5, 2026
rfay added a commit to rfay/ddev that referenced this pull request Nov 6, 2026
…ainer gaps, for ddev#7372

Each skip names its cause: hostname uniqueness on Compose recreate,
socktainer#497 (volume nocopy), ddev#498 (network names), ddev#493 (exit code),
ddev#499 (exec working directory, only that check in TestCmdExec), the
single-writer volume, and the server OS socktainer reports. The
stale-dbimage subtest builds with --load, since socktainer's builder is
buildx's docker-container driver. Adds the repros for ddev#497-ddev#499.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 6, 2026
rfay added a commit to rfay/ddev that referenced this pull request Nov 23, 2026
…#7372

## Short Summary (TL;DR)

DDEV detects Apple Container behind [socktainer](https://github.com/socktainer/socktainer) and adapts to it, so projects start and run there. Support is marked experimental, and nothing changes on other providers.

## The Issue

- Fixes ddev#7372

Apple Container runs each container in its own VM. A named volume takes either one read-write attachment or any number of read-only ones. A Unix socket in one container can't be reached from another. Ports below 1024 can't be published. socktainer, the Docker-compatible API in front of it, still has gaps. Most of the volume sharing DDEV used to depend on was removed upstream for ddev#8895 (ddev#8945, ddev#9024, ddev#8956, ddev#8944, ddev#9041, ddev#9042, ddev#9045). ddev#9040, ddev#9046, ddev#9061, ddev#9108, ddev#9115 and ddev#9121 also came out of this work. What's left is here.

## How This PR Solves The Issue

DDEV detects the provider through socktainer's `docker version` output (`IsAppleContainer()`). Every change below applies only on that provider.

- `ddev version`, `ddev utility dockercheck`, `ddev utility port-diagnose` and instrumentation report the provider as `apple-container`.
- `ddev start` and `ddev utility dockercheck` warn when socktainer is older than 1.6.1. Builds from source report no release version, so DDEV doesn't compare them.
- `ddev-ssh-agent` is always omitted, because web can't attach a volume another VM holds. With `ssh_agent_upstream` set, web bind-mounts that host socket directly, and Apple Container relays it into the VM. `host` uses `SSH_AUTH_SOCK`. `ddev auth ssh` explains this instead of adding keys to an agent web can't reach.
- `CopyIntoContainer` extracts with `tar` inside the container. socktainer 1.6.1 ignores a gzipped archive ([socktainer#484](socktainer/socktainer#484)) and drops each file's owner and mtime ([socktainer#514](socktainer/socktainer#514)). Both are fixed on socktainer `main` but not released.
- The mkcert CA archive leaves out its directory entry, which a never-started container refuses ([socktainer#502](socktainer/socktainer#502)).
- Project images build one service at a time. Concurrent image loads can leave a tag on its old image ([socktainer#518](socktainer/socktainer#518)), and Compose's bake build loads them all at once. Compose's concurrency limit doesn't reach the bake path, so DDEV calls `Build` once per service.
- Image pulls and `BuildPlatformToPull` use `linux/<arch>`, because socktainer's `/version` reports `Os: macOS` ([socktainer#517](socktainer/socktainer#517)).
- `host.docker.internal` is `host-gateway`, which socktainer resolves to the network gateway where the Mac answers.
- `FindContainersByVolume` matches `Mounts` itself, because socktainer ignores the `volume=` filter.
- Add-on installs get the same virtiofs propagation delay as Lima and Colima.
- Docs: an experimental Apple Container tab on the macOS Docker installation page, with setup, the Local Network prompt, SSH keys, limitations and a fix for a hanging `container system start`.

Mutagen works and is the default, as on any macOS provider.

Known limitations, each documented or named by a test skip:

- **Ports below 1024** can't be published. The router needs `ddev config global --router-http-port=8080 --router-https-port=8443`. The global setting matters: with 80/443 there, the router fails to bind even when the project sets 8080/8443.
- **Single-writer volumes:** add-on services that share a named volume with a running container fail to start. Apple closed [apple/container#1133](apple/container#1133) as working as designed.
- **Open socktainer issues:** [ddev#518](socktainer/socktainer#518), [ddev#519](socktainer/socktainer#519), [ddev#520](socktainer/socktainer#520), [ddev#517](socktainer/socktainer#517), [ddev#514](socktainer/socktainer#514), [ddev#510](socktainer/socktainer#510), [ddev#504](socktainer/socktainer#504), [ddev#499](socktainer/socktainer#499), [ddev#498](socktainer/socktainer#498), [ddev#497](socktainer/socktainer#497).
- **Unreleased socktainer fixes:** `main` has fixes for ddev#505, ddev#514, ddev#484 and ddev#498, the last still in PR [ddev#528](socktainer/socktainer#528). After the next release, a follow-up can raise `SocktainerMinVersion` and remove the matching skips and the `tar` workaround.
- socktainer 1.6.1 warns that it was built for Apple Container 1.6.1 when run with 1.7.1. The CI testbots run that pair, and it passes.

## Manual Testing Instructions

This needs macOS 26 on Apple silicon. The setup is in the new docs tab: https://ddev--8656.org.readthedocs.build/en/8656/users/install/docker-installation/

```bash
brew install socktainer docker docker-buildx
container system start
socktainer &
docker context use socktainer
ddev utility download-ddev --pr 8656
export PATH="$HOME/tmp/ddev-download-ddev/pr-8656:$PATH"
ddev config global --router-http-port=8080 --router-https-port=8443 --ssh-agent-upstream=host
mkdir -p ~/tmp/appletest && cd ~/tmp/appletest
echo '<?php echo gethostname();' > index.php
ddev config --project-type=php --docroot=.
ddev start -y
# Expect: macOS asks to allow container-runtime-linux on the local network the first time; click Allow
curl -s http://appletest.ddev.site:8080/
# Expect: appletest-web
ddev mutagen st -l | grep Status
# Expect: Status: Watching for changes
ddev exec ssh-add -l
# Expect: the keys that `ssh-add -l` lists on the host
ddev auth ssh
# Expect: an explanation that web uses the host's agent directly
ddev utility dockercheck
# Expect: socktainer version: 1.6.1
```

On another provider, run `ddev debug compose-config` in a project. Confirm that web still mounts `ddev-ssh-agent_socket_dir` and that `host.docker.internal` is unchanged.

## Automated Testing Overview

The Buildkite pipeline [macos-socktainer](https://buildkite.com/ddev/macos-socktainer) runs the suite with `DOCKER_TYPE=socktainer` and router ports 8080/8443. It runs on testbots with Apple Container 1.7.1 and socktainer 1.6.1. Build 40 passed on this branch before it was squashed.

- `TestAppleContainerSSHAgent` covers the host-agent mount. The `ddev-ssh-agent` tests skip there.
- Tests that hit a known socktainer or Apple Container gap skip on `IsAppleContainer()`, and each skip names its cause.
- `SkipUnlessDefaultEnvironment` still skips its tests there through its Mutagen check.

## Release/Deployment Notes

Apple Container support is experimental. The `macos-socktainer` pipeline builds only this branch, so its branch filter needs widening after merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 24, 2026
…#7372

## Short Summary (TL;DR)

DDEV detects Apple Container behind [socktainer](https://github.com/socktainer/socktainer) and adapts to it, so projects start and run there. Support is marked experimental, and nothing changes on other providers.

## The Issue

- Fixes ddev#7372

Apple Container runs each container in its own VM. A named volume takes either one read-write attachment or any number of read-only ones. A Unix socket in one container can't be reached from another. Ports below 1024 can't be published. socktainer, the Docker-compatible API in front of it, still has gaps. Most of the volume sharing DDEV used to depend on was removed upstream for ddev#8895 (ddev#8945, ddev#9024, ddev#8956, ddev#8944, ddev#9041, ddev#9042, ddev#9045). ddev#9040, ddev#9046, ddev#9061, ddev#9108, ddev#9115 and ddev#9121 also came out of this work. What's left is here.

## How This PR Solves The Issue

DDEV detects the provider through socktainer's `docker version` output (`IsAppleContainer()`). Every change below applies only on that provider.

- `ddev version`, `ddev utility dockercheck`, `ddev utility port-diagnose` and instrumentation report the provider as `apple-container`.
- `ddev start` and `ddev utility dockercheck` warn when socktainer is older than 1.6.1. Builds from source report no release version, so DDEV doesn't compare them.
- `ddev-ssh-agent` is always omitted, because web can't attach a volume another VM holds. With `ssh_agent_upstream` set, web bind-mounts that host socket directly, and Apple Container relays it into the VM. `host` uses `SSH_AUTH_SOCK`. `ddev auth ssh` explains this instead of adding keys to an agent web can't reach.
- `CopyIntoContainer` extracts with `tar` inside the container. socktainer 1.6.1 ignores a gzipped archive ([socktainer#484](socktainer/socktainer#484)) and drops each file's owner and mtime ([socktainer#514](socktainer/socktainer#514)). Both are fixed on socktainer `main` but not released.
- The mkcert CA archive leaves out its directory entry, which a never-started container refuses ([socktainer#502](socktainer/socktainer#502)).
- Project images build one service at a time. Concurrent image loads can leave a tag on its old image ([socktainer#518](socktainer/socktainer#518)), and Compose's bake build loads them all at once. Compose's concurrency limit doesn't reach the bake path, so DDEV calls `Build` once per service.
- Image pulls and `BuildPlatformToPull` use `linux/<arch>`, because socktainer's `/version` reports `Os: macOS` ([socktainer#517](socktainer/socktainer#517)).
- `host.docker.internal` is `host-gateway`, which socktainer resolves to the network gateway where the Mac answers.
- `FindContainersByVolume` matches `Mounts` itself, because socktainer ignores the `volume=` filter.
- Add-on installs get the same virtiofs propagation delay as Lima and Colima.
- Docs: an experimental Apple Container tab on the macOS Docker installation page, with setup, the Local Network prompt, SSH keys, limitations and a fix for a hanging `container system start`.

Mutagen works and is the default, as on any macOS provider.

Known limitations, each documented or named by a test skip:

- **Ports below 1024** can't be published. The router needs `ddev config global --router-http-port=8080 --router-https-port=8443`. The global setting matters: with 80/443 there, the router fails to bind even when the project sets 8080/8443.
- **Single-writer volumes:** add-on services that share a named volume with a running container fail to start. Apple closed [apple/container#1133](apple/container#1133) as working as designed.
- **Open socktainer issues:** [ddev#518](socktainer/socktainer#518), [ddev#519](socktainer/socktainer#519), [ddev#520](socktainer/socktainer#520), [ddev#517](socktainer/socktainer#517), [ddev#514](socktainer/socktainer#514), [ddev#510](socktainer/socktainer#510), [ddev#504](socktainer/socktainer#504), [ddev#499](socktainer/socktainer#499), [ddev#498](socktainer/socktainer#498), [ddev#497](socktainer/socktainer#497).
- **Unreleased socktainer fixes:** `main` has fixes for ddev#505, ddev#514, ddev#484 and ddev#498, the last still in PR [ddev#528](socktainer/socktainer#528). After the next release, a follow-up can raise `SocktainerMinVersion` and remove the matching skips and the `tar` workaround.
- socktainer 1.6.1 warns that it was built for Apple Container 1.6.1 when run with 1.7.1. The CI testbots run that pair, and it passes.

## Manual Testing Instructions

This needs macOS 26 on Apple silicon. The setup is in the new docs tab: https://ddev--8656.org.readthedocs.build/en/8656/users/install/docker-installation/

```bash
brew install socktainer docker docker-buildx
container system start
socktainer &
docker context use socktainer
ddev utility download-ddev --pr 8656
export PATH="$HOME/tmp/ddev-download-ddev/pr-8656:$PATH"
ddev config global --router-http-port=8080 --router-https-port=8443 --ssh-agent-upstream=host
mkdir -p ~/tmp/appletest && cd ~/tmp/appletest
echo '<?php echo gethostname();' > index.php
ddev config --project-type=php --docroot=.
ddev start -y
# Expect: macOS asks to allow container-runtime-linux on the local network the first time; click Allow
curl -s http://appletest.ddev.site:8080/
# Expect: appletest-web
ddev mutagen st -l | grep Status
# Expect: Status: Watching for changes
ddev exec ssh-add -l
# Expect: the keys that `ssh-add -l` lists on the host
ddev auth ssh
# Expect: an explanation that web uses the host's agent directly
ddev utility dockercheck
# Expect: socktainer version: 1.6.1
```

On another provider, run `ddev debug compose-config` in a project. Confirm that web still mounts `ddev-ssh-agent_socket_dir` and that `host.docker.internal` is unchanged.

## Automated Testing Overview

The Buildkite pipeline [macos-socktainer](https://buildkite.com/ddev/macos-socktainer) runs the suite with `DOCKER_TYPE=socktainer` and router ports 8080/8443. It runs on testbots with Apple Container 1.7.1 and socktainer 1.6.1. Build 40 passed on this branch before it was squashed.

- `TestAppleContainerSSHAgent` covers the host-agent mount. The `ddev-ssh-agent` tests skip there.
- Tests that hit a known socktainer or Apple Container gap skip on `IsAppleContainer()`, and each skip names its cause.
- `SkipUnlessDefaultEnvironment` still skips its tests there through its Mutagen check.

## Release/Deployment Notes

Apple Container support is experimental. The `macos-socktainer` pipeline builds only this branch, so its branch filter needs widening after merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 25, 2026
…#7372

## Short Summary (TL;DR)

DDEV detects Apple Container behind [socktainer](https://github.com/socktainer/socktainer) and adapts to it, so projects start and run there. Support is marked experimental, and nothing changes on other providers.

## The Issue

- Fixes ddev#7372

Apple Container runs each container in its own VM. A named volume takes either one read-write attachment or any number of read-only ones. A Unix socket in one container can't be reached from another. Ports below 1024 can't be published. socktainer, the Docker-compatible API in front of it, still has gaps. Most of the volume sharing DDEV used to depend on was removed upstream for ddev#8895 (ddev#8945, ddev#9024, ddev#8956, ddev#8944, ddev#9041, ddev#9042, ddev#9045). ddev#9040, ddev#9046, ddev#9061, ddev#9108, ddev#9115 and ddev#9121 also came out of this work. What's left is here.

## How This PR Solves The Issue

DDEV detects the provider through socktainer's `docker version` output (`IsAppleContainer()`). Every change below applies only on that provider.

- `ddev version`, `ddev utility dockercheck`, `ddev utility port-diagnose` and instrumentation report the provider as `apple-container`.
- `ddev start` and `ddev utility dockercheck` warn when socktainer is older than 1.6.1. Builds from source report no release version, so DDEV doesn't compare them.
- `ddev-ssh-agent` is always omitted, because web can't attach a volume another VM holds. With `ssh_agent_upstream` set, web bind-mounts that host socket directly, and Apple Container relays it into the VM. `host` uses `SSH_AUTH_SOCK`. `ddev auth ssh` explains this instead of adding keys to an agent web can't reach.
- `CopyIntoContainer` extracts with `tar` inside the container. socktainer 1.6.1 ignores a gzipped archive ([socktainer#484](socktainer/socktainer#484)) and drops each file's owner and mtime ([socktainer#514](socktainer/socktainer#514)). Both are fixed on socktainer `main` but not released.
- The mkcert CA archive leaves out its directory entry, which a never-started container refuses ([socktainer#502](socktainer/socktainer#502)).
- Project images build one service at a time. Concurrent image loads can leave a tag on its old image ([socktainer#518](socktainer/socktainer#518)), and Compose's bake build loads them all at once. Compose's concurrency limit doesn't reach the bake path, so DDEV calls `Build` once per service.
- Image pulls and `BuildPlatformToPull` use `linux/<arch>`, because socktainer's `/version` reports `Os: macOS` ([socktainer#517](socktainer/socktainer#517)).
- `host.docker.internal` is `host-gateway`, which socktainer resolves to the network gateway where the Mac answers.
- `FindContainersByVolume` matches `Mounts` itself, because socktainer ignores the `volume=` filter.
- Add-on installs get the same virtiofs propagation delay as Lima and Colima.
- Docs: an experimental Apple Container tab on the macOS Docker installation page, with setup, the Local Network prompt, SSH keys, limitations and a fix for a hanging `container system start`.

Mutagen works and is the default, as on any macOS provider.

Known limitations, each documented or named by a test skip:

- **Ports below 1024** can't be published. The router needs `ddev config global --router-http-port=8080 --router-https-port=8443`. The global setting matters: with 80/443 there, the router fails to bind even when the project sets 8080/8443.
- **Single-writer volumes:** add-on services that share a named volume with a running container fail to start. Apple closed [apple/container#1133](apple/container#1133) as working as designed.
- **Open socktainer issues:** [ddev#518](socktainer/socktainer#518), [ddev#519](socktainer/socktainer#519), [ddev#520](socktainer/socktainer#520), [ddev#517](socktainer/socktainer#517), [ddev#514](socktainer/socktainer#514), [ddev#510](socktainer/socktainer#510), [ddev#504](socktainer/socktainer#504), [ddev#499](socktainer/socktainer#499), [ddev#498](socktainer/socktainer#498), [ddev#497](socktainer/socktainer#497).
- **Unreleased socktainer fixes:** `main` has fixes for ddev#505, ddev#514, ddev#484 and ddev#498, the last still in PR [ddev#528](socktainer/socktainer#528). After the next release, a follow-up can raise `SocktainerMinVersion` and remove the matching skips and the `tar` workaround.
- socktainer 1.6.1 warns that it was built for Apple Container 1.6.1 when run with 1.7.1. The CI testbots run that pair, and it passes.

## Manual Testing Instructions

This needs macOS 26 on Apple silicon. The setup is in the new docs tab: https://ddev--8656.org.readthedocs.build/en/8656/users/install/docker-installation/

```bash
brew install socktainer docker docker-buildx
container system start
socktainer &
docker context use socktainer
ddev utility download-ddev --pr 8656
export PATH="$HOME/tmp/ddev-download-ddev/pr-8656:$PATH"
ddev config global --router-http-port=8080 --router-https-port=8443 --ssh-agent-upstream=host
mkdir -p ~/tmp/appletest && cd ~/tmp/appletest
echo '<?php echo gethostname();' > index.php
ddev config --project-type=php --docroot=.
ddev start -y
# Expect: macOS asks to allow container-runtime-linux on the local network the first time; click Allow
curl -s http://appletest.ddev.site:8080/
# Expect: appletest-web
ddev mutagen st -l | grep Status
# Expect: Status: Watching for changes
ddev exec ssh-add -l
# Expect: the keys that `ssh-add -l` lists on the host
ddev auth ssh
# Expect: an explanation that web uses the host's agent directly
ddev utility dockercheck
# Expect: socktainer version: 1.6.1
```

On another provider, run `ddev debug compose-config` in a project. Confirm that web still mounts `ddev-ssh-agent_socket_dir` and that `host.docker.internal` is unchanged.

## Automated Testing Overview

The Buildkite pipeline [macos-socktainer](https://buildkite.com/ddev/macos-socktainer) runs the suite with `DOCKER_TYPE=socktainer` and router ports 8080/8443. It runs on testbots with Apple Container 1.7.1 and socktainer 1.6.1. Build 40 passed on this branch before it was squashed.

- `TestAppleContainerSSHAgent` covers the host-agent mount. The `ddev-ssh-agent` tests skip there.
- Tests that hit a known socktainer or Apple Container gap skip on `IsAppleContainer()`, and each skip names its cause.
- `SkipUnlessDefaultEnvironment` still skips its tests there through its Mutagen check.

## Release/Deployment Notes

Apple Container support is experimental. The `macos-socktainer` pipeline builds only this branch, so its branch filter needs widening after merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants