Skip to content

implement first pass at cached image data source #3

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

Merged
merged 21 commits into from
Aug 1, 2024

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Jul 29, 2024

Closes #1

Implements reading a cached image data source using envbuilder.RunCacheProbe

I'm just testing with one Terraform version for now. Later on I want to extract the existing 'happy-path' provider test into a separate integration test.

Note: when seeding the cache, I explicitly do not set PUSH_IMAGE to work around an issue with envbuilder creating files owned by root:root. I plan to address this later on by running the provider inside a container, which should work around this issue.

@johnstcn johnstcn self-assigned this Jul 29, 2024
@johnstcn johnstcn marked this pull request as ready for review August 1, 2024 14:45
@johnstcn johnstcn requested review from mafredri and mtojek August 1, 2024 14:45
image, err := envbuilder.RunCacheProbe(ctx, opts)
data.Exists = types.BoolValue(err == nil)
if err != nil {
resp.Diagnostics.AddWarning("Cached image not found", 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.

note: only add the warning if it is an apply, otherwise you get this on terraform plan:

Plan: 5 to add, 0 to change, 0 to destroy.
╷
│ Warning: Cached image not found
│ 
│   with data.envbuilder_cached_image.cached,
│   on main.tf line 121, in data "envbuilder_cached_image" "cached":
│  121: data "envbuilder_cached_image" "cached" {
│ 
│ --cache-repo must be set when using --get-cached-image
╵

Copy link
Member

@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.

Stellar work! ⭐


.PHONY: update-envbuilder-version
update-envbuilder-version:
go get github.com/coder/envbuilder@main
Copy link
Member

Choose a reason for hiding this comment

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

Do we want this to update to main or would it be better to default to the latest release version?

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'm actually not sure what we'll want right now. Let's leave it at main for now and maybe later we can specify a particular version if needed.

tflog.Info(ctx, "set kaniko dir to "+tmpKanikoDir)
defer func() {
kconfig.KanikoDir = oldKanikoDir
tflog.Info(ctx, "restored kaniko dir to "+oldKanikoDir)
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need to restore? I'm not saying we should remove it, just wondering.

Copy link
Member Author

Choose a reason for hiding this comment

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

probably not, but better safe than sorry

opts := eboptions.Options{
// These options are always required
CacheRepo: data.CacheRepo.ValueString(),
Filesystem: osfs.New("/"),
Copy link
Member

Choose a reason for hiding this comment

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

Is this safe? Should we use the tmpdir?

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 only really matters for the git cloning

InitScript: "",
LayerCacheDir: "",
PostStartScriptPath: "",
PushImage: false,
Copy link
Member

Choose a reason for hiding this comment

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

AFAIR we conditionally append instructions to the Dockerfile if push image is used, we should make sure we don't get a cache miss due to this. Potentially we should append the instructions always if GetCachedImage: true as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

related: #5

@johnstcn johnstcn merged commit c9e7cb8 into main Aug 1, 2024
6 checks passed
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.

create envbuilder_cached_image data source
2 participants