Commit Graph

1803 Commits

Author SHA1 Message Date
55e404e7a8 cli/command/system: remove netfilter warnings from tests
These warnings will no longer be returned by the daemon, so remove
them from the tests as well to make them more representative of
reality.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-13 10:29:01 +01:00
6a2cde6c75 Add option '--ipv4'
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-10 15:51:21 +00:00
e554bfef6c Merge pull request #5662 from laurazard/consistent-attach-check
run: correctly handle only STDIN attached
2024-12-09 18:01:45 +01:00
30c4637f03 run: don't hang if only attaching STDIN
If STDOUT or STDERR are attached and the container exits, the streams
will be closed by the daemon while the container is exiting, causing
the streamer to return an error
61b02e636d/cli/command/container/hijack.go (L53)
that gets sent
61b02e636d/cli/command/container/run.go (L278)
and received
61b02e636d/cli/command/container/run.go (L225)
on `errCh`.

However, if only STDIN is attached, it's not closed (since this is
attached to the user's TTY) when the container exits, so the streamer
doesn't exit and nothing gets sent on `errCh`, meaning the CLI execution
hangs receiving on `errCh` on L231.

Change the logic to receive on both `errCh` and `statusChan` – this way,
if the container exits, we get notified on `statusChan` (even if only
STDIN is attached), and can cancel the streamer and exit.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-12-09 15:49:20 +00:00
b51a71148f cli/command/system: don't use "non-distributable-artifacts" fields in tests
Nondistributable artifacts are deprecated, and no longer used; we'll be
deprecating these fields, so let's already skip their use.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-07 12:24:59 +01:00
66dfe6d428 Merge pull request #5664 from akerouanton/gw-priority
run, create, connect: add support for gw-priority
2024-12-06 22:20:57 +01:00
e398d16c04 cli/command/registry: return status only instead of whole response
Various functions were passing through the API response as a whole, but
effectively only needed it for a status message (if any). Reduce what's
returned to only the message.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-03 19:04:24 +01:00
297afb2a2b cli/command/registry: TestLoginWithCredStoreCreds slight refactor
- also check errors that were previously not handled
- use the fakeCLI's buffer instead of creating one manually

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-03 18:42:40 +01:00
575e373669 cli/command/registry: rename some vars that collided with imports
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-03 18:37:35 +01:00
d4db289eb5 run, create, connect: add support for gw-priority
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-03 15:13:08 +01:00
cf89afb32b cli/command/registry: storeCredentials: accept configfile as arg
This function only needs access to the configfile

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-03 13:00:59 +01:00
b5a00d0b0f cli/command/registry: loginWithRegistry: use shallower interface
This function only needs the API client, not all of the CLI.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-03 12:50:12 +01:00
13f0d46411 cli/command/registry: don't return creds on error
Be more explicit on not returning a response if there was an error;
change some non-exported functions to return a pointer, and return
nil instead.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-03 12:48:12 +01:00
a3d9fc4941 run: cleanup – remove errCh nil check
Now, if running in "detached" mode, we early exit at L222.

Similarly, if `attachContainer` errors out, it returns an error that
gets handled on L190.

As such, `errCh` can never be nil on L231. Remove the nil check.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-12-02 14:35:30 +00:00
446f36ce58 run: cleanup – move "detached" early exit earlier
Since everything else after the `apiClient.ContainerStart` block is
under an `if attach` conditional, we can move the "detached" early exit
up.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-12-02 14:35:29 +00:00
8431298824 run: cleanup – use attached where applicable
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-12-02 14:34:28 +00:00
aee9eebf34 run: return error code when only STDIN attached
During a `docker run`, the CLI has some different behavior/output
depending on whether the run is "detached" or not.

In some cases, the CLI is checking whether either `stdin`, `stdout` or
`stderr` are attached, but in other cases we're only checking `stdout`
and `stderr`, which leads to some inconsistencies:

```
$ docker run -a stdout --rm --name test alpine top
[docker kill test]
exit status 137

$ docker run -a stderr --rm --name test alpine top
[docker kill test]
exit status 137

$ docker run -a stdin --rm --name test alpine top
56820d94a89b96889478241ae68920323332c6d4cf9b51ba9340cba01e9e0565
[docker kill test]
[no exit code]
```

Since we're not checking for whether `stdin` is attached when deciding
whether to early exit without receiving on `statusChan`, the `docker run
-a stdin` is falling into the "detached mode" logic, which simply prints
the container ID and doesn't print/return the exit code.

