3718 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
6505d3877c API: /info: remove BridgeNfIptables, BridgeNfIp6tables fields
The `BridgeNfIptables` and `BridgeNfIp6tables` fields in the
`GET /info` response were deprecated in API v1.48, and are now omitted
in API v1.50.

With this patch, old API version continue to return the field:

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIp6tables
    false

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIptables
    false

Omitting the field in API v1.50 and above

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.50/info | jq .BridgeNfIp6tables
    null

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.50/info | jq .BridgeNfIptables
    null

This reverts commit eacbbdeec6, and re-applies
a variant of 5d2006256f

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-16 19:49:52 +02:00
Sebastiaan van Stijn
735ccfbc6f pkg/stack: use t.TempDir
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-12 12:05:50 +02:00
Matthieu MOREL
70139978d3 fix(ST1016): Use consistent method receiver names
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-01 14:30:52 +02:00
Sebastiaan van Stijn
692610414a pkg/plugins: fix vars that shadowed (govet)
pkg/plugins/plugins.go:325:4: shadow: declaration of "pl" shadows declaration at line 315 (govet)
                pl, err := loadWithRetry(name, false)
                ^
    pkg/plugins/pluginrpc-gen/parser.go:153:4: shadow: declaration of "iface" shadows declaration at line 135 (govet)
                iface, ok := spec.Type.(*ast.InterfaceType)
                ^
    pkg/plugins/pluginrpc-gen/parser_test.go:61:2: shadow: declaration of "arg" shadows declaration at line 40 (govet)
        arg := f.Args[0]
        ^
    pkg/plugins/pluginrpc-gen/parser_test.go:165:2: shadow: declaration of "arg" shadows declaration at line 40 (govet)
        arg := f.Args[0]
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 15:42:06 +02:00
Sebastiaan van Stijn
d6b2aec809 pkg/progress: remove named err-return
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 14:15:19 +02:00
Sebastiaan van Stijn
029f267d9b pkg/pidfile: remove named err-returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 14:15:19 +02:00
Sebastiaan van Stijn
fdbf246889 pkg/parsers: remove named err-returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 14:15:18 +02:00
Sebastiaan van Stijn
b0f93d5283 pkg/fileutils: remove named err-returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 14:15:11 +02:00
Sebastiaan van Stijn
ab8e3da82c pkg/stdcopy: remove/rename err-returns
Prevent accidentally shadowing these errors, which are used in defers, and
while at it, also fixed some linting warnings about unhandled errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 14:14:51 +02:00
Sebastiaan van Stijn
d17a62592f pkg/ioutils: remove named err-returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 14:14:37 +02:00
Sebastiaan van Stijn
fd550344b1 vendor: github.com/moby/go-archive v0.1.0
full diff: https://github.com/moby/go-archive/compare/21f3f3385ab7...v0.1.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-16 13:00:13 +02:00
Sebastiaan van Stijn
eacbbdeec6 Revert "API: /info: remove BridgeNfIptables, BridgeNfIp6tables fields"
This reverts commit 5d2006256f, which
caused some issues in the docker/cli formatting code that needs some
investigating.

Let's (temporarily) revert this while we look what's wrong.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-11 14:47:10 +02:00
Sebastiaan van Stijn
5d2006256f API: /info: remove BridgeNfIptables, BridgeNfIp6tables fields
The `BridgeNfIptables` and `BridgeNfIp6tables` fields in the
`GET /info` response were deprecated in API v1.48, and are now omitted
in API v1.49.

With this patch, old API version continue to return the field:

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIp6tables
    false

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIptables
    false

Omitting the field in API v1.49 and above

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.49/info | jq .BridgeNfIp6tables
    null

    curl -s --unix-socket /var/run/docker.sock http://localhost/v1.49/info | jq .BridgeNfIptables
    null

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-10 14:26:42 +02:00
Derek McGowan
57a042b77c deprecate pkg/(chroot)archive for github.com/moby/go-archive
- pkg/archive: deprecate, and add aliases
  Keeping the tests in this commit; also moves various utilities
  into a _test.go file, as they were now only used in tests.
- pkg/chrootarchive: deprecate and add aliase
  deprecate pkg/archive and add aliases
  keeping the tests in this commit
- Add temporary exceptions for deprecation linting errors, because
  this commit is to verify everything works with the aliases.
- remove tests that depend on un-exported types

    === RUN   TestDisablePigz
    --- FAIL: TestDisablePigz (0.00s)
    panic: interface conversion: io.Reader is *archive.readCloserWrapper, not *archive.readCloserWrapper (types from different packages) [recovered]

- pkg/archive, pkg/chrootarchive: remove test files

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-08 10:56:58 -07:00
Sebastiaan van Stijn
c95e17638f Merge pull request #49757 from thaJeztah/archive_fix_linting
pkg/archive: fix linting issues
2025-04-07 10:18:03 +02:00
Sebastiaan van Stijn
b3791dea92 pkg/archive: fix linting issues
fix "struct literal uses unkeyed fields" (govet)

    pkg/archive/changes_test.go:123:18: composites: github.com/docker/docker/pkg/archive.Change struct literal uses unkeyed fields (govet)
        modifyChange := Change{"change", ChangeModify}
                        ^
    pkg/archive/changes_test.go:128:15: composites: github.com/docker/docker/pkg/archive.Change struct literal uses unkeyed fields (govet)
        addChange := Change{"change", ChangeAdd}
                     ^
    ...

fix various variables that shadowed types

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-07 08:48:53 +02:00
Sebastiaan van Stijn
a427477220 pkg/idtools: MkdirAllAndChownNew: improve deprecation message
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-06 13:02:52 +02:00
Sebastiaan van Stijn
6422ff2804 deprecate pkg/atomicwriter, migrate to github.com/moby/sys/atomicwriter
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-04 23:07:00 +02:00
Sebastiaan van Stijn
d7b743b856 Merge pull request #49741 from thaJeztah/atomicwriter_stricter_validate
pkg/atomicwriter: disallow symlinks for now, add more tests and touch-up GoDoc
2025-04-04 20:11:23 +02:00
Sebastiaan van Stijn
f1ec5bf14f pkg/idtools: remove tests already covered in moby/sys/user
Removes all tests, except for TestGetRootUIDGID and TestToContainer, which
are the only once that have a local implementation that's not covered.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-04 08:24:09 -07:00
Derek McGowan
3fc36bcac4 Update daemon to use moby sys/user identity mapping
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-04 08:24:09 -07:00
Derek McGowan
b5c99c0e95 Update moby/sys/user to version which includes mapping
Update idtools to use Mkdir funcs from moby sys/user package
Add deprecation exception to golanci until move off idtools is complete

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-04 08:22:05 -07:00
Sebastiaan van Stijn
c6cdfbf495 pkg/atomicwriter: return early if parent directory is invalid
Rewrite `validateDestination` to first check if the destination path
exists. This slightly simplifies the logic (allowing returning
early in each step of the validation) and slightly improves the
error produced.

Before this, the error confusingly would mention the full path
not being a directory. While this _does_ match what `os.Writefile`
would return, it's .. confusing:

    failed to stat output path: lstat ./not-a-dir/new-file.txt: not a directory

After this, the error would mention the directory that doesn't exist:

    invalid output path: stat ./not-a-dir: not a directory

A slight optimization is made as well, now checking for _both_ "."
and ".." as special case, as either path should exist given any current
working directory (unless the working directory has been deleted, but we'd
fail further down the line).

