moby--moby/integration-cli
Sebastiaan van Stijn 010adeec55
Builder: print relative path if COPY/ADD source path was not found
Before this change, the error returned to the user would include the physical
path inside the tmp dir on the daemon host. These paths should be considered
an implementation detail, and provide no value to the user. Printing the tmp
path can confuse users, and will be even more confusing if the daemon is running
remotely (or in a VM, such as on Docker Desktop), in which case the path in the
error message does not exist on the local machine;

    echo -e "FROM busybox\nCOPY /some/non-existing/file.txt ." | DOCKER_BUILDKIT=0 docker build -f- .

    Sending build context to Docker daemon   1.57kB
    Step 1/2 : FROM busybox
     ---> 1c35c4412082
    Step 2/2 : COPY /some/non-existing/file.txt .
    COPY failed: stat /var/lib/docker/tmp/docker-builder405687992/some/non-existing/file.txt: no such file or directory

When copying files from an image or a build stage, using `--from`, the error
is similarly confusing:

    echo -e "FROM busybox\nCOPY --from=busybox /some/non-existing/file.txt ." | DOCKER_BUILDKIT=0 docker build -f- .
    Sending build context to Docker daemon  4.671kB
    Step 1/2 : FROM busybox
     ---> 018c9d7b792b
    Step 2/2 : COPY --from=busybox /some/non-existing/file.txt .
    COPY failed: stat /var/lib/docker/overlay2/ef34239c80526c779b7afaeaedbf11c1b201d7f7681d45613102c4541da0e156/merged/some/non-existing/file.txt: no such file or directory

This patch updates the error messages to be more user-friendly. Changes are slightly
different, depending on if the source was a local path, or an image (or build-stage),
using `--from`.

If `--from` is used, only the path is updated, and we print the relative path
instead of the full path;

    echo -e "FROM busybox\nCOPY --from=busybox /some/non-existing/file.txt ." | DOCKER_BUILDKIT=0 docker build -f- .
    Sending build context to Docker daemon  1.583kB
    Step 1/2 : FROM busybox
     ---> 018c9d7b792b
    Step 2/2 : COPY --from=busybox /some/non-existing/file.txt .
    COPY failed: stat some/non-existing/file.txt: file does not exist

In other cases, additional information is added to mention "build context" and
".dockerignore", which could provide the user some hints to find the problem:

    echo -e "FROM busybox\nCOPY /some/non-existing/file.txt ." | DOCKER_BUILDKIT=0 docker build -f- .
    Sending build context to Docker daemon  1.583kB
    Step 1/2 : FROM busybox
     ---> 018c9d7b792b
    Step 2/2 : COPY /some/non-existing/file.txt .
    COPY failed: file not found in build context or excluded by .dockerignore: stat some/non-existing/file.txt: file does not exist

    echo -e "FROM busybox\nADD /some/non-existing/file.txt ." | DOCKER_BUILDKIT=0 docker build -f- .
    Sending build context to Docker daemon  1.583kB
    Step 1/2 : FROM busybox
     ---> 018c9d7b792b
    Step 2/2 : ADD /some/non-existing/file.txt .
    ADD failed: file not found in build context or excluded by .dockerignore: stat some/non-existing/file.txt: file does not exist

