Skip to content

Commit 8b8786c

Browse files
authored
Create parent directories for Windows container image (#313)
Most container runtimes, including containerd and Moby (aka Docker) with Linux images will accept tar files where directory entries are missing. ``` -rwxr-xr-x 0/0 117 1970-01-01 01:00 app/bb_storage.repo_mapping -rwxr-xr-x 0/0 49701048 1970-01-01 01:00 app/bb_storage hrwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.runfiles/_repo_mapping link to app/bb_storage.repo_mapping hrwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.runfiles/_main/cmd/bb_storage/bb_storage_/bb_storage link to app/bb_storage ``` If a file like `app/bb_storage.repo_mapping` is extracted, any missing parent directories are created during extraction (but before the file is created): https://github.com/containerd/containerd/blob/dea7da592f5d1d2b7755e3a161be07f43fad8f75/pkg/archive/tar.go#L268-L276 On Windows (at least with Moby), missing parent directories are never created: https://github.com/microsoft/hcsshim/blob/d97b376c86e77d0df1b94500350fd2625c516dbf/internal/wclayer/legacy.go#L694 For that reason we explicitly create those directories on Windows: ``` drwxr-xr-x 0/0 0 1970-01-01 01:00 app/ -rwxr-xr-x 0/0 117 1970-01-01 01:00 app/bb_storage.exe.repo_mapping -rwxr-xr-x 0/0 50391552 1970-01-01 01:00 app/bb_storage.exe drwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.exe.runfiles/ hrwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.exe.runfiles/_repo_mapping link to app/bb_storage.exe.repo_mapping drwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.exe.runfiles/_main/ drwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.exe.runfiles/_main/cmd/ drwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.exe.runfiles/_main/cmd/bb_storage/ drwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.exe.runfiles/_main/cmd/bb_storage/bb_storage_/ hrwxr-xr-x 0/0 0 1970-01-01 01:00 app/bb_storage.exe.runfiles/_main/cmd/bb_storage/bb_storage_/bb_storage.exe link to app/bb_storage.extracted ``` Note that it is generally better NOT to create parent directories, since any directories created in upper layers (like `/app` here) shadow potential directory contents of lower layers. Long term, we should probably fix tar extraction on Windows upstream.
1 parent 33893b3 commit 8b8786c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tools/container.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ def multiarch_go_image(name, binary):
2020
"@rules_go//go/platform:linux": {"app/" + binary_name: binary},
2121
"@rules_go//go/platform:windows": {"app/{}.exe".format(binary_name): binary},
2222
}),
23+
# Creating parent directories is not recommended
24+
# as the directory creation during layer extraction shadows layers
25+
# from parent directories instead of merging their contents.
26+
# On Windows, the extraction routine requires parent directories to exist.
27+
create_parent_directories = select({
28+
"@rules_go//go/platform:linux": "disabled",
29+
"@rules_go//go/platform:windows": "enabled",
30+
}),
2331
# Don't build un-transitioned images, as the default target
2432
# architecture might be unsupported For example when building on
2533
# linux-i386.

0 commit comments

Comments
 (0)