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

fix: preserve files correctly when rendering to a local directory #268

Merged
merged 3 commits into from
Mar 25, 2024

Conversation

krancour
Copy link
Member

When we write to a stage-specific branch, we gut its existing contents entirely and render into the empty directory. The long-time exception to that has been that we do not delete any files or directories explicitly named in the Kargo Render config as preservedPaths.

Only if writing to a local directory instead of a remote branch, all files that were meant to be preserved are going missing. The reason is that we have been rendering into a brand new, empty directory, when really, we should have been copying whatever was to be preserved from the target branch.

Note that since I worked on a new test case that involved a temporary directory, I have also taken the liberty of fixing a few outstanding temp directory-related nits.

Copy link

netlify bot commented Mar 25, 2024

Deploy Preview for docs-kargo-render-akuity-io ready!

Name Link
🔨 Latest commit b70c46a
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-render-akuity-io/deploys/6601cefa450f040007138c1c
😎 Deploy Preview https://deploy-preview-268.bookkeeper.akuity.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Mar 25, 2024

Codecov Report

Attention: Patch coverage is 53.84615% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 27.72%. Comparing base (89fd5f9) to head (b70c46a).

Files Patch % Lines
branches.go 62.50% 2 Missing and 1 partial ⚠️
service.go 0.00% 2 Missing ⚠️
rendering.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #268      +/-   ##
==========================================
+ Coverage   27.57%   27.72%   +0.14%     
==========================================
  Files          22       22              
  Lines        2096     2103       +7     
==========================================
+ Hits          578      583       +5     
- Misses       1440     1441       +1     
- Partials       78       79       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines -262 to +261
if err = os.MkdirAll(outputDir, 0755); err != nil {
if err = copyBranchContents(rc.repo.WorkingDir(), outputDir); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change, right here.

func copyBranchContents(srcDir, dstDir string) error {
// nolint: gosec
if _, err := libExec.Exec(
exec.Command("cp", "-r", srcDir, dstDir),
Copy link

@jessesuen jessesuen Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cp may not exist in trimmed-down or distroless-like images, which is an eventual direction we need to consider for kargo or other utilities built on kargo-render. Do you think we could replace this with a golang implementation? e.g.:

https://stackoverflow.com/questions/51779243/copy-a-folder-in-go

or

https://github.com/otiai10/copy

or

https://github.com/hashicorp/terraform/blob/d3b8a55781f42b5fab662e2a4f2dc2b77faeef1a/internal/copy/copy_dir.go#L38

Copy link
Member Author

@krancour krancour Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to that, but would note two things:

We use cp in other places besides this in both Kargo Render and Kargo proper (simply because the Go stdlib doesn't have a good alternative -- which would be why those libs all exist).

I love distroless and would much prefer that we we were distroless, but I believe the fact that we exec out to the gitCLI (for reasons I believe you're familiar with) present a much larger hurdle to achieving distroless than cp does.

Is this a bridge you'd be open to crossing at a later time?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, if we are already using cp else where, then there's no sense fixing it here and we can address it as separate feature.

@krancour krancour merged commit 093186b into akuity:main Mar 25, 2024
13 checks passed
@krancour krancour deleted the krancour/preserve-files branch March 25, 2024 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants