Skip to content

Commit

Permalink
feat: Add cache_from option in the docker-build module (#641)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Babenko <[email protected]>
  • Loading branch information
jean-simon-barry1 and antonbabenko authored Jan 8, 2025
1 parent 3e553e9 commit 55cdaa6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/container-image/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ module "docker_build_from_ecr" {
triggers = {
dir_sha = local.dir_sha
}

cache_from = ["${module.ecr.repository_url}:latest"]
}

module "ecr" {
Expand Down
1 change: 1 addition & 0 deletions modules/docker-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_build_args"></a> [build\_args](#input\_build\_args) | A map of Docker build arguments. | `map(string)` | `{}` | no |
| <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 |
| <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 |
| <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 |
| <a name="input_docker_file_path"></a> [docker\_file\_path](#input\_docker\_file\_path) | Path to Dockerfile in source package | `string` | `"Dockerfile"` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/docker-build/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions modules/docker-build/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}
1 change: 1 addition & 0 deletions wrappers/docker-build/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 55cdaa6

Please sign in to comment.