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: set env and run scripts when starting cached image #359

Merged
merged 7 commits into from
Sep 27, 2024

Conversation

mafredri
Copy link
Member

Fixes #358

@mafredri mafredri force-pushed the mafredri/fix-cached-image-startup branch 6 times, most recently from ab0ffa8 to ed1ad13 Compare September 26, 2024 17:31
@mafredri mafredri force-pushed the mafredri/fix-cached-image-startup branch from ed1ad13 to 0e8b049 Compare September 26, 2024 17:33
Copy link
Member Author

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

I'll see about adding some tests tomorrow (need to figure out what to test), but in the meantime I think this is ready for review.

envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Outdated
}
if buildParams.User != "" {
// BUG(mafredri): buildParams may set the user to remoteUser which
// is incorrect, we should only override if containerUser is set.
Copy link
Member Author

Choose a reason for hiding this comment

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

Review: Didn't want to change this logic now, but documenting it for posterity.

Copy link
Member

Choose a reason for hiding this comment

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

Nice find. Can you open a follow-up PR to track this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did and closed it right up: #365

I'll remove this comment.

There's still something wonky going on here:

if remoteUser != "" {
// TODO: We should warn that because we were unable to find the remote user,
// we're going to run as root.
lines = append(lines, fmt.Sprintf("USER %s", remoteUser))
}

But I don't understand its purpose yet. It seems to change the user at the end without actually doing anything with that user?

envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
os.Setenv(pair[0], pair[1])
runtimeData.Scripts = devContainer.LifecycleScripts
} else {
opts.Logger(log.LevelError, "Failed to parse devcontainer.json: %s", err.Error())
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Review: We're parsing the workspace devcontainer.json here as we don't have access to the build-time devcontainer.json.

Motivation: Unless we cache the whole repo in the image, we can't reliably use devcontainer.json from it, it could be referencing unknown files from the repo which we haven't cached.

envbuilder.go Show resolved Hide resolved
@mafredri mafredri self-assigned this Sep 26, 2024
@mafredri mafredri marked this pull request as ready for review September 26, 2024 17:50
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

I tested the provider against this branch and all tests passed 👍

envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Outdated
}
if buildParams.User != "" {
// BUG(mafredri): buildParams may set the user to remoteUser which
// is incorrect, we should only override if containerUser is set.
Copy link
Member

Choose a reason for hiding this comment

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

Nice find. Can you open a follow-up PR to track this?

envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved
envbuilder.go Show resolved Hide resolved

// Unset the Kaniko environment variable which we set it in the
// Dockerfile to ensure correct behavior during building.
_ = os.Unsetenv("KANIKO_DIR")
Copy link
Member Author

Choose a reason for hiding this comment

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

Review: This was left in a built image, but not in a cached image. I chose to go this path, but it also means it's not as "easy" to re-envbuilder inside a built image. But I didn't think that's really a use-case, wdyt @johnstcn?

Copy link
Member

Choose a reason for hiding this comment

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

I think the main use-case of a cached image is to run the lifecycle scripts. We don't ever want to delete the filesystem or run kaniko inside a pre-built image anyway, so I don't see a reason to need this env.

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 isn't actually relevant for the cached image, since it doesn't set this env. It's only for a built image. But I'd argue the same logic applies there.

@mafredri mafredri force-pushed the mafredri/fix-cached-image-startup branch from aaa1965 to b2041cc Compare September 27, 2024 12:43
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

:shipit:

@mafredri mafredri merged commit c11faf3 into main Sep 27, 2024
4 checks passed
@mafredri mafredri deleted the mafredri/fix-cached-image-startup branch September 27, 2024 13:41
johnstcn pushed a commit that referenced this pull request Sep 27, 2024
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.

Startup environment issues when starting a cached image
3 participants