With this change in order, we can also merge `validateFileMode` into
`validateDestination`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-03 21:57:13 +02:00
Sebastiaan van Stijn
00c988caa4 pkg/atomicwriter: add test for parent dir not being a directory
While the target-file does not have to exist, its parent must, and must
be a directory. This adds a test-case to verify the behavior if the
parent is not a directory.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-03 21:39:33 +02:00
Sebastiaan van Stijn
ad386f64e5 pkg/atomicwriter: error on unknown file-modes
Previously, we were silently discarding this situation and hoping that
it would work; let's produce an error instead (we can add additional
filemodes when they arrive and if we need them)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-03 21:39:32 +02:00
Sebastiaan van Stijn
ec82bc35c3 pkg/atomicwriter: disallow symlinked files for now
The implementation uses "os.Rename" to move the temporary file to
the destination, which does not follow symlinks, and because of this
would replace a symlink with a file.

We can consider adding support for symlinked files in future, so that
WriteFile can be used as a drop-in replacement for `os.WriteFile()`
but in the meantime, let's produce an error so that nobody can depend
on this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-03 21:39:32 +02:00
Sebastiaan van Stijn
f3aebbf9d8 pkg/atomicwriter: add basic godoc for package
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-03 21:39:21 +02:00
Sebastiaan van Stijn
be6e92a57b pkg/atomicwriter: use sequential file access on Windows
Using sequential file access ([FILE_FLAG_SEQUENTIAL_SCAN]) prevents
Windows from aggressively keeping files in the cache, freeing up system
memory for other tasks. On Linux, these changes have no effect, as the
sequential package use the standard (os.CreateTemp, os.OpenFile) on
non-Windows platforms. Refer to the [Win32 API documentation] for details
on sequential file access.

[Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
[FILE_FLAG_SEQUENTIAL_SCAN]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-21 16:39:28 +01:00
Sebastiaan van Stijn
1daeaec333 pkg/atomicwriter: validate destination path
- Disallow empty filenames
- Don't allow writing to a directory
- Return early if parent dir doesn't exist
- TBD: do we want to allow symlinks to be followed, or disallow?

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-10 18:23:02 +01:00
Sebastiaan van Stijn
084b7cec1a pkg/atomicwriter: add additional test-cases
- test errors returned for non-existing destination
- test that files are cleaned up after
- test writing to a symlinked file (to be fixed)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-10 17:58:51 +01:00
Sebastiaan van Stijn
ff061e28c1 pkg/atomicwriter: don't overwrite destination on close without write
Creating a writer (`atomicwriter.New()`) and closing it without a write
ever happening, would replace the destination file with an empty file.

This patch adds a check whether a write was performed (either successful
or unsuccessful); if no write happened, we cleanup the tempfile without
replacing the destination file.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-10 17:58:46 +01:00
Sebastiaan van Stijn
88a5bca43c pkg/atomicwriter: add separate tests for New()
We were testing this function implicitly through `TestWriteFile`, but
not verifying the behavior of `New` in isolation. Add separate tests
for this function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-10 17:58:11 +01:00
Sebastiaan van Stijn
09e804f570 pkg/atomicwriter: refactor tests
- rename tests to match the function tested
- remove init func in favor or a test-helper
- rename some vars to prevent shadowing
- update example values to be more descriptive
- add a utility for asserting file content and mode

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-10 17:57:17 +01:00
Sebastiaan van Stijn
b22431ee9c pkg/atomicwriter: New(): use absolute path for temp-file
Use an absolute path for both the temp-file and the destination-file.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-09 15:00:00 +01:00
Sebastiaan van Stijn
58bd93a625 pkg/atomicwriter: New(): prevent creating temp-file on errors
The temp-file was created before trying to make the given filename an
absolute path. Reverse the order of code so that we don't create
a temp-file if an error happens.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-09 14:55:11 +01:00
Sebastiaan van Stijn
faa9cb125b pkg/tarsum: fix naked returns
pkg/tarsum/versioning.go:150:2: naked return in func `v1TarHeaderSelect` with 35 lines of code (nakedret)
        return
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-04 13:56:13 +01:00
Sebastiaan van Stijn
b5b514ab04 pkg/stdcopy: fix naked returns
pkg/stdcopy/stdcopy.go:68:2: naked return in func `Write` with 23 lines of code (nakedret)
        return
        ^
    pkg/stdcopy/stdcopy_test.go:93:3: naked return in func `getSrcBuffer` with 10 lines of code (nakedret)
            return
            ^
    pkg/stdcopy/stdcopy_test.go:97:2: naked return in func `getSrcBuffer` with 10 lines of code (nakedret)
        return
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-04 13:56:13 +01:00
Sebastiaan van Stijn
d3d84bde4b pkg/pools: fix naked returns
pkg/pools/pools.go:83:2: naked return in func `Copy` with 5 lines of code (nakedret)
        return
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-04 13:56:13 +01:00
Sebastiaan van Stijn
52b8298975 pkg/chrootarchive: remove unused named return
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-04 13:56:13 +01:00
Sebastiaan van Stijn
b38f0dd804 pkg/archive: fix naked returns, output variables in tests
pkg/archive/copy_unix_test.go:54:3: naked return in func `fileContentsEqual` with 35 lines of code (nakedret)
            return
            ^
    pkg/archive/copy_unix_test.go:60:3: naked return in func `fileContentsEqual` with 35 lines of code (nakedret)
            return
            ^
    pkg/archive/copy_unix_test.go:67:3: naked return in func `fileContentsEqual` with 35 lines of code (nakedret)
            return
            ^
    pkg/archive/copy_unix_test.go:74:3: naked return in func `fileContentsEqual` with 35 lines of code (nakedret)
            return
            ^
    pkg/archive/copy_unix_test.go:83:2: naked return in func `fileContentsEqual` with 35 lines of code (nakedret)
        return
        ^
    pkg/archive/diff_test.go:314:3: naked return in func `makeTestLayer` with 35 lines of code (nakedret)
            return
            ^
    pkg/archive/diff_test.go:326:5: naked return in func `makeTestLayer` with 35 lines of code (nakedret)
                    return
                    ^
    pkg/archive/diff_test.go:330:5: naked return in func `makeTestLayer` with 35 lines of code (nakedret)
                    return
                    ^
    pkg/archive/diff_test.go:336:3: naked return in func `makeTestLayer` with 35 lines of code (nakedret)
            return
            ^
    pkg/archive/copy_unix_test.go:36:2: naked return in func `getTestTempDirs` with 10 lines of code (nakedret)
        return
        ^
    pkg/stdcopy/stdcopy_test.go:93:3: naked return in func `getSrcBuffer` with 10 lines of code (nakedret)
            return
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-04 13:56:13 +01:00
Sebastiaan van Stijn
d59a9d9b10 pkg/archive: fix naked returns, output variables
pkg/archive/archive_linux.go:65:2: naked return in func `ConvertWrite` with 43 lines of code (nakedret)
        return
        ^
    pkg/archive/archive.go:265:2: naked return in func `Read` with 11 lines of code (nakedret)
        return
        ^
    pkg/archive/copy.go:32:2: naked return in func `copyWithBuffer` with 5 lines of code (nakedret)
        return
        ^
    pkg/archive/copy.go:114:3: naked return in func `TarResourceRebase` with 16 lines of code (nakedret)
            return
            ^
    pkg/archive/copy.go:449:4: naked return in func `ResolveHostSourcePath` with 26 lines of code (nakedret)
                return
                ^
    pkg/archive/copy.go:460:4: naked return in func `ResolveHostSourcePath` with 26 lines of code (nakedret)
                return
                ^
    pkg/archive/wrap.go:58:2: naked return in func `parseStringPairs` with 11 lines of code (nakedret)
        return
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-04 13:56:08 +01:00
Sebastiaan van Stijn
6ee1558852 Merge pull request #49417 from thaJeztah/fix_linting_step1
Fix linting issues to allow enabling more linters
2025-02-13 23:58:24 +01:00
Sebastiaan van Stijn
bd13fc37b0 pkg/jsonmessage: JSONMessage: fix deprecation of ProgressMessage, ErrorMessage
- ErrorMessage was deprecated in 3043c26419
  which was part of docker v0.6.0 / API v1.4
- ProgressMessage was deprecated in 597e0e69b4
  which was part of docker v0.7.1 / API v1.8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-11 15:40:37 +01:00
Sebastiaan van Stijn
07e2fc83ae pkg/plugins: fix "Multiplication of durations" (durationcheck)
Change some variables to a time.Duration to reduce conversions between
integers and durations, which also makes the code slightly more transparent.

    pkg/plugins/client_test.go:109:9: Multiplication of durations: `tc.expTimeOff * time.Second` (durationcheck)
                s := tc.expTimeOff * time.Second
                     ^
    pkg/plugins/client_test.go:132:9: Multiplication of durations: `tc.timeOff * time.Second` (durationcheck)
                s := tc.timeOff * time.Second
                     ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:48 +01:00
Sebastiaan van Stijn
1ffbcb566b pkg/jsonmessage: fix "Multiplication of durations" (durationcheck)
pkg/jsonmessage/jsonmessage.go:111:10: Multiplication of durations: `(left / time.Second) * time.Second` (durationcheck)
            left = (left / time.Second) * time.Second
                   ^

This code was rounding down time remaining to the nearest second;

- Use go's time.Duration.Round() instead
- Make the calculation conditional, as it was only used if there's enough
  space available to print
- Move the declaration of the timeLeftBox var closer to where used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:48 +01:00
Sebastiaan van Stijn
09c5a01346 pks/plugins/pluginrpc-gen: fix unused value assign (wastedassign)
pkg/plugins/pluginrpc-gen/parser_test.go:80:2: assigned to arg, but reassigned without using the value (wastedassign)
        arg = f.Args[0]
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:48 +01:00
Sebastiaan van Stijn
0bf8c8b99e pkg/tailfile: avoid allocations with (*os.File).WriteString (mirror)
pkg/tailfile/tailfile_test.go:149:16: avoid allocations with (*os.File).WriteString (mirror)
            if _, err := f.Write([]byte("tailfile pretty interesting line\n")); err != nil {
                         ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:47 +01:00
Sebastiaan van Stijn
4e6c91cc56 pkg/pools: avoid allocations with (*bufio.Writer).WriteString (mirror)
pkg/pools/pools_test.go:100:18: avoid allocations with (*bufio.Writer).WriteString (mirror)
        written, err := writer.Write([]byte("foobar"))
                        ^
    pkg/pools/pools_test.go:112:14: avoid allocations with (*bufio.Writer).WriteString (mirror)
        if _, err = writer.Write([]byte("barfoo")); err != nil {
                    ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:47 +01:00
Sebastiaan van Stijn
f0a233bdc3 pkg/archive: avoid allocations with strings.Compare (mirror)
pkg/archive/changes_linux.go:146:10: avoid allocations with strings.Compare (mirror)
            switch bytes.Compare([]byte(ni1.name), []byte(ni2.name)) {
                   ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:47 +01:00
Sebastiaan van Stijn
192431cb35 pkg/idtools: un-deprecate Windows consts for now
These consts were deprecated in 9c368a93b6, but are
used externally and lack a canonical location. These sids are "special", as they
are available by default in Windows containers, but we need to;

- Reference official documentation / specification for that.
- Add names (not just the sid)
- Consider finding a canonical location for these consts, which could be as part
  of the OCI specs, or hcsshim (or otherwise).

Lacking a good place for these, let's un-deprecate them for the time being until
we decided what's the best location for these.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-06 17:30:35 +01:00