Skip to content

Commit b3b0cb8

Browse files
committed
feat: add remote_repo_build_mode envbuilder option
1 parent ad8b1fd commit b3b0cb8

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

GNUmakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test-registry: test-registry-container test-images-pull test-images-push
3636
test-registry-container: .registry-cache
3737
if ! curl -fsSL http://localhost:5000/v2/_catalog > /dev/null 2>&1; then \
3838
docker rm -f tfprov-envbuilder-registry && \
39-
docker run -d -p 5000:5000 --name envbuilder-registry --volume $(PWD)/.registry-cache:/var/lib/registry registry:2; \
39+
docker run -d -p 5000:5000 --name tfprov-envbuilder-registry --volume $(PWD)/.registry-cache:/var/lib/registry registry:2; \
4040
fi
4141

4242
# Pulls images referenced in integration tests and pushes them to the local cache.

docs/resources/cached_image.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The cached image resource can be used to retrieve a cached image produced by env
4141
- `git_username` (String) (Envbuilder option) The username to use for Git authentication. This is optional.
4242
- `ignore_paths` (List of String) (Envbuilder option) The comma separated list of paths to ignore when building the workspace.
4343
- `insecure` (Boolean) (Envbuilder option) Bypass TLS verification when cloning and pulling from container registries.
44+
- `remote_repo_build_mode` (Boolean) (Envbuilder option) RemoteRepoBuildMode uses the remote repository as the source of truth when building the image. Enabling this option ignores user changes to local files and they will not be reflected in the image. This can be used to improve cache utilization when multiple users are working on the same repository.
4445
- `ssl_cert_base64` (String) (Envbuilder option) The content of an SSL cert file. This is useful for self-signed certificates.
4546
- `verbose` (Boolean) (Envbuilder option) Enable verbose output.
4647
- `workspace_folder` (String) (Envbuilder option) path to the workspace folder that will be built. This is optional.

internal/provider/cached_image_resource.go

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type CachedImageResourceModel struct {
7373
GitUsername types.String `tfsdk:"git_username"`
7474
IgnorePaths types.List `tfsdk:"ignore_paths"`
7575
Insecure types.Bool `tfsdk:"insecure"`
76+
RemoteRepoBuildMode types.Bool `tfsdk:"remote_repo_build_mode"`
7677
SSLCertBase64 types.String `tfsdk:"ssl_cert_base64"`
7778
Verbose types.Bool `tfsdk:"verbose"`
7879
WorkspaceFolder types.String `tfsdk:"workspace_folder"`
@@ -206,6 +207,13 @@ func (r *CachedImageResource) Schema(ctx context.Context, req resource.SchemaReq
206207
MarkdownDescription: "(Envbuilder option) Bypass TLS verification when cloning and pulling from container registries.",
207208
Optional: true,
208209
},
210+
"remote_repo_build_mode": schema.BoolAttribute{
211+
MarkdownDescription: "(Envbuilder option) RemoteRepoBuildMode uses the remote repository as the source of truth when building the image. Enabling this option ignores user changes to local files and they will not be reflected in the image. This can be used to improve cache utilization when multiple users are working on the same repository.",
212+
Optional: true,
213+
PlanModifiers: []planmodifier.Bool{
214+
boolplanmodifier.RequiresReplace(),
215+
},
216+
},
209217
"ssl_cert_base64": schema.StringAttribute{
210218
MarkdownDescription: "(Envbuilder option) The content of an SSL cert file. This is useful for self-signed certificates.",
211219
Optional: true,
@@ -482,6 +490,7 @@ func (r *CachedImageResource) runCacheProbe(ctx context.Context, data CachedImag
482490
GitPassword: data.GitPassword.ValueString(),
483491
GitSSHPrivateKeyPath: data.GitSSHPrivateKeyPath.ValueString(),
484492
GitHTTPProxyURL: data.GitHTTPProxyURL.ValueString(),
493+
RemoteRepoBuildMode: data.RemoteRepoBuildMode.ValueBool(),
485494
SSLCertBase64: data.SSLCertBase64.ValueString(),
486495

487496
// Other options

internal/provider/provider_test.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServe
3838

3939
// testDependencies contain information about stuff the test depends on.
4040
type testDependencies struct {
41-
BuilderImage string
42-
CacheRepo string
43-
ExtraEnv map[string]string
44-
Repo testGitRepoSSH
41+
BuilderImage string
42+
CacheRepo string
43+
ExtraEnv map[string]string
44+
Repo testGitRepoSSH
45+
RemoteRepoBuildMode bool
4546
}
4647

4748
// Config generates a valid Terraform config file from the dependencies.
@@ -59,6 +60,7 @@ resource "envbuilder_cached_image" "test" {
5960
}
6061
git_url = {{ quote .Repo.URL }}
6162
git_ssh_private_key_path = {{ quote .Repo.Key }}
63+
remote_repo_build_mode = {{ .RemoteRepoBuildMode }}
6264
verbose = true
6365
workspace_folder = {{ quote .Repo.Dir }}
6466
}`
@@ -91,10 +93,11 @@ func setup(ctx context.Context, t testing.TB, files map[string]string) testDepen
9193
gitRepo := serveGitRepoSSH(ctx, t, repoDir)
9294

9395
return testDependencies{
94-
BuilderImage: envbuilderImageRef,
95-
CacheRepo: reg + "/test",
96-
ExtraEnv: make(map[string]string),
97-
Repo: gitRepo,
96+
BuilderImage: envbuilderImageRef,
97+
CacheRepo: reg + "/test",
98+
ExtraEnv: make(map[string]string),
99+
Repo: gitRepo,
100+
RemoteRepoBuildMode: true,
98101
}
99102
}
100103

0 commit comments

Comments
 (0)