Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is COPY/ADD supposed to work with files in subdirectories? #6847

Closed
srcshelton opened this issue Jul 2, 2020 · 6 comments
Closed

Is COPY/ADD supposed to work with files in subdirectories? #6847

srcshelton opened this issue Jul 2, 2020 · 6 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue

Comments

@srcshelton
Copy link
Contributor

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

I have a Dockerfile containing:

COPY subdirectory/file /destination/
RUN  ls -l /destination/file

... and I've found that the COPY directive succeeds, then the RUN command fails. Actually, it seems that the COPY (and ADD) directives can't handle subdirectories, but regardless succeed even though no file has been copied.

I've solved this by changing directory in my build script to effectively move the context folder one level deeper so that I can just do COPY file /destination (which works, for otherwise exactly the same setup).

But surely, either the COPY/ADD directives should copy the specified file/directory, or they should fail. They should not succeed without creating the intended files within the container (and if locating a source file in a subdirectory is disallowed, then it really should say so!)
Output of podman version:

Version:      2.0.0-rc6
API Version:  1
Go Version:   go1.14.2
Git Commit:   e74e84aa0637033c821955d817fca85f56a90d85
Built:        Mon Jun 29 01:04:58 2020
OS/Arch:      linux/amd64

(... still on 2.0.0_rc6 pending the resolution of #6785)

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.15.0-dev
  cgroupVersion: v1
  conmon:
    package: Unknown
    path: /usr/libexec/podman/conmon
    version: 'conmon version 2.0.17, commit: 41877362fc4685d55e0473d2e4a1cbe5e1debee0'
  cpus: 8
  distribution:
    distribution: gentoo
    version: unknown
  eventLogger: file
  hostname: dellr330
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 5.4.38-gentoo
  linkmode: dynamic
  memFree: 1262424064
  memTotal: 8132182016
  ociRuntime:
    name: runc
    package: Unknown
    path: /usr/bin/runc
    version: |-
      runc version 1.0.0-rc10
      commit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
      spec: 1.0.1-dev
  os: linux
  remoteSocket:
    path: /run/podman/podman.sock
  rootless: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 25122934784
  swapTotal: 25769787392
  uptime: 656h 34m 23.71s (Approximately 27.33 days)
registries:
  search:
  - docker.io
  - quay.io
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 1
    paused: 0
    running: 1
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.ignore_chown_errors: "false"
  graphRoot: /space/podman/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 931
  runRoot: /space/podman/run
  volumePath: /space/podman/storage/volumes
version:
  APIVersion: 1
  Built: 1593392698
  BuiltTime: Mon Jun 29 01:04:58 2020
  GitCommit: e74e84aa0637033c821955d817fca85f56a90d85
  GoVersion: go1.14.2
  OsArch: linux/amd64
  Version: 2.0.0-rc6
@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 2, 2020
@mheon mheon added the Buildah label Jul 2, 2020
@mheon
Copy link
Member

mheon commented Jul 2, 2020

@TomSweeneyRedHat PTAL

@github-actions
Copy link

github-actions bot commented Aug 2, 2020

A friendly reminder that this issue had no activity for 30 days.

@zhangguanzhang
Copy link
Collaborator

this is the reulst of the docker:

$ mkdir temp
$ mkdir temp/temp
$ touch temp/temp/test1
$ vi Dockerfile
$ cat Dockerfile
FROM alpine
COPY temp/temp /test
RUN ls -l /test

build it

$ docker build -t test .
Sending build context to Docker daemon  13.82kB
Step 1/3 : FROM alpine
latest: Pulling from library/alpine
df20fa9351a1: Pull complete
Digest: sha256:185518070891758909c9f839cf4ca393ee977ac378609f700f60a771a2dfe321
Status: Downloaded newer image for alpine:latest
 ---> a24bb4013296
Step 2/3 : COPY temp/temp /test
 ---> 7b715c462071
Step 3/3 : RUN ls -l /test
 ---> Running in e206f5ff9289
total 0
-rw-r--r--    1 root     root             0 Aug  2 05:00 test1
Removing intermediate container e206f5ff9289
 ---> f9a32d896597
Successfully built f9a32d896597
Successfully tagged test:latest

@rhatdan
Copy link
Member

rhatdan commented Aug 4, 2020

 $ podman build .
STEP 1: FROM alpine
STEP 2: COPY temp/temp /test
--> 56804ae1c44
STEP 3: RUN ls -l /test
total 0
-rw-rw-r--    1 root     root             0 Aug  4 18:44 test1
STEP 4: COMMIT
--> 9b122533af1
9b122533af105fcb6c1e9bbeaaa9752e0756281623501686d8c94410d8ed0712

What am I missing?

@srcshelton
Copy link
Contributor Author

What am I missing?

Confirmed - since raising this issue, I've upgraded from podman version 2.0.0-rc6 to 2.0.3 and I now get the same result as you, that the file is successfully copied.

Is there any means to verify that there are no other edge-cases where COPY/ADD can succeed without having created the intended file, since I assume that the false-positive in 2.0.0-rc6 wasn't picked-up by any automated testing?

@rhatdan
Copy link
Member

rhatdan commented Aug 6, 2020

@nalind is adding a ton of testing for building container images to Buildah, which will hopefully catch these issues.

@rhatdan rhatdan closed this as completed Aug 6, 2020
bors bot added a commit to containers/buildah that referenced this issue Aug 6, 2020
2508: Add documentation for .dockerignore r=TomSweeneyRedHat a=rhatdan

<!--
Thanks for sending a pull request!

Please make sure you've read and understood our contributing guidelines
(https://github.com/containers/buildah/blob/master/CONTRIBUTING.md) as well as ensuring
that all your commits are signed with `git commit -s`.
-->

#### What type of PR is this?

<!--
Please label this pull request according to what type of issue you are
addressing, especially if this is a release targeted pull request.

Uncomment only one `/kind <>` line, hit enter to put that in a new line, and
remove leading whitespace from that line:
-->

> /kind api-change
> /kind bug
> /kind cleanup
> /kind deprecation
> /kind design
> /kind documentation
> /kind failing-test 
> /kind feature
> /kind flake
> /kind other

#### What this PR does / why we need it:

#### How to verify it

#### Which issue(s) this PR fixes:

<!--
Automatically closes linked issue when PR is merged.
Uncomment the following comment block and include the issue
number or None on one line.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`, or `None`.
-->

<!--
Fixes #
or
None
-->

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

<!--
If no, just write `None` in the release-note block below. If yes, a release note
is required: Enter your extended release note in the block below. If the PR
requires additional action from users switching to the new release, include the
string "action required".

For more information on release notes please follow the kubernetes model:
https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note

```



2510: Add BuilderIdentityAnnotation to identify buildah version used to bui… r=TomSweeneyRedHat a=rhatdan

…ld image

We were adding this for buildah commit but not for buildah bud.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

<!--
Thanks for sending a pull request!

Please make sure you've read and understood our contributing guidelines
(https://github.com/containers/buildah/blob/master/CONTRIBUTING.md) as well as ensuring
that all your commits are signed with `git commit -s`.
-->

#### What type of PR is this?

<!--
Please label this pull request according to what type of issue you are
addressing, especially if this is a release targeted pull request.

Uncomment only one `/kind <>` line, hit enter to put that in a new line, and
remove leading whitespace from that line:
-->

> /kind api-change
> /kind bug
> /kind cleanup
> /kind deprecation
> /kind design
> /kind documentation
> /kind failing-test 
> /kind feature
> /kind flake
> /kind other

#### What this PR does / why we need it:

#### How to verify it

#### Which issue(s) this PR fixes:

<!--
Automatically closes linked issue when PR is merged.
Uncomment the following comment block and include the issue
number or None on one line.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`, or `None`.
-->

<!--
Fixes #
or
None
-->

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

<!--
If no, just write `None` in the release-note block below. If yes, a release note
is required: Enter your extended release note in the block below. If the PR
requires additional action from users switching to the new release, include the
string "action required".

For more information on release notes please follow the kubernetes model:
https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note

```



2517: conformance: add a test for COPY from subdirectory r=rhatdan a=nalind

#### What type of PR is this?

/kind cleanup

#### What this PR does / why we need it:

Add a conformance test for containers/podman#6847, making sure that we test copying from a subdirectory of the build context to a new directory.

#### How to verify it

Compare the combination of build context and Dockerfile content to the reported issue, and if doesn't look like we're doing the same thing here, we'll need to correct the test.

#### Which issue(s) this PR fixes:

None

#### Special notes for your reviewer:

The test doesn't need to pass, since we're not requiring that conformance tests pass in CI yet, but this ensures that when we do make it a requirement, we don't miss the case.

#### Does this PR introduce a user-facing change?

```
None
```



Co-authored-by: Daniel J Walsh <dwalsh@redhat.com>
Co-authored-by: Nalin Dahyabhai <nalin@redhat.com>
bors bot added a commit to containers/buildah that referenced this issue Aug 6, 2020
2510: Add BuilderIdentityAnnotation to identify buildah version used to bui… r=TomSweeneyRedHat a=rhatdan

…ld image

We were adding this for buildah commit but not for buildah bud.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

<!--
Thanks for sending a pull request!

Please make sure you've read and understood our contributing guidelines
(https://github.com/containers/buildah/blob/master/CONTRIBUTING.md) as well as ensuring
that all your commits are signed with `git commit -s`.
-->

#### What type of PR is this?

<!--
Please label this pull request according to what type of issue you are
addressing, especially if this is a release targeted pull request.

Uncomment only one `/kind <>` line, hit enter to put that in a new line, and
remove leading whitespace from that line:
-->

> /kind api-change
> /kind bug
> /kind cleanup
> /kind deprecation
> /kind design
> /kind documentation
> /kind failing-test 
> /kind feature
> /kind flake
> /kind other

#### What this PR does / why we need it:

#### How to verify it

#### Which issue(s) this PR fixes:

<!--
Automatically closes linked issue when PR is merged.
Uncomment the following comment block and include the issue
number or None on one line.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`, or `None`.
-->

<!--
Fixes #
or
None
-->

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

<!--
If no, just write `None` in the release-note block below. If yes, a release note
is required: Enter your extended release note in the block below. If the PR
requires additional action from users switching to the new release, include the
string "action required".

For more information on release notes please follow the kubernetes model:
https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note

```



2517: conformance: add a test for COPY from subdirectory r=rhatdan a=nalind

#### What type of PR is this?

/kind cleanup

#### What this PR does / why we need it:

Add a conformance test for containers/podman#6847, making sure that we test copying from a subdirectory of the build context to a new directory.

#### How to verify it

Compare the combination of build context and Dockerfile content to the reported issue, and if doesn't look like we're doing the same thing here, we'll need to correct the test.

#### Which issue(s) this PR fixes:

None

#### Special notes for your reviewer:

The test doesn't need to pass, since we're not requiring that conformance tests pass in CI yet, but this ensures that when we do make it a requirement, we don't miss the case.

#### Does this PR introduce a user-facing change?

```
None
```



Co-authored-by: Daniel J Walsh <dwalsh@redhat.com>
Co-authored-by: Nalin Dahyabhai <nalin@redhat.com>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue
Projects
None yet
Development

No branches or pull requests

5 participants