Skip to content

Commit 55cdaa6

Browse files
feat: Add cache_from option in the docker-build module (#641)
Co-authored-by: Anton Babenko <[email protected]>
1 parent 3e553e9 commit 55cdaa6

File tree

5 files changed

+11
-0
lines changed

5 files changed

+11
-0
lines changed

examples/container-image/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ module "docker_build_from_ecr" {
127127
triggers = {
128128
dir_sha = local.dir_sha
129129
}
130+
131+
cache_from = ["${module.ecr.repository_url}:latest"]
130132
}
131133

132134
module "ecr" {

modules/docker-build/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ No modules.
9191
| Name | Description | Type | Default | Required |
9292
|------|-------------|------|---------|:--------:|
9393
| <a name="input_build_args"></a> [build\_args](#input\_build\_args) | A map of Docker build arguments. | `map(string)` | `{}` | no |
94+
| <a name="input_cache_from"></a> [cache\_from](#input\_cache\_from) | List of images to consider as cache sources when building the image. | `list(string)` | `[]` | no |
9495
| <a name="input_create_ecr_repo"></a> [create\_ecr\_repo](#input\_create\_ecr\_repo) | Controls whether ECR repository for Lambda image should be created | `bool` | `false` | no |
9596
| <a name="input_create_sam_metadata"></a> [create\_sam\_metadata](#input\_create\_sam\_metadata) | Controls whether the SAM metadata null resource should be created | `bool` | `false` | no |
9697
| <a name="input_docker_file_path"></a> [docker\_file\_path](#input\_docker\_file\_path) | Path to Dockerfile in source package | `string` | `"Dockerfile"` | no |

modules/docker-build/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ resource "docker_image" "this" {
1717
dockerfile = var.docker_file_path
1818
build_args = var.build_args
1919
platform = var.platform
20+
cache_from = var.cache_from
2021
}
2122

2223
force_remove = var.force_remove

modules/docker-build/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,9 @@ variable "triggers" {
112112
type = map(string)
113113
default = {}
114114
}
115+
116+
variable "cache_from" {
117+
description = "List of images to consider as cache sources when building the image."
118+
type = list(string)
119+
default = []
120+
}

wrappers/docker-build/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module "wrapper" {
44
for_each = var.items
55

66
build_args = try(each.value.build_args, var.defaults.build_args, {})
7+
cache_from = try(each.value.cache_from, var.defaults.cache_from, [])
78
create_ecr_repo = try(each.value.create_ecr_repo, var.defaults.create_ecr_repo, false)
89
create_sam_metadata = try(each.value.create_sam_metadata, var.defaults.create_sam_metadata, false)
910
docker_file_path = try(each.value.docker_file_path, var.defaults.docker_file_path, "Dockerfile")

0 commit comments

Comments
 (0)