Commit Graph

71 Commits

Author SHA1 Message Date
Paweł Gronowski
6c5233e109 modernize: Use strings.CutSuffix
Added in Go 1.20

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:34 +01:00
Paweł Gronowski
a25907b485 modernize: Prefer strings.SplitSeq instead of Split
Avoids extra allocations. Added in Go 1.24.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:33 +01:00
Cory Snider
ae28867804 api/pkg/progress: move to client and daemon/internal
Move the progress package up into the client as a temporary shared location for
common clients like CLI and compose.

The progress package is used by the daemon to write progress updates to
some sink, typically a streamformatter. This package is of little use to
API clients as this package does not provide any facilities to consume
the progress updates.

Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-10-24 07:56:57 -05:00
Cory Snider
6baf274fa3 api/pkg/streamformatter: move to client and daemon/internal
Move the streamformatter package up into the client for a temporary
shared location between common clients like CLI and compose.

The streamformatter package is used by the daemon to write streams of
status and progress messages to API clients. It is completely out of
scope of the api module and not used outside the daemon. Remove the
unused rawSteamFormatter, whose purpose is to render the progress as a
TUI.

Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-10-24 07:56:51 -05:00
Paweł Gronowski
22016b516b Merge pull request #51024 from thaJeztah/custom_metaheaders
daemon/containerd: pass custom metaHeaders to resolver
2025-09-25 11:26:44 +00:00
Sebastiaan van Stijn
a32a53ae01 daemon/containerd: pass custom metaHeaders to resolver
Similar to how [distribution.newRepository] in the legacy distribution code
passes the (custom) http-headers. User-Agent is always set, and can't be
overridden, so we apply it after setting the custom headers.

[distribution.newRepository]: 9ce272f804/daemon/internal/distribution/registry.go (L74-L97)

Before this patch:

    docker run --rm -d --name debugger -p 127.0.0.1:5001:8080 mendhak/http-https-echo
    DOCKER_CUSTOM_HEADERS=X-Meta-Hello=thaJeztah docker pull localhost:5001/myimage:latest
    docker logs debugger
    ...
    "headers": {
        "host": "localhost:5001",
        "user-agent": "docker/dev go/go1.24.7 git-commit/8e89fe7e8cbb3048f640846590175cbae4719b25 kernel/6.10.14-linuxkit os/linux arch/arm64 containerd-client/2.1.4+unknown storage-driver/overlayfs UpstreamClient(Docker-Client/28.3.2 \\(linux\\))",
        "accept": "application/json, */*",
        "accept-encoding": "zstd;q=1.0, gzip;q=0.8, deflate;q=0.5",
        "baggage": "trigger=api"
    },

With this patch:

    docker run --rm -d --name debugger -p 127.0.0.1:5001:8080 mendhak/http-https-echo
    DOCKER_CUSTOM_HEADERS=X-Meta-Hello=thaJeztah docker pull localhost:5001/myimage:latest
    docker logs debugger
    ...
    "headers": {
        "host": "localhost:5001",
        "user-agent": "docker/dev go/go1.24.7 git-commit/8e89fe7e8cbb3048f640846590175cbae4719b25 kernel/6.10.14-linuxkit os/linux arch/arm64 containerd-client/2.1.4+unknown storage-driver/overlayfs UpstreamClient(Docker-Client/28.3.2 \\(linux\\))",
        "accept": "application/json, */*",
        "accept-encoding": "zstd;q=1.0, gzip;q=0.8, deflate;q=0.5",
        "baggage": "trigger=api",
        "x-meta-hello": "thaJeztah"
    },

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-23 11:42:10 +02:00
Sebastiaan van Stijn
2223b7f582 daemon/server/imagebackend: add PushOptions struct
The PushImage method for the ImageService used positional arguments for its
options, which made it more difficult to introduce new options. This patch
introduces a `PushOptions` struct to specify the options. As part of these
changes, the `platform` option was already adjusted to accept a slice of
platforms, which currently is not supported, but may be in the near future.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-23 09:57:22 +02:00
Derek McGowan
f74e5d48b3 Create github.com/moby/moby/v2 module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-31 10:13:29 -07:00
Derek McGowan
d00ecdc479 Move pkg/streamformatter to api/pkg/streamformatter
Signed-off-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-30 14:22:31 +02:00
Derek McGowan
66862e14d1 Move pkg/progress to api/pkg/progress
Signed-off-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-30 14:22:31 +02:00
Derek McGowan
afd6487b2e Create github.com/moby/moby/api module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-21 09:30:05 -07:00
Derek McGowan
0b2582dc8f Move internal/metrics to daemon/internal/metrics
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-06-27 14:25:45 -07:00
Matthieu MOREL
369c8f828e fix var-declaration from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-06-26 12:07:24 +00:00
Paweł Gronowski
987b8a88a6 c8d/push: Extract shared push logic
Just a refactor of the previous commit to reduce duplication.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-06-13 14:51:18 +02:00
Paweł Gronowski
d9e7b86de4 c8d/push: Fix fallback single-manifest push not creating a tag
After pushing the multi-platform index fails due to missing content, we
retry with the single-platform manifest. While the target descriptor was
changed for the second push, the actual target digested reference still
pointed to the original multi-platform index. Obviously, with the
fallback that didn't really work correctly, because the multi-platform
index is not pushed.

