Repository navigation
API/json implementation and interaction with ddev, fixes #477 - #499
Conversation
ef29020 to
c73bbd4
Compare
|
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. |
tannerjfco
left a comment
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| func init() { | ||
| RootCmd.PersistentFlags().BoolVarP(&util.JSONOutput, "json", "j", false, "If true, iser-oriented output will be in JSON format.") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I'm open to --json-output. -j is in fact nice for testing.
| 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) |
There was a problem hiding this comment.
We only need one of these :) First or last ones look best to me.
| } | ||
|
|
||
| // 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 |
There was a problem hiding this comment.
this comment line seems inaccurate for this function
| @@ -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 | |||
There was a problem hiding this comment.
nit, we can probably lose this TODO. I think we're doing all that's reasonable to be done here.
There was a problem hiding this comment.
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;") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, the tests now use it instead of trying to capture output in the fancy output-capture way.
| return true | ||
| } | ||
| for _, ch := range text { | ||
| if !((ch >= 'a' && ch <= 'z') || |
There was a problem hiding this comment.
i'm having a hard time grokking these conditions
There was a problem hiding this comment.
Yeah copied from logrus. No idea.
| if !f.DisableTimestamp { | ||
| f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat)) | ||
| } | ||
| //f.appendKeyValue(b, "level", entry.Level.String()) |
There was a problem hiding this comment.
nit, cleanup - this and a couple lines later
| } | ||
| } | ||
|
|
||
| // Below is from logus json_formatter.go |
There was a problem hiding this comment.
might be useful to reference a commit/file this is adapted from, and to highlight any of our customizations
| func Failed(format string, a ...interface{}) { | ||
| Error(format, a...) | ||
| os.Exit(1) | ||
| if a != nil { |
There was a problem hiding this comment.
not sure i understand the reason for condition check here
There was a problem hiding this comment.
IIRc, log.Fatalf("some format string", nil) makes ugly output, pointing out the nil to the end user and calling it bad.
| func Error(format string, a ...interface{}) { | ||
| color.Red(format, a...) | ||
| if a != nil { | ||
| UserOut.Fatalf(format, a...) |
There was a problem hiding this comment.
fatal doesn't seem right here
7a53cfa to
40b59f0
Compare
|
This now has tests for |
29bb61e to
04c3d9b
Compare
beeradb
left a comment
There was a problem hiding this comment.
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.
| @@ -0,0 +1,347 @@ | |||
| package util | |||
There was a problem hiding this comment.
This would probably feel better to me as it's own package. It feels sort of weird to see util.UserOut everywhere.
There was a problem hiding this comment.
Suggestions for package name?
There was a problem hiding this comment.
There goes Brad wanting a package for every function :)
| 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) { |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
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.
| platform.RenderAppRow(table, desc) | ||
| } | ||
|
|
||
| util.UserOut.WithField("raw", appDescs).Print(table) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| // Look through list results in json for this site. | ||
| found := false | ||
| for _, listitem := range raw { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| "path/filepath" | ||
| "strings" | ||
|
|
||
| log "github.com/sirupsen/logrus" |
There was a problem hiding this comment.
There is a log.Fatalf in this file which I believe should use the new output logger?
| } | ||
| appTable := CreateAppTable() | ||
| shortRoot := RenderHomeRootedDir(l.AppRoot()) | ||
| appDesc := make(map[string]interface{}) |
There was a problem hiding this comment.
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: ") |
There was a problem hiding this comment.
This should be util.UserOut, right?
There was a problem hiding this comment.
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:") |
There was a problem hiding this comment.
This should be util.UserOut, right?
There was a problem hiding this comment.
No, same reason, apparently no way to get Logrus to not emit a CR, so prompting looks weird.
| } | ||
|
|
||
| // LogSetUp sets up UserOut and log loggers as needed by ddev | ||
| func LogSetUp() { |
There was a problem hiding this comment.
Nit: This feels more like "output" than "logs" to me. I'm not sure why. Maybe there's no difference.
There was a problem hiding this comment.
From the perspective of Logrus, it's log setup. From the perspective of the end user it's output.
| } | ||
|
|
||
| func init() { | ||
| RootCmd.PersistentFlags().BoolVarP(&util.JSONOutput, "json-output", "j", false, "If true, user-oriented output will be in JSON format.") |
There was a problem hiding this comment.
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
|
I think all the small feedback is accounted for. Now we have decisions to make on larger feedback:
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). |
d2a785b to
d279609
Compare
|
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. |
|
There is one more test fix for windows required on this. It affects nothing for review or decisionmaking. |
tannerjfco
left a comment
There was a problem hiding this comment.
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
| // 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 { |
There was a problem hiding this comment.
this name really stutters. CaptureUserOut would be fine IMO
| levelColor = nocolor | ||
| } | ||
|
|
||
| fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m ", levelColor, entry.Message) |
There was a problem hiding this comment.
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.
|
@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
left a comment
There was a problem hiding this comment.
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.
42863d3 to
80ed3bc
Compare
80ed3bc to
4f35405
Compare
|
@rfay Acknowledged that this is a request for me to weigh in. Attempting to get a test on this today... |
rickmanelius
left a comment
There was a problem hiding this comment.
Reference
- PR 499 #499
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
- https://github.com/drud/ddev at hash 0d16773
Setup
git fetch --allgit checkout 0d16773make clean && make darwinddev versionoutputs 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:
- Basic debugging and alerting the end-user to containers being created/removed.
- 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.
- Verbosity. If we rely on DRUD_DEBUG, then I anticipate many will leave on by default and get overwhelmed.
- For ddev start/stop/restart, I fall on the side of wanting to see the docker compose output. Three reasons:
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.
|
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. |
|
I re-enabled output of docker-compose output. There is a newline (sometimes) output in the docker-compose output that I've been unable to track down and work on. |
tannerjfco
left a comment
There was a problem hiding this comment.
Thanks for all the work on this @rfay. I think we're good to go here 👍
rickmanelius
left a comment
There was a problem hiding this comment.
Thanks for the quick turn! 👍
…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]>
…v#499 and the CA fix, for ddev#7372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
…v#499 and the CA fix, for ddev#7372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
…v#499 and the CA fix, for ddev#7372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
…v#499 and the CA fix, for ddev#7372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
…v#499 and the CA fix, for ddev#7372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#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]>
…#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]>
…#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]>
The Problem/Issue/Bug:
OP #477: It will be done in several sections:
Work to do from #477:
ddev listandddev describeneed 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.Note that
ddev logsturns 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 listgives traditional output (but using UserOut, not direct stdout), butddev list --jsonorddev list -jgives the same a machine-readable json version.JSON output
For the json
ddev listandddev describecommands 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: