Commit Graph

614 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
e5c2b5e10d Merge pull request #48897 from thaJeztah/client_import_no_empties
client: ImageImport: omit empty query-parameters
2024-11-20 15:27:49 +01:00
Sebastiaan van Stijn
9c9eccfb23 client: support multiple platforms on save and load
We don't yet support this at the API level, so for now it returns
an error when trying to set multiple, but this makes sure that the
client types are already ready for this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-19 15:56:28 +01:00
Sebastiaan van Stijn
f303531757 client: ImageImport: omit empty query-parameters
Don't set query-parameters for options that weren't set.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-19 13:30:59 +01:00
Sebastiaan van Stijn
a333c2990f client: TestImageImport: use table-test, asserts, add platform test-case
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-18 15:14:33 +01:00
Sebastiaan van Stijn
2bab030d6c client: TestImageSave: use table-test, asserts, add platform test-case
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-18 14:56:55 +01:00
Sebastiaan van Stijn
1ea24b7be3 client: TestImageLoad: add test-case for platform
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-18 14:06:12 +01:00
Sebastiaan van Stijn
613538469b client: TestImageLoad: rewrite to use table-tests, use asserts
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-18 14:00:32 +01:00
Sebastiaan van Stijn
ce1a39ab34 client: remove redundant capturing of loop vars (copyloopvar)
client/client_test.go:91:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    client/client_test.go:326:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    client/client_test.go:481:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    client/image_list_test.go:183:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    client/image_push_test.go:163:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    client/image_tag_test.go:50:3: The copy of the 'for' variable "repo" can be deleted (Go 1.22+) (copyloopvar)
            repo := repo
            ^
    client/image_tag_test.go:61:3: The copy of the 'for' variable "repotag" can be deleted (Go 1.22+) (copyloopvar)
            repotag := repotag
            ^
    client/ping_test.go:114:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    client/request_test.go:53:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:12 +01:00
Sebastiaan van Stijn
e6e6f0cdca client: TestTLSCloseWriter: fix G112 Potential Slowloris Attack (gosec)
Not a real issue for tests, but easy to fix;

    client/hijack_test.go:23:34: G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:50:21 +01:00
Sebastiaan van Stijn
083d595286 client: TestImageHistory: add minimal test for platform
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-05 13:28:28 +01:00
Sebastiaan van Stijn
73fabd5a21 client: TestImageHistory: use fixture for JSON response
Use a fixture instead of encoding with the current definition of the type,
to make sure we don't regress if any changes are made in the type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-05 13:28:27 +01:00
Sebastiaan van Stijn
5cfd326aa4 client: Client.ImageHistory: don't decorate error twice
I forgot to include this patch in 96039276b6,
which introduced the encodePlatform, which already decorates the error to
have a `invalid platform:` prefix.

While updating, also be more explicit on no result being returned on error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-05 13:28:15 +01:00
Sebastiaan van Stijn
96039276b6 client: add utilities to encode platforms
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-31 20:40:27 +01:00
Sebastiaan van Stijn
8c3945c761 client: rename vars for consistency
We use "query" for this everywhere else in the client.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-31 13:50:33 +01:00
Sebastiaan van Stijn
1240301299 Merge pull request #48736 from laurazard/client-set-conn-timeout
client: prevent idle connections leaking FDs
2024-10-25 17:28:14 +02:00
Laura Brehm
5c72a95a30 client: prevent idle connections leaking FDs
Patch from af6ada910f

Without this change, if a long-lived process uses the client and creates
connections, these connections are not released and grow over time.

We can also look into addressing this issue from the server side, but it
doesn't hurt for the `client` package to have good defaults and not
cause this.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-10-23 16:14:10 +01:00
Sebastiaan van Stijn
7faaa3afa8 client: explicitly return zero-type on failures in prune functions
Mostly a "nit", but it makes it clearer that we're returning an empty result,
and not a (partially) propagated struct.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-21 11:29:59 +02:00
Sebastiaan van Stijn
abed0e1f97 client: ContainerResize, ContainerExecResize: don't overflow width/height
Mostly theoretical, but let's be correct here. It's worth noting that the API
(backend) accepts uint32, but container.ResizeOptions uses uint (uint64). We
could decide to add checks for this on the client side, or to change the
type (but that would be a breaking change).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 14:04:37 +02:00
Sebastiaan van Stijn
1b7c209de1 Merge pull request #48651 from thaJeztah/cleaner_buildopts
client: imageBuildOptionsToQuery: omit empty and default values from query
2024-10-16 17:34:11 +02:00
Sebastiaan van Stijn
5b149d3faa client: update link to API documentation
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-12 17:23:09 +02:00
Sebastiaan van Stijn
e06245a2a6 client: imageBuildOptionsToQuery: omit "default" networkmode
Both the classic builder and buildkit treat empty value and "default"
as equivalent;

classic builder: c9619248d0/builder/dockerfile/internals.go (L379-L386)
buildkit: c9619248d0/builder/builder-next/builder.go (L350-L356)

Before:

    DEBU[2024-10-12T11:30:47.716478170Z] Calling POST /v1.47/build?dockerfile=Dockerfile&networkmode=default&version=1  spanID=893f850bd8bda19d traceID=e7ab3b76fd7a9c27a7aa7b25f4528fb8

After:

    DEBU[2024-10-12T13:42:56.799531715Z] Calling POST /v1.47/build?dockerfile=Dockerfile&version=1  spanID=d37f36ca6325422e traceID=a5eb4637fc3d0acf56cbb6a0a1d4a5ca

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-12 16:06:43 +02:00
Sebastiaan van Stijn
b13cf4fc5f client: imageBuildOptionsToQuery: only send "rm" when disabling
The "rm" option was made the default in API version 1.12  in commit
b60d647172, so the query-parameter can be
omitted unless the user opted to disable removing intermediate containers.

Before:

    DEBU[2024-10-12T11:30:47.716478170Z] Calling POST /v1.47/build?dockerfile=Dockerfile&networkmode=default&rm=1&version=1  spanID=893f850bd8bda19d traceID=e7ab3b76fd7a9c27a7aa7b25f4528fb8

After:

    DEBU[2024-10-12T11:30:47.716478170Z] Calling POST /v1.47/build?dockerfile=Dockerfile&networkmode=default&version=1  spanID=893f850bd8bda19d traceID=e7ab3b76fd7a9c27a7aa7b25f4528fb8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-12 16:06:36 +02:00
Sebastiaan van Stijn
740798da34 client: imageBuildOptionsToQuery: omit empty values from query
Before:

    DEBU[2024-10-12T11:26:55.791312715Z] Calling POST /v1.47/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&target=&ulimits=%5B%5D&version=1  spanID=893f850bd8bda19d traceID=e7ab3b76fd7a9c27a7aa7b25f4528fb8

After:

    DEBU[2024-10-12T11:30:47.716478170Z] Calling POST /v1.47/build?dockerfile=Dockerfile&networkmode=default&rm=1&version=1  spanID=893f850bd8bda19d traceID=e7ab3b76fd7a9c27a7aa7b25f4528fb8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-12 15:20:29 +02:00
Sebastiaan van Stijn
5bdbc2f026 client: ContainerCreate: normalize CapAdd, CapDrop capabilities
Before this change, capabilities would be sent un-normalized, un-sorted,
and could contain duplicates;

    docker create --name foo --cap-add SYS_ADMIN --cap-add sys_admin --cap-add cap_sys_admin --cap-add ALL busybox
    docker container inspect --format '{{json .HostConfig.CapAdd }}' foo
    ["SYS_ADMIN","sys_admin","cap_sys_admin","ALL"]

After this change, capabilities are sent in their normalized form, sorted,
and with duplicates removed;

    docker create --name foo --cap-add SYS_ADMIN --cap-add sys_admin --cap-add cap_sys_admin --cap-add ALL busybox
    docker container inspect --format '{{json .HostConfig.CapAdd }}' foo
    ["ALL", "CAP_SYS_ADMIN"]

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-26 17:11:13 +02:00
Sebastiaan van Stijn
be248d18b5 client.ContainerCreate: use container.CreateRequest instead of local type
This function used a locally defined `configWrapper`, which was identical
to the `container.CreateRequest`, with the exception of `CreateRequest`
defining `omitempty` for HostConfig and NetworkingConfig, but this should
not impact our use as the same type is used to handle the request on the
daemon side.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-26 15:30:16 +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
ab075ecd10 image/history: Support Platform parameter
Add `Platform` parameter that allows to select a specific platform to
show the history for.

This is a breaking change to the Go client as it changes the signature
of `ImageHistory`.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-09-11 19:44:32 +02:00
Paweł Gronowski
050afe1e1a api/list: Expose manifests
Add `Manifests` field to `ImageSummary` which exposes all image
manifests (which includes other blobs using the image media type, like
buildkit attestations).

There's also a new `manifests` query field that needs to be set in order
for the response to contain the new information.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-08-07 13:48:54 +02:00
Sebastiaan van Stijn
fb18966aa5 api/types/container: InspectResponse: keep old name for embedded type
This is a follow-up to 1abc8f6158, which
moved the ContainerJSONBase to api/types/container, but also renamed it
to container.InspectBase. This field is embedded into the InspectResponse
type, which meant that renaming the type also implicitly renamed the
field when creating this type from a struct-literal.

While we're planning to merge these types (which would be a breaking
change for users constructing it through struct-literals), let's keep
it backward-compatible for now (other than deprecating the old names).

We can continue the other changes separately.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-03 17:14:03 +02:00
Sebastiaan van Stijn
1abc8f6158 api/types: move container-inspect types to api/types/container
This moves the `ContainerJSONBase`, `ContainerJSON` and `ContainerNode`
types to the api/types/container package and deprecates the old location.

- `ContainerJSONBase` was renamed to `InspectBase`
- `ContainerJSON` was rnamed to `InspectResponse`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-02 12:50:24 +02:00
Sebastiaan van Stijn
05b0e653dd api/types: move Container to api/types/container
This moves the `Container` type to the containere package, rename
it to `Summary`, and deprecates the old location.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-02 12:46:48 +02:00
Sebastiaan van Stijn
7053007f71 api/types: move ImageInspect and RootFS to api/types/image
This moves the `ImageInspect` and `RootFS` types to the image package,
and deprecates the old location.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-02 12:46:48 +02:00
Sebastiaan van Stijn
1fc9236119 api/types: deprecate ContainerJSONBase.Node, ContainerNode
The `Node` field and related `ContainerNode` type were used by the classic
(standalone) Swarm API. API documentation for this field was already removed
in 234d5a78fe (API 1.41 / docker 20.10), and
as the Docker Engine didn't implement these fields for the Swarm API, it
would always have been unset / nil.

Let's do a quick deprecation, and remove it on the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-25 18:47:59 +02:00
Paweł Gronowski
018d93decf Merge pull request #47961 from gtomitsuka/gabriel/data-races
client: Make version negotiation thread-safe
2024-06-20 13:55:10 +02:00
Sebastiaan van Stijn
91a2a574d7 api/types: rename container.StatsResponse to StatsResponseReader
commit 17c3269a37 moved the ContainerStats
type to the container package, and renamed it to StatsResponse. However,
this name is chosen poorly, as it documents it to be the response of
the API endpoint, but is more accurately a wrapper around a reader,
used to read a (stream of) StatsJSON. We want to change StatsJSON
to StatsResponse, as it's more consistent with other response types.

As 17c3269a37 did not make it into a
non-pre-release, we can still change this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 08:54:52 +02:00
Sebastiaan van Stijn
517fb0991e api/types/container: provide alias for github.com/docker/go-units.Ulimit
This type is included in various types used in the API, but comes from
a separate module. The go-units module may be moving to the moby org,
and it is yet to be decided if the Ulimit type is a good fit for that
module (which deals with more generic units, such as "size" and "duration"
otherwise).

This patch introduces an alias to help during the transition of this type
to it's new location. The alias makes sure that existing code continues
to work (at least for now), but we need to start updating such code after
this PR is merged.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 13:18:20 +02:00
Gabriel Tomitsuka
88e5e4cfb4 Prevent data race during version negotiation
Signed-off-by: Gabriel Tomitsuka <gabriel@tomitsuka.com>
2024-06-13 19:37:11 +00:00
Sebastiaan van Stijn
1513068d8c Merge pull request #47679 from vvoland/c8d-multiplatform-push
c8d/push: Support `--platform` switch
2024-06-10 18:38:47 +02:00
Sebastiaan van Stijn
a736d0701c Merge pull request #47936 from thaJeztah/api_types_container_types
api/types: move more types to sub-packages
2024-06-10 16:51:49 +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
6c2934f373 api/types: move ImageLoadResponse to api/types/image
This moves the type, but we should consider removing this type, and just
returning an io.ReadCloser

This type was added in 9fd2c0feb0c131d01d727d50baa7183b976c7bdc;

> Make docker load to output json when the response content type is json
> Swarm hijacks the response from docker load and returns JSON rather
> than plain text like the Engine does. This makes the API library to return
> information to figure that out.

However the "load" endpoint unconditionally returns JSON;
7b9d2ef6e5/api/server/router/image/image_routes.go (L248-L255)

Commit 96d7db665b made the response-type depend
on whether "quiet" was set, but this logic got changed in a follow-up
2f27632cde, which made the JSON response-type
unconditionally, but the output produced depend on whether"quiet" was set.

We should deprecated the "quiet" option, as it's really a client
responsibility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:25 +02:00
Sebastiaan van Stijn
eb675cce71 api/types: move ImageImportSource to api/types/image
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:25 +02:00
Sebastiaan van Stijn
f6cc76ceb9 api/types: move ImageSearchOptions to api/types/registry
Note that RequestPrivilegeFunc could not be referenced, as it would
introduce a circular import, so copying the definition instead.

Also combining the other search-related types in the package to be in
the same file.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
b5f15bc0aa api/types: move EventsOptions to api/types/events
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
ecb24afaaf api/types: move ImagesPruneReport to api/types/image
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
162ef4f8d1 api/types: move VolumesPruneReport to api/types/volume
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
17c3269a37 api/types: move ContainerStats to api/types/container
This is the response type; other types related to stats are left
for now, but should be moved (as well as utilities ported from
the CLI repository).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:22 +02:00
Sebastiaan van Stijn
fd1d8f323b api/types: move CopyToContainerOptions to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:20:47 +02:00
Sebastiaan van Stijn
47d7c9e31d api/types: move ContainerPathStat to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:20:45 +02:00
Sebastiaan van Stijn
db2f1acd5d api/types: move ContainersPruneReport to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:19:47 +02:00