This commit fixes the issue by updating the target reference to point to
the single-platform manifest.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-06-13 14:31:34 +02:00
Matthieu MOREL
55da8ea276 daemon: replace uses of errdefs package
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-05-28 05:38:39 +00:00
Henry Wang
a7ef4a208d Fix multiarch image push tag for containerd snapshotter
Signed-off-by: Henry Wang <henwang@amazon.com>
2025-05-13 17:14:36 +00:00
Derek McGowan
6c73266a71 Add registry error handling for push and pull
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-09 14:19:27 -07:00
Paweł Gronowski
7acef8101e c8d/pull: Show progress for non-layer blobs
Use the same logic as push for determining whether a progress should be
shown for a blob.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-04-07 13:31:04 +02:00
Derek McGowan
0aa8fe0bf9 Update to containerd v2.0.2, buildkit v0.19.0-rc2
Update buildkit version to commit which uses 2.0

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-01-15 14:09:30 +01:00
Sebastiaan van Stijn
ee1a15a970 daemon: ImageService.LogImageEvent: pass through context
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-08 15:43:17 +01:00
Paweł Gronowski
438f5801e1 daemon/images: Move ImageActions to metrics
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-01-07 14:13:07 +01:00
Paweł Gronowski
90fef061ec daemon/c8d: Force c8dimages alias for containerd/images
Change all github.com/containerd/containerd/images imports to be
imported as `c8dimages`.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-12-19 18:39:43 +01:00
Paweł Gronowski
1ad78f00b1 daemon/c8d: Fix duplicate containerd/images import
Remove duplicate imports under different aliases

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-12-19 18:39:40 +01:00
Paweł Gronowski
96ef85272f c8d/pull: Show Extracting layer status
Before this patch, pull progress wouldn't show the `Extracting` layer
status which made the pull look like it got stuck when extracting a big
layer.

Use the `containerd.io/snapshot/cri.layer-digest` snapshot labels to
find a corresponding snapshot and check whether it's `active` or
`committed` to set the layer status accordingly.

Despite the `cri.` component in the label name, it's not CRI specific -
it only depends on the `snapshotters.AppendInfoHandlerWrapper`.

We _could_ also use the `Usage` snapshot method to query the exact
progress of the unpack, but it would be too expensive as the
implementation time complexity will be proportional to the snapshot size.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-12-12 19:01:04 +01:00
Sebastiaan van Stijn
cd551b936b daemon/containerd: getPushDescriptor: fix formatting of platform in errors
The platform was printed in its raw format, which didn't produce a very
readable output;

Before this change:

    $ docker image save --platform=linux/amd64 -o alpine_amd64.tar alpine:latest
    Error response from daemon: no suitable export target found for platform linux/amd64: no suitable image manifest found for platform {amd64 linux [] }

After this change:

    $ docker image save --platform=linux/amd64 -o alpine_amd64.tar alpine:latest
    Error response from daemon: no suitable export target found: image with reference alpine:latest was found but does not provide the specified platform (linux/amd64)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-11 17:16:29 +02:00
Paweł Gronowski
f143f4ec51 image/save&load: Support Platform parameter
Add `Platform` parameter that allows to select a specific platform to
save/load.

This is a breaking change to the Go client as it changes the signatures
of `ImageLoad` and `ImageSave`.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-09-11 19:44:35 +02:00
Paweł Gronowski
842c5c584e c8d/image: Add matchRequestedOrDefault
Refactor a pattern where a passed `*ocispec.Platform` was used to
create a platform matcher that matches the passed platform if not nil
and uses a default host platform otherwise into a separate function.

Also add some basic unit tests for its behavior.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-08-05 14:30:14 +02:00
Sebastiaan van Stijn
d0aa3eaccf Migrate to github.com/containerd/platforms module
Switch to use github.com/containerd/platforms module, because containerd's
platforms package has moved to a separate module. This allows updating the
platforms parsing independent of the containerd module itself.

The package in containerd is deprecated, but kept as an alias to provide
compatibility between codebases.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-02 21:20:29 +02:00
Sebastiaan van Stijn
5343c7b451 remove internal/compatcontext and use context instead
This internal package was added in f6e44bc0e8
to preserve compatibility with go1.20 and older. At the time, our vendor.mod
still had go1.18 as minimum version requirement (see [1]), which got updated to go1.20
in 16063c7456, and go1.21 in f90b03ee5d

The version of BuildKit we use already started using context.WithoutCancel,
without a fallback, so we no longer can provide compatibility with older
versions of Go, which makes our compatiblity package redundant.

This patch removes the package, and updates our code to use stdlib's context
instead.

