Skip to content

Commit 62b3687

Browse files
committed
feat: Implement use_legacy_builder attribute
1 parent 1801b74 commit 62b3687

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

.github/workflows/acc-test.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ jobs:
9191
else:
9292
provider_bases = set()
9393
other_go_change = False
94+
buildx_build_changed = False
9495
for f in go_files:
96+
# This file doesn't follow the resource/data_source naming convention,
97+
# but changes here affect image build/push behaviors.
98+
if f.endswith('docker_buildx_build.go'):
99+
buildx_build_changed = True
100+
continue
101+
95102
base = base_type_from_provider_file(f)
96103
if base:
97104
provider_bases.add(base)
@@ -120,6 +127,14 @@ jobs:
120127
should_run = True
121128
else:
122129
selected = sorted({test_prefix_for_base(b) for b in provider_bases})
130+
131+
# docker_buildx_build.go impacts both image-related and registry image flows.
132+
if buildx_build_changed:
133+
selected = sorted(set(selected) | {
134+
'TestAccDockerImage',
135+
'TestAccDockerRegistryImage',
136+
})
137+
123138
should_run = True
124139
125140
# Drop prefixes that don't match any tests in this repo.

docs/resources/image.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ resource "docker_image" "zoo" {
8686

8787
-> **Note**: The buildx feature is currently in preview and may have some quirks. Known issues: Setting `ulimits` will not work.
8888

89-
If you want to use a buildx builder, you need to set the `builder` argument. For the default buildx builder, you can set the `builder` argument to `default`. For a custom buildx builder, you can set the `builder` argument to the name of the builder. You can find the name of the builder by running `docker buildx ls`.
89+
If buildx is available, the provider will use it by default.
90+
91+
To force the legacy builder, set `use_legacy_builder = true` in the `build` block.
92+
93+
To select a specific buildx builder, set the `builder` argument (for the default buildx builder, use `default`). For a custom buildx builder, set `builder` to the builder name (see `docker buildx ls`).
9094

9195
The single platform build result is automatically loaded to `docker images`.
9296

@@ -159,6 +163,7 @@ Optional:
159163
- `tag` (List of String) Name and optionally a tag in the 'name:tag' format
160164
- `target` (String) Set the target build stage to build
161165
- `ulimit` (Block List) Configuration for ulimits (see [below for nested schema](#nestedblock--build--ulimit))
166+
- `use_legacy_builder` (Boolean) Force using the legacy Docker builder for image builds, even if buildx/buildkit would be available.
162167
- `version` (String) Version of the underlying builder to use
163168

164169
<a id="nestedblock--build--auth_config"></a>

docs/resources/registry_image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Optional:
105105
- `tag` (List of String) Name and optionally a tag in the 'name:tag' format
106106
- `target` (String) Set the target build stage to build
107107
- `ulimit` (Block List) Configuration for ulimits (see [below for nested schema](#nestedblock--build--ulimit))
108+
- `use_legacy_builder` (Boolean) Force using the legacy Docker builder for image builds, even if buildx/buildkit would be available.
108109
- `version` (String) Version of the underlying builder to use
109110

110111
<a id="nestedblock--build--auth_config"></a>

internal/provider/resource_docker_image.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,13 @@ var buildSchema = &schema.Resource{
443443
Optional: true,
444444
ForceNew: true,
445445
},
446+
"use_legacy_builder": {
447+
Type: schema.TypeBool,
448+
Description: "Force using the legacy Docker builder for image builds, even if buildx/buildkit would be available.",
449+
Optional: true,
450+
Default: false,
451+
ForceNew: true,
452+
},
446453
"builder": {
447454
Type: schema.TypeString,
448455
Description: "The name of the buildx builder to use. If BUILDX_BUILDER environment variable is set, it will be used. If left empty, the provider tries to resolve to the default builder - which might not always work. If you are in Windows, the legacy builder is used.",

internal/provider/resource_docker_image_funcs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ func resourceDockerImageCreate(ctx context.Context, d *schema.ResourceData, meta
5757

5858
func buildImage(ctx context.Context, rawBuild interface{}, client *client.Client, imageName string) (bool, diag.Diagnostics) {
5959
rawBuildValue := rawBuild.(map[string]interface{})
60+
useLegacyBuilder, _ := rawBuildValue["use_legacy_builder"].(bool)
6061
// now we need to determine whether we can use buildx or need to use the legacy builder
6162
canUseBuildx, err := canUseBuildx(ctx, client)
6263
if err != nil {
6364
return true, diag.FromErr(err)
6465
}
66+
if useLegacyBuilder {
67+
log.Printf("[DEBUG] use_legacy_builder=true, forcing legacy builder")
68+
canUseBuildx = false
69+
}
6570

6671
log.Printf("[DEBUG] canUseBuildx: %v", canUseBuildx)
6772
// buildx is enabled

templates/resources/image.md.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ You can use the `triggers` argument to specify when the image should be rebuild.
4747

4848
-> **Note**: The buildx feature is currently in preview and may have some quirks. Known issues: Setting `ulimits` will not work.
4949

50-
If you want to use a buildx builder, you need to set the `builder` argument. For the default buildx builder, you can set the `builder` argument to `default`. For a custom buildx builder, you can set the `builder` argument to the name of the builder. You can find the name of the builder by running `docker buildx ls`.
50+
If buildx is available, the provider will use it by default.
51+
52+
To force the legacy builder, set `use_legacy_builder = true` in the `build` block.
53+
54+
To select a specific buildx builder, set the `builder` argument (for the default buildx builder, use `default`). For a custom buildx builder, set `builder` to the builder name (see `docker buildx ls`).
5155

5256
The single platform build result is automatically loaded to `docker images`.
5357

0 commit comments

Comments
 (0)