Skip to content

Commit b9181a7

Browse files
authored
feat: Implement using of buildx for docker_image (#717)
* feat: Implement using of buildx for docker_image * fix: secrets in docker_image * fix: fmt issues * test: Add test for build_log_file * chore: Disable flaky test and update goreleaser to exclude not possible build * feat: Small refactoring and documentation improvements
1 parent 46a6a72 commit b9181a7

File tree

13 files changed

+1493
-611
lines changed

13 files changed

+1493
-611
lines changed

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ builds:
2424
ignore:
2525
- goos: darwin
2626
goarch: "386"
27+
- goos: openbsd
28+
goarch: arm
2729
binary: "{{ .ProjectName }}_v{{ .Version }}"
2830
archives:
2931
- format: zip

docs/resources/image.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "docker_image" "ubuntu" {
4343

4444
### Build
4545

46-
You can also use the resource to build an image.
46+
You can also use the resource to build an image. By default the build block is using the old legacy docker build. In order to use a buildx builder, please read the section below
4747

4848
-> **Note**: The default timeout for the building is 20 minutes. If you need to increase this, you can use [operation timeouts](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts).
4949

@@ -81,6 +81,14 @@ resource "docker_image" "zoo" {
8181
}
8282
```
8383

84+
### Buildx
85+
86+
-> **Note**: The buildx feature is currently in preview and may have some quirks. Known issues: Setting `ulimits` will not work.
87+
88+
The `build` argument uses the legacy docker builder. 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+
90+
The single platform build result is automatically loaded to `docker images`.
91+
8492
<!-- schema generated by tfplugindocs -->
8593
## Schema
8694

@@ -116,6 +124,8 @@ Optional:
116124
- `auth_config` (Block List) The configuration for the authentication (see [below for nested schema](#nestedblock--build--auth_config))
117125
- `build_args` (Map of String) Pairs for build-time variables in the form of `ENDPOINT : "https://example.com"`
118126
- `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.
127+
- `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.
128+
- `builder` (String) Set the name of the buildx builder to use. If not set or empty, the legacy builder will be used.
119129
- `cache_from` (List of String) Images to consider as cache sources
120130
- `cgroup_parent` (String) Optional parent cgroup for the container
121131
- `cpu_period` (Number) The length of a CPU period in microseconds
@@ -135,9 +145,9 @@ Optional:
135145
- `no_cache` (Boolean) Do not use the cache when building the image
136146
- `platform` (String) Set platform if server is multi-platform capable
137147
- `pull_parent` (Boolean) Attempt to pull the image even if an older image exists locally
138-
- `remote_context` (String) A Git repository URI or HTTP/HTTPS context URI
148+
- `remote_context` (String) A Git repository URI or HTTP/HTTPS context URI. Will be ignored if `builder` is set.
139149
- `remove` (Boolean) Remove intermediate containers after a successful build. Defaults to `true`.
140-
- `secrets` (Block List) Set build-time secrets (see [below for nested schema](#nestedblock--build--secrets))
150+
- `secrets` (Block List) Set build-time secrets. Only available when you use a buildx builder. (see [below for nested schema](#nestedblock--build--secrets))
141151
- `security_opt` (List of String) The security options
142152
- `session_id` (String) Set an ID for the build session
143153
- `shm_size` (Number) Size of /dev/shm in bytes. The size must be greater than 0
@@ -176,7 +186,7 @@ Required:
176186
Optional:
177187

178188
- `env` (String) Environment variable source of the secret
179-
- `src` (String) File source of the secret
189+
- `src` (String) File source of the secret. Takes precedence over `env`
180190

181191

182192
<a id="nestedblock--build--ulimit"></a>

go.mod

Lines changed: 116 additions & 39 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 279 additions & 447 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)