Commit Graph

162 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
fe34e89992 layer: remove // import comments
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.

Remove these imports in preparation of migrating our code to become an
actual go module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-30 15:59:14 +02:00
Sebastiaan van Stijn
08c5ebe040 layer: use t.TempDir and minor cleanups
- Use strings.Cut
- Use strconv instead of fmt.Sprintf
- Rename vars that shadowed

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-12 14:35:21 +02:00
Sebastiaan van Stijn
f87dcbe350 layer: remove/rename err-returns and remove naked returns
- rename error-output variables to prevent shawdowing
- remove naked returns
- rename some (err) variables for clarity
- remove redundant assertNotDirectoryError utility

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-08 14:33:09 +02:00
Derek McGowan
d0154d3e59 Update to use github.com/moby/go-archive
Update use of idtools to moby/user for archive and other deprecated uses

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-08 17:35:05 -07: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
42ca9154e9 layer: remove StoreOptions.ExperimentalEnabled
I noticed that the only reason we kept this was so that we could produce
a more targeted error for the deprecated storage-driver plugins, but it's
very unlikely someone used those, and if they did, we already had the
"DOCKERD_DEPRECATED_GRAPHDRIVER_PLUGINS" added as requirement. Let's
just produce an error if that option is set (and remove that altogether in
a later release, but just that check doesn't add significant complexity).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-07 22:39:55 +01:00
Sebastiaan van Stijn
d34e1ff826 layer: remove StoreOptions.MetadataStorePathTemplate
This field was added to allow templating the storage-location of the storage
driver as part of a refactor in f5916b10ae.

In practice, the template is never customized, and always set to;
`/<data-root>/image/<driver-name>/layerdb`, where `<driver-name>` is
passed in by the driver.

This patch removes the field and its uses.

- 00ab386b5a/daemon/daemon.go (L1074-L1075)
- 00ab386b5a/integration/image/remove_unix_test.go (L50-L51)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-07 00:50:02 +01:00
Sebastiaan van Stijn
379b82862f layer: fix naked returns
layer/layer_store.go:524:4: naked return in func `CreateRWLayer` with 72 lines of code (nakedret)
                return
                ^
    layer/layer_store.go:534:3: naked return in func `CreateRWLayer` with 72 lines of code (nakedret)
            return
            ^
    layer/layer_store.go:537:3: naked return in func `CreateRWLayer` with 72 lines of code (nakedret)
            return
            ^
    layer/migration.go:19:3: naked return in func `ChecksumForGraphID` with 28 lines of code (nakedret)
            return
            ^
    layer/migration.go:25:3: naked return in func `ChecksumForGraphID` with 28 lines of code (nakedret)
            return
            ^
    layer/migration.go:36:3: naked return in func `ChecksumForGraphID` with 28 lines of code (nakedret)
            return
            ^
    layer/migration.go:40:3: naked return in func `ChecksumForGraphID` with 28 lines of code (nakedret)
            return
            ^
    layer/migration.go:43:2: naked return in func `ChecksumForGraphID` with 28 lines of code (nakedret)
        return
        ^
    layer/ro_layer.go:176:2: naked return in func `Read` with 13 lines of code (nakedret)
        return
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-04 13:55:45 +01:00
Laurent Goderre
8c58934106 Implement mount from image
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
2025-01-31 10:34:27 -05:00
Sebastiaan van Stijn
61aa1657f7 layerStore.registerWithDescriptor: improve logs for cleaning up cache
The debug log was slightly confusing, as it seemed the cleaning up failed,
but the log was intended to inform that cleaning up was started because
of an error.

Before this patch:

    DEBU[2025-01-18T12:29:52.717452919Z] Cleaning up layer 472e3e532da3945040a6224ba36d2befcfe250aeb53536868d23e5f617e34226: exit status 1: unpigz: skipping: <stdin>: corrupted -- incomplete deflate data

With this patch:

    DEBU[2025-01-18T13:01:45.307983471Z] Cleaning up cache layer after error           cache-id=c4d9f38bdf6d8fcb69bd130b89d34d1511b42f3644fc49c91e253eda648bd37a error="exit status 1: unpigz: skipping: <stdin>: corrupted -- incomplete deflate data\n"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-18 16:18:08 +01:00
Sebastiaan van Stijn
7864454792 pkg/ioutils: move atomic file-writers to a separate (pkg/atomicwriter) package
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-08 10:36:32 +01:00
Sebastiaan van Stijn
a0b84a34c2 layer: verifiedReadCloser.Read: fix shadowed variables (govet)
layer/ro_layer.go:167:6: shadow: declaration of "n" shadows declaration at line 164 (govet)
            if n, err := vrc.verifier.Write(p[:n]); err != nil {
               ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:54:53 +01:00
Sebastiaan van Stijn
5fd3cd2d77 layer: layerStore.deleteLayer(): remove redundant error-check
Commit e1ea911aba removed the error return from
.Size() and .DiffSize(), but forgot to remove this error-check.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-10 11:22:19 +02:00
Sebastiaan van Stijn
b56c58a860 layer: ignore G602: slice index out of range (gosec)
This looks to be a false positive;

    layer/layer.go:202:47: G602: slice index out of range (gosec)
            return createChainIDFromParent(ChainID(dgsts[0]), dgsts[1:]...)
                                                        ^
    layer/layer.go:205:69: G602: slice index out of range (gosec)
        dgst := digest.FromBytes([]byte(string(parent) + " " + string(dgsts[0])))
                                                                           ^
    layer/layer.go:206:53: G602: slice bounds out of range (gosec)
        return createChainIDFromParent(ChainID(dgst), dgsts[1:]...)
                                                           ^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-27 10:23:39 +02:00
Kir Kolyshkin
1c0dc8a94f layer: rm regexp use
Replace the regexp checking ID validity with a function. The benefits
are:

 - function is faster (up to 10x faster with less allocations);
 - no init overhead to compile the regexp;

Add a test case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-07-16 12:30:17 -07:00
Sebastiaan van Stijn
688301caf4 daemon/graphdriver: remove Capabilities, CapabilityDriver
Capabilities were implemented in aa96c3176b,
as part of work on an external graphdriver-plugin. Given that none of
the builtin graphdrivers use this option, and support for graphdriver-
plugins has been removed in 555dac5e14,
we can remove this functionality.

This patch:

- removes the CapabilityDriver interface, which has no implementations
- removes the Capabilities type
- layer: remove layerStore.useTarSplit. This field was previously set
  through the driver's Capabilities, but always enabled for the builtin
  graphdrivers,

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-08 18:23:21 -05:00
Sebastiaan van Stijn
c0dd5c18f6 Merge pull request #48081 from thaJeztah/gofumpt
do another run of gofumpt
2024-07-01 16:17:54 +02:00
Sebastiaan van Stijn
bb1b766ddb layer: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 23:18:48 +02:00
Sebastiaan van Stijn
84cabde357 daemon/graphdriver: deprecate GetDriver(), and remove its use
The exported function was only used in tests, and identical in use when
using New with a name provided. Deprecate it, and remove the uses of it
in our (integration-)tests.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 20:05:44 +02:00
Paweł Gronowski
47eebd718f Merge pull request #48072 from thaJeztah/remove_graphdriver_plugins
daemon/graphdriver: remove support for external graphdriver plugins
2024-06-27 19:53:32 +02:00
Sebastiaan van Stijn
555dac5e14 daemon/graphdriver: remove support for external graphdriver plugins
This is a follow-up to 6da604aa6a, which
deprecated external graphdriver plugins.

This patch removes the functionality; some warnings / errors are kept in
place, but can be removed in a follow-up release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 14:25:14 +02:00
Sebastiaan van Stijn
bc4991e443 layer: rename vars that shadowed imports
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 14:03:47 +02:00
Sebastiaan van Stijn
782fe1fe82 layer: ChecksumForGraphID: remove unused code for for migrating v1 layers
The only use is in `builder/builder-next/adapters/snapshot.EnsureLayer()`,
which always calls the function with an _empty_ `oldTarDataPath`;
7082aecd54/builder/builder-next/adapters/snapshot/layer.go (L81)

When called with an empty `oldTarDataPath`, this function was an alias for
`checksumForGraphIDNoTarsplit`, so let's make it that.

Note that this code was added in 500e77bad0, as
part of the migration from "v1" images to "v2" (content-addressable) images.

Given that the remaining code lives in a "migration" file, possibly more code
can be removed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-01-08 12:28:41 +01: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
Sebastiaan van Stijn
b2663a0f73 layer: format code with gofumpt
Formatting the code with https://github.com/mvdan/gofumpt

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-29 00:31:50 +02:00
Brian Goff
74da6a6363 Switch all logging to use containerd log pkg
This unifies our logging and allows us to propagate logging and trace
contexts together.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-06-24 00:23:44 +00:00
Sebastiaan van Stijn
ab35df454d remove pre-go1.17 build-tags
Removed pre-go1.17 build-tags with go fix;

    go mod init
    go fix -mod=readonly ./...
    rm go.mod

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-05-19 20:38:51 +02:00
Sebastiaan van Stijn
22f303e422 layer: NewStoreFromOptions(): include driver-name in error message
When reading through some bug reports, I noticed that the error-message for
unsupported storage drivers is not very informative, as it does not include
the actual storage driver. Some of these errors are used as sentinel errors
internally, so improving the error returned by graphdriver.New() may need
some additional work, but this patch makes a start by including the name
of the graphdriver (if set) in the error-message.

Before this patch:

    dockerd --storage-driver=foobar
    ...
    failed to start daemon: error initializing graphdriver: driver not supported

With this patch:

    dockerd --storage-driver=foobar
    ...
    failed to start daemon: error initializing graphdriver: driver not supported: foobar

It's worth noting that there may be code "in the wild" that perform string-
matching on this error (e.g. [balena][1]), which is why I included the name as a separate "component"
in the output, to allow matching parts of the error.

[1]: 3d5c77a466/lib/preload.ts (L34-L35)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-06 13:06:16 +01:00
Sebastiaan van Stijn
d131147a5c use errors.Is() to handle image store errors
The image store's used are an interface, so there's no guarantee
that implementations don't wrap the errors. Make sure to catch
such cases by using errors.Is.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-02 09:41:50 +01:00
Sebastiaan van Stijn
62344f515c layer: layerStore.registerWithDescriptor: rename var to prevent shadowing
This `err` is special (as described at the top of the function), but due
to its name is easy to overlook, which risks the chance of inadvertently
shadowing it.

This patch renames the variable to reduce the chance of this happening.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-25 13:36:57 +01:00
Sebastiaan van Stijn
0f7c9cd27e Remove uses of deprecated go-digest.NewDigestFromHex, go-digest.Digest.Hex
Both of these were deprecated in 55f675811a,
but the format of the GoDoc comments didn't follow the correct format, which
caused them not being picked up by tools as "deprecated".

This patch updates uses in the codebase to use the alternatives.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-08 16:42:13 +01:00
Sebastiaan van Stijn
1ffdac4502 layer: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-10-08 19:15:28 +02:00
Sebastiaan van Stijn
c3a5641132 layer: use strconv instead of fmt.Sprintf()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-10-08 19:15:28 +02:00
Sebastiaan van Stijn
8a2e1245d4 runconfig, oci, image, layer, distribution: fix empty-lines (revive)
runconfig/config_test.go:23:46: empty-lines: extra empty line at the start of a block (revive)
    runconfig/config_test.go:75:55: empty-lines: extra empty line at the start of a block (revive)

    oci/devices_linux.go:57:34: empty-lines: extra empty line at the start of a block (revive)
    oci/devices_linux.go:60:69: empty-lines: extra empty line at the start of a block (revive)

    image/fs_test.go:53:38: empty-lines: extra empty line at the end of a block (revive)
    image/tarexport/save.go:88:29: empty-lines: extra empty line at the end of a block (revive)

    layer/layer_unix_test.go:21:34: empty-lines: extra empty line at the end of a block (revive)

    distribution/xfer/download.go:302:9: empty-lines: extra empty line at the end of a block (revive)
    distribution/manifest_test.go:154:99: empty-lines: extra empty line at the end of a block (revive)
    distribution/manifest_test.go:329:52: empty-lines: extra empty line at the end of a block (revive)
    distribution/manifest_test.go:354:59: empty-lines: extra empty line at the end of a block (revive)

    registry/config_test.go:323:42: empty-lines: extra empty line at the end of a block (revive)
    registry/config_test.go:350:33: empty-lines: extra empty line at the end of a block (revive)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-28 01:58:52 +02:00
Cory Snider
9ce2b30b81 pkg/containerfs: drop ContainerFS type alias
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-09-23 16:56:53 -04:00
Cory Snider
e332c41e9d pkg/containerfs: alias ContainerFS to string
Drop the constructor and redundant string() type-casts.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-09-23 16:56:52 -04:00
Cory Snider
95824f2b5f pkg/containerfs: simplify ContainerFS type
Iterate towards dropping the type entirely.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-09-23 16:56:49 -04:00
Cory Snider
be4f4644a8 pkg/containerfs: drop Driver abstraction
The Driver abstraction was needed for Linux Containers on Windows,
support for which has since been removed.

There is no direct equivalent to Lchmod() in the standard library so
continue to use the containerd/continuity version.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-09-23 16:25:22 -04:00
Cory Snider
7014c0d65d pkg/containerfs: drop PathDriver abstraction
With LCOW support removed, there is no need to support non-native file
paths any longer.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-09-23 16:25:22 -04:00
Sebastiaan van Stijn
068ab51442 layer: layerstore.Cleanup(): improve some logging
Improve consistency for the logs, and remove a redundant log:

    time="2022-06-07T15:37:24.418470152Z" level=debug msg="found 0 orphan layers"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-06-21 13:34:03 +02:00
Sebastiaan van Stijn
0a3336fd7d Merge pull request #43366 from corhere/finish-identitymapping-refactor
Finish refactor of UID/GID usage to a new struct
2022-03-25 14:51:05 +01:00
Cory Snider
098a44c07f Finish refactor of UID/GID usage to a new struct
Finish the refactor which was partially completed with commit
34536c498d, passing around IdentityMapping structs instead of pairs of
[]IDMap slices.

Existing code which uses []IDMap relies on zero-valued fields to be
valid, empty mappings. So in order to successfully finish the
refactoring without introducing bugs, their replacement therefore also
needs to have a useful zero value which represents an empty mapping.
Change IdentityMapping to be a pass-by-value type so that there are no
nil pointers to worry about.

The functionality provided by the deprecated NewIDMappingsFromMaps
function is required by unit tests to to construct arbitrary
IdentityMapping values. And the daemon will always need to access the
mappings to pass them to the Linux kernel. Accommodate these use cases
by exporting the struct fields instead. BuildKit currently depends on
the UIDs and GIDs methods so we cannot get rid of them yet.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-03-14 16:28:57 -04:00
Sebastiaan van Stijn
c28a8e9cf7 layer: remove layerstore.setOS(), layerstore.getOS()
This removes the `setOS()` / `getOS()` functions from the layer store, which were
added in fc21bf280b and 0380fbff37
in support of LCOW.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-11 23:14:27 +01:00
Sebastiaan van Stijn
367cd41937 Merge pull request #43302 from thaJeztah/layer_remove_getwithoutlock
layers: remove layerStore.getWithoutLock()
2022-03-05 21:18:26 +01:00
Sebastiaan van Stijn
a0230f3d9a remove unneeded "digest" alias for "go-digest"
I think this was there for historic reasons (may have been goimports expected
this, and we used to have a linter that wanted it), but it's not needed, so
let's remove it (to make my IDE less complaining about unneeded aliases).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-04 14:49:42 +01:00
Sebastiaan van Stijn
82f96da04d layer: remove unused ErrActiveMount, ErrNotMounted, ErrNotSupported
These errors were added in 500e77bad0, but were
never used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-02 21:30:41 +01:00
Sebastiaan van Stijn
203fcd6997 layers: remove layerStore.getWithoutLock()
This function was abstracting things a bit too much; the layerStore had a
exported `.Get()` which called `.getWithoutLock()`, but also a non-exported
`.get()`, which also called `.getWithoutLock()`.

While it's common to have a non-exported variant (without locking), the naming
of `.get()` could easily be confused for that variant (which it wasn't).

All locations where `.get()` was called were already handling locks for
`releaseLayer()`, so moving the actual locking inline for `.get()` makes it
more visible where locking happens.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-28 19:57:37 +01:00
Sebastiaan van Stijn
32e5fe5099 Merge pull request #43182 from thaJeztah/layer_remove_unused_error
layer: remove unused error return from .Size() and .DiffSize()
2022-02-17 20:51:45 +01:00
Sebastiaan van Stijn
b36d896fce layer: remove OS from layerstore
This was added in commits fc21bf280b and
0380fbff37 in support of LCOW, but was
now always set to runtime.GOOS.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-01-25 15:23:23 +01:00
Sebastiaan van Stijn
e1ea911aba layer: remove unused error return from .Size() and .DiffSize()
None of the implementations used return an error, so removing the error
return can simplify using these.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-01-24 18:45:47 +01:00