[1]: f6e44bc0e8/vendor.mod (L7)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 13:29:39 +02:00
Paweł Gronowski
e2326c27b5 c8d/push: Fix wrong Originalindex descriptor in aux error
The target variable was already overwritten with the new value. Use the
original value instead.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 19:14:21 +02:00
Paweł Gronowski
68a63d0611 c8d/push: Extract missing content note to an Aux progress
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:14 +02:00
Paweł Gronowski
0a31437208 c8d/push: Support platform selection
Add a OCI platform fields as parameters to the `POST /images/{id}/push`
that allow to specify a specific-platform manifest to be pushed instead
of the whole image index.

When no platform was requested and pushing whole index failed, fallback
to pushing a platform-specific manifest with a best candidate (if it's
possible to choose one).

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:13 +02:00
Sebastiaan van Stijn
86f7762d48 vendor: github.com/containerd/containerd v1.7.18
Update to containerd 1.7.18, which now migrated to the errdefs module. The
existing errdefs package is now an alias for the module, and should no longer
be used directly.

This patch:

- updates the containerd dependency: https://github.com/containerd/containerd/compare/v1.7.17...v1.7.18
- replaces uses of the old package in favor of the new module
- adds a linter check to prevent accidental re-introduction of the old package
- adds a linter check to prevent using the "log" package, which was also
  migrated to a separate module.

There are still some uses of the old package in (indirect) dependencies,
which should go away over time.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-05 09:21:00 +02:00
Djordje Lukic
388ecf65bc c8d: Send push metrics to prom
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
2024-03-13 15:03:42 +01:00
Paweł Gronowski
74e2f23e1a daemon/c8d: Use i.images and i.content
Use `image.Store` and `content.Store` stored in the ImageService struct
instead of fetching it every time from containerd client.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-03-07 16:25:27 +01:00
Derek McGowan
755f008c1e Default the auth config domain to the target image domain
When server address is not provided with the auth configuration,
use the domain from the image provided with the auth.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-11-06 17:02:18 -08:00
Brian Goff
2f138d860e Merge pull request #46685 from rumpl/c8d-tag-does-not-exist
c8d: Return the "tag does not exist error"
2023-11-02 12:33:36 -07:00
Paweł Gronowski
cd95cd0671 c8d/push: Return error when repository has no tags
In case of `docker push -a`, we need to return an error if there is no
image for the given repository.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-10-30 10:55:08 +01:00
Djordje Lukic
8166818791 c8d: Return the "tag does not exist error"
In the tagged case the error message when the image/tag is not found
should be "tag does not exist: ref"

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
2023-10-20 16:55:20 +02:00
Djordje Lukic
0253fedf03 Merge pull request #46655 from vvoland/c8d-push-propagate-source-children
c8d/push: Set distribution source recursively
2023-10-19 10:30:47 +02:00
Paweł Gronowski
488559a330 c8d/push: Set distribution source recursively
After a successful push, all pushed blobs should have a
distribution.source label pointing to the new registry.

Before this commit, the label was only appended to the top-level blob
(manifest or manifest list). Adjust this to also do that recursively to
its children.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-10-16 17:07:39 +02:00
Paweł Gronowski
6040283f23 Merge pull request #46581 from vvoland/c8d-push-hide-jsons
c8d/push: Show progress only on blobs
2023-10-16 13:39:25 +02:00
Paweł Gronowski
42af8795a3 c8d/save: Implement exporting all tags
Implement a behavior from the graphdriver's export where `docker save
something` (untagged reference) would export all images matching the
specified repository.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-10-13 11:52:07 +02:00
Paweł Gronowski
44dbbeb196 c8d/progress: Remove unused mountable
It's no longer needed as we get this information from containerd
directly.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-10-12 11:08:11 +02:00
Sebastiaan van Stijn
cff4f20c44 migrate to github.com/containerd/log v0.1.0
The github.com/containerd/containerd/log package was moved to a separate
module, which will also be used by upcoming (patch) releases of containerd.

This patch moves our own uses of the package to use the new module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-11 17:52:23 +02:00
Djordje Lukic
f3aa9e151d c8d: Simplify error handling and distribution source label
Extract the distribution source label append into its own function and
make it not fail on any error, we do still log the error.

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
2023-10-10 14:13:34 +02:00
Paweł Gronowski
6f27bef9fc daemon/c8d: Use non cancellable context in defers
Fixes leases not being released when operation was cancelled.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-10-03 15:27:40 +02:00
Paweł Gronowski
77f7c83114 c8d/push: Show progress only on blobs
To match the graphdriver's push behavior which only shows the progress
for layers.
Exclude indexes, manifests and image configs from the push progress.
Don't explicitly check for `IsLayerType` to also handle other
potentially big blobs (like buildkit attestations).

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-10-03 14:59:19 +02:00
Bjorn Neergaard
8cd5f04ea3 daemon/c8d: use new containerd LabelDistributionSource constant
Introduced in dd3eedf3c3

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
2023-09-21 14:18:42 -06:00