diff --git a/examples/container-image/main.tf b/examples/container-image/main.tf index 3258960f..75a36ffc 100644 --- a/examples/container-image/main.tf +++ b/examples/container-image/main.tf @@ -127,6 +127,8 @@ module "docker_build_from_ecr" { triggers = { dir_sha = local.dir_sha } + + cache_from = ["${module.ecr.repository_url}:latest"] } module "ecr" { diff --git a/modules/docker-build/README.md b/modules/docker-build/README.md index bd223aaf..0bfb506c 100644 --- a/modules/docker-build/README.md +++ b/modules/docker-build/README.md @@ -91,6 +91,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [build\_args](#input\_build\_args) | A map of Docker build arguments. | `map(string)` | `{}` | no | +| [cache\_from](#input\_cache\_from) | List of images to consider as cache sources when building the image. | `list(string)` | `[]` | no | | [create\_ecr\_repo](#input\_create\_ecr\_repo) | Controls whether ECR repository for Lambda image should be created | `bool` | `false` | no | | [create\_sam\_metadata](#input\_create\_sam\_metadata) | Controls whether the SAM metadata null resource should be created | `bool` | `false` | no | | [docker\_file\_path](#input\_docker\_file\_path) | Path to Dockerfile in source package | `string` | `"Dockerfile"` | no | diff --git a/modules/docker-build/main.tf b/modules/docker-build/main.tf index 6ed24831..1bf27a1f 100644 --- a/modules/docker-build/main.tf +++ b/modules/docker-build/main.tf @@ -17,6 +17,7 @@ resource "docker_image" "this" { dockerfile = var.docker_file_path build_args = var.build_args platform = var.platform + cache_from = var.cache_from } force_remove = var.force_remove diff --git a/modules/docker-build/variables.tf b/modules/docker-build/variables.tf index 509f35f3..e153fa7f 100644 --- a/modules/docker-build/variables.tf +++ b/modules/docker-build/variables.tf @@ -112,3 +112,9 @@ variable "triggers" { type = map(string) default = {} } + +variable "cache_from" { + description = "List of images to consider as cache sources when building the image." + type = list(string) + default = [] +} diff --git a/wrappers/docker-build/main.tf b/wrappers/docker-build/main.tf index 0375d4eb..7d7614cf 100644 --- a/wrappers/docker-build/main.tf +++ b/wrappers/docker-build/main.tf @@ -4,6 +4,7 @@ module "wrapper" { for_each = var.items build_args = try(each.value.build_args, var.defaults.build_args, {}) + cache_from = try(each.value.cache_from, var.defaults.cache_from, []) create_ecr_repo = try(each.value.create_ecr_repo, var.defaults.create_ecr_repo, false) create_sam_metadata = try(each.value.create_sam_metadata, var.defaults.create_sam_metadata, false) docker_file_path = try(each.value.docker_file_path, var.defaults.docker_file_path, "Dockerfile")