This patch only improves the error for the classic builder. Similar changes could
be made for BuildKit, which produces equally, or even more confusing errors;

    echo -e "FROM busybox\nCOPY /some/non-existing/file.txt ." | DOCKER_BUILDKIT=1 docker build -f- .
    [+] Building 1.2s (6/6) FINISHED
     => [internal] load build definition from Dockerfile                 0.0s
     => => transferring dockerfile: 85B                                  0.0s
     => [internal] load .dockerignore                                    0.0s
     => => transferring context: 2B                                      0.0s
     => [internal] load metadata for docker.io/library/busybox:latest    1.2s
     => [internal] load build context                                    0.0s
     => => transferring context: 2B                                      0.0s
     => CACHED [1/2] FROM docker.io/library/busybox@sha256:4f47c01...    0.0s
     => ERROR [2/2] COPY /some/non-existing/file.txt .                   0.0s
    ------
     > [2/2] COPY /some/non-existing/file.txt .:
    ------
    failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount181923793/some/non-existing:
    lstat /var/lib/docker/tmp/buildkit-mount181923793/some/non-existing: no such file or directory

    echo -e "FROM busybox\nCOPY --from=busybox /some/non-existing/file.txt ." | DOCKER_BUILDKIT=1 docker build -f- .
    [+] Building 2.5s (6/6) FINISHED
     => [internal] load build definition from Dockerfile                        0.0s
     => => transferring dockerfile: 100B                                        0.0s
     => [internal] load .dockerignore                                           0.0s
     => => transferring context: 2B                                             0.0s
     => [internal] load metadata for docker.io/library/busybox:latest           1.2s
     => FROM docker.io/library/busybox:latest                                   1.2s
     => => resolve docker.io/library/busybox:latest                             1.2s
     => CACHED [stage-0 1/2] FROM docker.io/library/busybox@sha256:4f47c01...   0.0s
     => ERROR [stage-0 2/2] COPY --from=busybox /some/non-existing/file.txt .   0.0s
    ------
     > [stage-0 2/2] COPY --from=busybox /some/non-existing/file.txt .:
    ------
    failed to compute cache key: failed to walk /var/lib/docker/overlay2/2a796d91e46fc038648c6010f062bdfd612ee62b0e8fe77bc632688e3fba32d9/merged/some/non-existing:
    lstat /var/lib/docker/overlay2/2a796d91e46fc038648c6010f062bdfd612ee62b0e8fe77bc632688e3fba32d9/merged/some/non-existing: no such file or directory

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-17 12:03:18 +02:00
..
checker bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
cli bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
daemon bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
environment testutil: make testing packages public 2019-09-11 07:47:23 -05:00
fixtures run shfmt 2020-03-03 12:27:49 +09:00
requirement integration-cli: make testRequires() a Helper 2019-10-09 21:44:22 +02:00
testdata Clean some integration-cli/fixtures package/files 2018-04-16 10:48:58 +02:00
benchmark_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
check_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
daemon_swarm_hack_test.go rm-gocheck: run goimports to compile successfully 2019-09-09 21:06:12 +00:00
docker_api_attach_test.go Merge pull request #40595 from sfzhu93/GL_2_25 2020-05-08 16:00:52 +02:00
docker_api_build_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_build_windows_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_containers_test.go Merge pull request #41168 from thaJeztah/raise_minimum_memory_limit 2020-07-09 11:48:34 -07:00
docker_api_containers_windows_test.go Accept platform spec on container create 2020-03-20 16:10:36 -07:00
docker_api_exec_resize_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_exec_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_images_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_inspect_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_logs_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_api_network_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_stats_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_swarm_node_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_swarm_service_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_api_swarm_test.go Replace errors.Cause() with errors.Is() / errors.As() 2020-04-29 00:28:41 +02:00
docker_api_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_attach_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_attach_unix_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_build_test.go Builder: print relative path if COPY/ADD source path was not found 2020-08-17 12:03:18 +02:00
docker_cli_build_unix_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_by_digest_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_commit_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_cp_from_container_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_cp_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_cp_to_container_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_cp_to_container_unix_test.go Upgrading the versions of images in Dockerfile. 2020-06-30 12:24:06 +08:00
docker_cli_cp_utils_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_create_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_daemon_plugins_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_daemon_test.go fix TestDaemonNoSpaceLeftOnDeviceError for mips64le 2020-08-05 11:31:51 +08:00
docker_cli_events_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_events_unix_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_exec_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_exec_unix_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_external_volume_driver_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_health_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_history_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_images_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_import_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_info_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_info_unix_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_inspect_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_links_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_login_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_logout_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_logs_bench_test.go rm-gocheck: run goimports to compile successfully 2019-09-09 21:06:12 +00:00
docker_cli_logs_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_netmode_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_network_test.go Setup tests 2019-09-09 21:09:57 +00:00
docker_cli_network_unix_test.go Upgrading the versions of images in Dockerfile. 2020-06-30 12:24:06 +08:00
docker_cli_plugins_logdriver_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_plugins_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_port_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_proxy_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_prune_unix_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_ps_test.go Fix filter on expose and publish 2020-05-15 11:12:03 +02:00
docker_cli_pull_local_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_pull_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_push_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_registry_user_agent_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_restart_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_rmi_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_run_test.go Remove apt.dockerproject.org from test 2020-07-28 00:10:37 +02:00
docker_cli_run_unix_test.go Upgrading the versions of images in Dockerfile. 2020-06-30 12:24:06 +08:00
docker_cli_save_load_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_save_load_unix_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_search_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_service_create_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_service_health_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_service_logs_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_service_scale_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_sni_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_start_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_stats_test.go test: add buffer to prevent goroutine leak 2020-02-27 21:37:26 -05:00
docker_cli_swarm_test.go Fix TestSwarmManagerAddress to not depend on "pretty" format 2020-05-11 14:07:04 +02:00
docker_cli_swarm_unix_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_top_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_update_unix_test.go Set minimum memory limit to 6M, to account for higher startup memory use 2020-07-01 13:29:07 +02:00
docker_cli_userns_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_v2_only_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_cli_volume_test.go Accept platform spec on container create 2020-03-20 16:10:36 -07:00
docker_deprecated_api_v124_test.go Set minimum memory limit to 6M, to account for higher startup memory use 2020-07-01 13:29:07 +02:00
docker_deprecated_api_v124_unix_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_hub_pull_suite_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
docker_utils_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
events_utils_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
fixtures_linux_daemon_test.go Upgrading the versions of images in Dockerfile. 2020-06-30 12:24:06 +08:00
requirements_test.go integration-cli: make testRequires() a Helper 2019-10-09 21:44:22 +02:00
requirements_unix_test.go integration-cli: remove unused requirements utils 2019-07-08 18:58:46 +02:00
test_vars_noseccomp_test.go
test_vars_seccomp_test.go
test_vars_test.go Remove deprecated environment.DaemonPlatform() 2018-01-15 15:32:06 +01:00
test_vars_unix_test.go integration-cli: remove defaultSleepImage constant 2019-07-08 18:42:08 +02:00
test_vars_windows_test.go integration-cli: remove defaultSleepImage constant 2019-07-08 18:42:08 +02:00
utils_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00