This patch makes the "attached" checks consistent.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-12-02 14:31:26 +00:00
30a73ff19c fix: ctx should cancel image pull on run
This patch fixes the context cancellation
behaviour for the `runContainer` function,
specifically the `createContainer` function
introduced in this commit 991b1303da.

It delays stripping the `cancel` from the context
passed into the `runContainer` function so that
the `createContainer` function can be cancelled
gracefully by a SIGTERM/SIGINT.

This is especially true when the requested image
does not exist and `docker run` needs to `pull`
the image before creating the container.

Although this patch does gracefully cancel
the `runContainer` function it does not address
the root cause. Some functions in the call path
are not context aware, such as `pullImage`.

Future work would still be necessary to ensure
a consistent behaviour in the CLI.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2024-11-28 09:53:04 +01:00
1d4a7ae082 tests: cleanup table test names
There's no need for `case=[xxx]` in table tests, Go does a good job of
formatting the test output and we're just adding the same information
for every test output line.

Previously:
```console
$ go test -count=1 -v -run=TestPromptForConfirmation ./cli/command
=== RUN   TestPromptForConfirmation
=== RUN   TestPromptForConfirmation/case=SIGINT
=== RUN   TestPromptForConfirmation/case=no
=== RUN   TestPromptForConfirmation/case=yes
=== RUN   TestPromptForConfirmation/case=any
=== RUN   TestPromptForConfirmation/case=with_space
=== RUN   TestPromptForConfirmation/case=reader_closed
--- PASS: TestPromptForConfirmation (0.00s)
    --- PASS: TestPromptForConfirmation/case=SIGINT (0.00s)
    --- PASS: TestPromptForConfirmation/case=no (0.00s)
    --- PASS: TestPromptForConfirmation/case=yes (0.00s)
    --- PASS: TestPromptForConfirmation/case=any (0.00s)
    --- PASS: TestPromptForConfirmation/case=with_space (0.00s)
    --- PASS: TestPromptForConfirmation/case=reader_closed (0.00s)
PASS
ok      github.com/docker/cli/cli/command       0.013s
```

After:
```console
go test -count=1 -v -run=TestPromptForConfirmation ./cli/command
=== RUN   TestPromptForConfirmation
=== RUN   TestPromptForConfirmation/SIGINT
=== RUN   TestPromptForConfirmation/no
=== RUN   TestPromptForConfirmation/yes
=== RUN   TestPromptForConfirmation/any
=== RUN   TestPromptForConfirmation/with_space
=== RUN   TestPromptForConfirmation/reader_closed
--- PASS: TestPromptForConfirmation (0.00s)
    --- PASS: TestPromptForConfirmation/SIGINT (0.00s)
    --- PASS: TestPromptForConfirmation/no (0.00s)
    --- PASS: TestPromptForConfirmation/yes (0.00s)
    --- PASS: TestPromptForConfirmation/any (0.00s)
    --- PASS: TestPromptForConfirmation/with_space (0.00s)
    --- PASS: TestPromptForConfirmation/reader_closed (0.00s)
PASS
ok      github.com/docker/cli/cli/command       0.009s
```

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-11-27 16:46:34 +00:00
d41b80fafc vendor: github.com/docker/docker e5c2b5e10d68 (master, v28.0.0-dev)
full diff: 6ac445c42b...e5c2b5e10d

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-20 15:54:27 +01:00
cb2f95ceee Optimise docker stats to not require clearing the whole screen
Instead of clearing the whole screen and then writing the new stats,
we now write the new stats on top of the old text, and then clear
the remaining text.

This is a more efficient way to update the stats, as it avoids the
flickering that happens when the screen is cleared and rewritten.

Signed-off-by: Giedrius Jonikas <giedriusj1@gmail.com>
2024-11-16 15:29:57 +00:00
d1d5353269 cli/command/container: fix missing go:build tag
make shell
    make -C ./internal/gocompat/

    GO111MODULE=on go test -v
    # github.com/docker/cli/cli/command/container
    ../../cli/command/container/completion.go:37:28: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../cli/command/container/completion.go:82:25: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../cli/command/container/completion.go:92:27: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    FAIL	gocompat [build failed]

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-15 11:06:20 +01:00
4adbb18f1c Merge pull request #5580 from albers/container-completions
Improve Cobra completions for `run` and `create`
2024-11-14 16:58:54 +01:00
7c80e4f938 update go:build tags to use go1.22
commit 4a7b04d412 configured golangci-lint
to use go1.23 semantics, which enabled the copyloopvar linter.

