feat: Add an command line option to exclude root directory in the tar…
feat: Add an option to exclude root directory in tarball
Fixes #1375
Description
The issue is that images built by Kaniko cannot be pulled successfully by Flux because Kaniko adds an absolute directory path “/” which tar program used by Flux doesn’t allow.
This PR adds a new command line option --exclude-root-dir-tarball to allow excluding root directory in the tar archive.
Testing done:
- Verified that all existing unit tests passed in a linux environment.
- Verified that the updated Kaniko image can generate tarball without root directory and command
flux pull artifact <oci>works properly.- Followed the public Kaniko tutorial here to set up local testing environment
Here are a few references about how the verification was performed.
# updated pod.yaml
containers:
- name: kaniko
image: docker.io/zchen333/kaniko-project:latest
args: ["--dockerfile=/workspace/dockerfile",
"--context=dir://workspace",
"--exclude-root-dir-tarball=true",
"--destination=zchen333/kaniko"] # replace with your dockerhub account
# tested different forms of input
* `--exclude-root-dir-tarball=true` // true
* `--exclude-root-dir-tarball=false` // false
* `--exclude-root-dir-tarball` // true
* None // false by default
# dockerfile to test
echo 'FROM scratch AS builder' >> dockerfile
echo 'COPY clusters /tmp/clusters' >> dockerfile
echo 'COPY teleports /tmp/teleports' >> dockerfile
echo 'FROM scratch' >> dockerfile
echo 'COPY --from=builder /tmp /' >> dockerfile
# Kaniko logs
INFO[0001] Resolved base name scratch to builder
INFO[0001] No base image, nothing to extract
INFO[0001] No base image, nothing to extract
INFO[0001] Built cross stage deps: map[0:[/tmp]]
INFO[0001] No base image, nothing to extract
INFO[0001] Executing 0 build triggers
INFO[0001] Building stage 'scratch' [idx: '0', base-idx: '-1']
INFO[0001] Unpacking rootfs as cmd COPY clusters /tmp/clusters requires it.
INFO[0001] COPY clusters /tmp/clusters
INFO[0001] Taking snapshot of files...
INFO[0001] COPY teleport /tmp/teleport
INFO[0001] Taking snapshot of files...
INFO[0001] Saving file tmp for later use
INFO[0001] Deleting filesystem...
INFO[0001] No base image, nothing to extract
INFO[0001] Executing 0 build triggers
INFO[0001] Building stage 'scratch' [idx: '1', base-idx: '-1']
INFO[0001] Unpacking rootfs as cmd COPY --from=builder /tmp / requires it.
INFO[0001] COPY --from=builder /tmp /
INFO[0001] Taking snapshot of files...
INFO[0001] Pushing image to zchen333/kaniko
INFO[0003] Pushed index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71
# Flux pull
❯ flux pull artifact oci://index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71 --output ./manifests
► pulling artifact from index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71
✔ digest index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71
✔ artifact content extracted to ./manifests
❯ ls ./manifests
clusters teleport
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you review them:
- [x] 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