Skip to content

Commit f1acb08

Browse files
committed
feat: Make buildx builder the default
1 parent b14d394 commit f1acb08

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

docs/resources/image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Optional:
127127
- `build_args` (Map of String) Pairs for build-time variables in the form of `ENDPOINT : "https://example.com"`
128128
- `build_id` (String) BuildID is an optional identifier that can be passed together with the build request. The same identifier can be used to gracefully cancel the build with the cancel request.
129129
- `build_log_file` (String) Path to a file where the buildx log are written to. Only available when `builder` is set. If not set, no logs are available. The path is taken as is, so make sure to use a path that is available.
130-
- `builder` (String) Set the name of the buildx builder to use. If not set, the legacy builder is used.
130+
- `builder` (String) 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.
131131
- `cache_from` (List of String) External cache sources (e.g., `user/app:cache`, `type=local,src=path/to/dir`). Only supported when using a buildx builder.
132132
- `cache_to` (List of String) Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`). Only supported when using a buildx builder.
133133
- `cgroup_parent` (String) Optional parent cgroup for the container

docs/resources/registry_image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Optional:
7373
- `build_args` (Map of String) Pairs for build-time variables in the form of `ENDPOINT : "https://example.com"`
7474
- `build_id` (String) BuildID is an optional identifier that can be passed together with the build request. The same identifier can be used to gracefully cancel the build with the cancel request.
7575
- `build_log_file` (String) Path to a file where the buildx log are written to. Only available when `builder` is set. If not set, no logs are available. The path is taken as is, so make sure to use a path that is available.
76-
- `builder` (String) Set the name of the buildx builder to use. If not set, the legacy builder is used.
76+
- `builder` (String) 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.
7777
- `cache_from` (List of String) External cache sources (e.g., `user/app:cache`, `type=local,src=path/to/dir`). Only supported when using a buildx builder.
7878
- `cache_to` (List of String) Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`). Only supported when using a buildx builder.
7979
- `cgroup_parent` (String) Optional parent cgroup for the container

docs/v3_v4_migration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Bump of minimum terraform version to `1.1.5` or newer. This is done as part of i
66

77
## `docker_image`
88

9+
**Default usage of buildx:** For all platforms (except for Windows) the provider now uses buildx to build images. If you do not have the `build.builder`
10+
attribute set, the provider will try to resolve the default buildx builder. In case it is set - no changes for you. It also mimics the behaviour of the docker cli and looks for the `BUILDX_BUILDER` env variable.
11+
912
**Reworked handling of context and Dockerfile:** This probably is not a breaking change, but more a big bugfix. The build logic now correctly resolves the Dockerfile path for both relative and absolute cases.
1013

1114

internal/provider/resource_docker_image.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,10 @@ var buildSchema = &schema.Resource{
445445
},
446446
"builder": {
447447
Type: schema.TypeString,
448-
Description: "Set the name of the buildx builder to use. If not set, the legacy builder is used.",
448+
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.",
449449
Optional: true,
450450
ForceNew: true,
451+
DefaultFunc: schema.EnvDefaultFunc("BUILDX_BUILDER", ""),
451452
},
452453
"build_log_file": {
453454
Type: schema.TypeString,

internal/provider/resource_docker_image_funcs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,16 @@ func buildImage(ctx context.Context, rawBuild interface{}, client *client.Client
6363
return true, diag.FromErr(err)
6464
}
6565

66-
builder := rawBuildValue["builder"].(string)
67-
log.Printf("[DEBUG] canUseBuildx: %v, builder %s", canUseBuildx, builder)
66+
log.Printf("[DEBUG] canUseBuildx: %v", canUseBuildx)
6867
// buildx is enabled
69-
if canUseBuildx && builder != "" {
68+
if canUseBuildx {
7069
log.Printf("[DEBUG] Using buildx")
7170
dockerCli, err := createAndInitDockerCli(client)
7271
if err != nil {
7372
return true, diag.FromErr(fmt.Errorf("failed to create and init Docker CLI: %w", err))
7473
}
7574

76-
options, err := mapBuildAttributesToBuildOptions(rawBuildValue, imageName)
75+
options, err := mapBuildAttributesToBuildOptions(rawBuildValue, imageName, dockerCli)
7776

7877
if err != nil {
7978
return true, diag.FromErr(fmt.Errorf("Error mapping build attributes: %v", err))

0 commit comments

Comments
 (0)