go1.22 now creates a copy of variables when assigned in a loop; make sure we
don't have files that may downgrade semantics to go1.21 in case that also means
disabling that feature; https://go.dev/ref/spec#Go_1.22

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 12:38:18 +01:00
06260e68f3 Handle null completions with a default callback
Credits to thaJeztah

Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
4525fe37b4 Add completion for --volume-driver
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
db0ed1e216 Add completion for --cgroupns
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
2915749279 Add completion for --uts
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
3a2503fa43 Add completion for --log-driver and --log-opt
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
9a9ae231a9 Add completion for --security-opt
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
5f7c43e5e6 Add completion for --detach-keys
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
3292afe6e6 Add completion for --userns
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
5d709a8d9f Add completion for --ulimit
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
2d89339b34 Add completion for --storage-opt
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
ac7bde6f64 Add completion for --pid
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:55:59 +00:00
e513454244 Add completion for --link
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:35:34 +00:00
c555327f0b Add completion for --ipc
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:35:34 +00:00
b598ec8cdb Add completion for --attach
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:35:34 +00:00
761d76750c Share the container completions
Signed-off-by: Harald Albers <github@albersweb.de>
2024-11-08 15:35:34 +00:00
32b40deb46 cli/command/service: remove redundant capturing of loop vars (copyloopvar)
go1.22 and up now produce a unique variable in loops, tehrefore no longer
requiring to capture the variable manually;

    cli/command/service/update.go:1061:3: The copy of the 'for' variable "entry" can be deleted (Go 1.22+) (copyloopvar)
            entry := entry
            ^
    cli/command/service/update.go:1089:4: The copy of the 'for' variable "port" can be deleted (Go 1.22+) (copyloopvar)
                port := port
                ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-05 10:14:32 +01:00
78a7e15032 cli/command/container: remove redundant capturing of loop vars (copyloopvar)
go1.22 and up now produce a unique variable in loops, tehrefore no longer
requiring to capture the variable manually;

    cli/command/container/opts.go:765:3: The copy of the 'for' variable "n" can be deleted (Go 1.22+) (copyloopvar)
            n := n
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-05 10:14:32 +01:00
4a71ce02e6 cli/command/image: remove redundant capturing of loop vars (copyloopvar)
go1.22 and up now produce a unique variable in loops, tehrefore no longer
requiring to capture the variable manually;

    cli/command/image/tree.go:59:4: The copy of the 'for' variable "im" can be deleted (Go 1.22+) (copyloopvar)
                im := im
                ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-05 10:14:31 +01:00
67458f710d cli/command: remove redundant capturing of loop vars in tests (copyloopvar)
go1.22 and up now produce a unique variable in loops, tehrefore no longer
requiring to capture the variable manually;

    service/logs/parse_logs_test.go:50: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-05 10:14:30 +01:00
0b16070ae6 Buffer 'docker stats' text to avoid terminal flickering
This change reduces the flickering of the terminal when
running `docker stats` by buffering the formatted stats
text and printing it in one write.

Should also consume less CPU as we now only have to issue
a single syscall to write the stats text to the terminal.

Signed-off-by: Giedrius Jonikas <giedriusj1@gmail.com>
2024-10-31 11:23:57 +00:00
aa331e94cc Merge pull request #5579 from thaJeztah/remove_warning
cli/command/container: parse: remove client-side warning
2024-10-30 10:50:34 +01:00
1875d9fdcb Merge pull request #5538 from albers/completion-events--filter
Completion for `events --filter`
2024-10-29 17:58:16 +01:00
e1c5180dba Add tests for completions that call the API
Signed-off-by: Harald Albers <github@albersweb.de>
2024-10-29 15:58:17 +00:00
d4f4cf1418 Add completion for events --filter
Signed-off-by: Harald Albers <github@albersweb.de>
2024-10-29 15:58:17 +00:00
59b90305f7 cli/command/container: parse: remove client-side warning
remove a client-side warning about volume drivers combined with "mounts"
in favor of producing the warning on the daemon side.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-28 23:13:31 +01:00
e9ae9f788b docker inspect: add support for swarm configs
The docker inspect command did not inspect configs. This patch adds support for
it, and while at it, also sorts the list of objects in runInspect.

Before this patch:

    docker config create myconfig ./codecov.yml
    danpeyh8qzb30vgdj9fr665l1

    docker inspect --format='{{.ID}}' myconfig
    []
    Error: No such object: myconfig

    docker inspect --format='{{.ID}}' --type=config myconfig
    "config" is not a valid value for --type

With this patch:

    docker inspect --format='{{.ID}}' myconfig
    danpeyh8qzb30vgdj9fr665l1

    docker inspect --format='{{.ID}}' --type=config myconfig
    danpeyh8qzb30vgdj9fr665l1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-24 18:32:32 +02:00