Expose container exit code and exit time via inspect#1562
Open
bilby91 wants to merge 1 commit into
Open
Conversation
The container daemon already captures `ExitStatus` when the init process terminates, but the value never reaches `ContainerSnapshot` and is therefore absent from `container inspect` / `container list` output. This makes it impossible for callers to distinguish successful exits from failures, or to implement compose-style `depends_on: condition: service_completed_successfully` on top of the API. Add two optional fields to `ContainerSnapshot`: - `exitCode: Int32?` — the exit status of the init process - `exitedDate: Date?` — when the container transitioned to stopped Both default to nil, so existing snapshot JSON decodes unchanged (verified by `ContainerSnapshotTests`). The fields are populated in `ContainersService.handleContainerExit` and surfaced through the CLI's `PrintableContainer` projection. Fixes apple#1501
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ContainerSnapshotcurrently drops the exit status of the init process, socontainer inspectandcontainer listcannot tell callers whether a stopped container exited cleanly or with an error. The daemon already has the value (it observesExitStatusinhandleContainerExit); this PR just plumbs it through to the snapshot type and the CLI projection.Fixes #1501.
Changes
ContainerSnapshotgains two optional fields:exitCode: Int32?— exit code of the init processexitedDate: Date?— when the container transitioned to stoppedContainersService.handleContainerExitpopulates both fields before callingsetContainerState.PrintableContainer(the CLI'sCodableprojection used byinspect/list) carries the new fields through.Both fields default to
nil, so:nilandJSONEncoderstrips the keys from output — no breaking change for downstream consumers parsing today's JSON.Motivation
We're building crunchloop/devcontainer — an open-source Go runtime for Dev Containers — and are adding
apple/containeras a first-class backend alongside Docker. Part of that work is a native implementation of the compose subset Dev Containers relies on for multi-service workspaces.Two concrete things break today without exit-code visibility:
depends_on: condition: service_completed_successfully— a one-shot service (DB seeder, migration, fixture loader) has to finish and exit cleanly before dependents start. With no exit code ininspect, we can only observe "stopped" and have to guess at success.This is a small plumbing change — the daemon already captures
ExitStatus, it just isn't propagated. It's also the kind of low-level primitive that helps anyone building an orchestrator or higher-level tooling on top ofapple/container, not only us.Test plan
swift build(full project, 258 modules) — cleanswift test --filter ContainerSnapshotTests— 3/3 passnilexit fields (back-compat)Int32range (incl. negative,Int32.min,Int32.max)JSONEncoderstripsniloptionals)make fmt— no changes