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

Add test cases and docString for regex in COPY command #2773

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

JeromeJu
Copy link
Collaborator

@JeromeJu JeromeJu commented Oct 3, 2023

Description
This commit adds test cases of COPY command used with regex.
With the mathSources in command_util, the {*?[} wildcards shall be handled. This corresponds to what docker honors regex according to https://docs.docker.com/engine/reference/builder/#copy
where it follows the matched patterns by filepath.match().

closes #757

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

Describe any changes here so maintainer can include it in the release notes, or delete this block.

Examples of user facing changes:
- kaniko adds a new flag `--registry-repo` to override registry

@aaron-prindle
Copy link
Collaborator

aaron-prindle commented Oct 10, 2023

Awesome! Just validated that this functionality indeed works @ HEAD using the example @ #757

Repro Dockerfile + file tree:

aprindle@aprindle-ssd ~/kaniko-ctx-dir tree
.
├── Dockerfile
└── files
    └── include_me

2 directories, 2 files
aprindle@aprindle-ssd ~/kaniko-ctx-dir cat Dockerfile; echo
# Use a base image
FROM debian:buster-slim AS base

RUN ls -a /workspace/files
COPY ./files/[^.]* /
aprindle@aprindle-ssd ~/kaniko-ctx-dir 

aprindle@aprindle-ssd ~/kaniko  [release-automation]./run_in_docker.sh /workspace/Dockerfile /usr/local/google/home/aprindle/kaniko-ctx-dir gcr.io/aprindle-test-cluster/kaniko-test:latest false |& tee ~/out.txt
INFO[0000] Resolved base name debian:buster-slim to base 
INFO[0000] Retrieving image manifest debian:buster-slim 
INFO[0000] Retrieving image debian:buster-slim from registry index.docker.io 
INFO[0001] Built cross stage deps: map[]                
INFO[0001] Retrieving image manifest debian:buster-slim 
INFO[0001] Returning cached image manifest              
INFO[0001] Executing 0 build triggers                   
INFO[0001] Building stage 'debian:buster-slim' [idx: '0', base-idx: '-1'] 
INFO[0001] Unpacking rootfs as cmd RUN ls -a /workspace/files requires it. 
INFO[0002] RUN ls -a /workspace/files                   
INFO[0002] Initializing snapshotter ...                 
INFO[0002] Taking snapshot of full filesystem...        
INFO[0003] Cmd: /bin/sh                                 
INFO[0003] Args: [-c ls -a /workspace/files]            
INFO[0003] Running: [/bin/sh -c ls -a /workspace/files] 
.
..
.exclude_me
include_me
INFO[0003] Taking snapshot of full filesystem...        
INFO[0003] No files were changed, appending empty layer to config. No layer added to image. 
INFO[0003] Resolving srcs [files/[^.]*]...              
INFO[0003] COPY ./files/[^.]* /                         
INFO[0003] Resolving srcs [files/[^.]*]...              
INFO[0003] Taking snapshot of files...                  
INFO[0003] Pushing image to gcr.io/aprindle-test-cluster/kaniko-test:latest 
INFO[0006] Pushed gcr.io/aprindle-test-cluster/kaniko-test@sha256:7078264902254c40122fd3ab3d462df40c032b03fda42de2cc1512b55dc9118a 
aprindle@aprindle-ssd ~/kaniko  [release-automation]docker run -it gcr.io/aprindle-test-cluster/kaniko-test@sha256:7078264902254c40122fd3ab3d462df40c032b03fda42de2cc1512b55dc9118a bash
Unable to find image 'gcr.io/aprindle-test-cluster/kaniko-test@sha256:7078264902254c40122fd3ab3d462df40c032b03fda42de2cc1512b55dc9118a' locally
gcr.io/aprindle-test-cluster/kaniko-test@sha256:7078264902254c40122fd3ab3d462df40c032b03fda42de2cc1512b55dc9118a: Pulling from aprindle-test-cluster/kaniko-test
9f1ecb66bc03: Already exists 
929208e555c0: Pull complete 
Digest: sha256:7078264902254c40122fd3ab3d462df40c032b03fda42de2cc1512b55dc9118a
Status: Downloaded newer image for gcr.io/aprindle-test-cluster/kaniko-test@sha256:7078264902254c40122fd3ab3d462df40c032b03fda42de2cc1512b55dc9118a
root@5e0484aac370:/# ls -a
.  ..  .dockerenv  bin	boot  dev  etc	home  include_me  lib  lib64  media  mnt  opt  proc  root  run	sbin  srv  sys	tmp  usr  var
root@5e0484aac370:/# 

From the above you can see the file .exclude_me is indeed excluded due to the Dockerfile COPY regex/matching syntax used

@aaron-prindle aaron-prindle merged commit b6f14ae into GoogleContainerTools:main Oct 10, 2023
10 checks passed
@JeromeJu JeromeJu deleted the 757-copy-regex branch June 9, 2024 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kaniko does not honor copy regex
2 participants