File tree 9 files changed +57
-5
lines changed
9 files changed +57
-5
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ Note that this example may create resources which cost money. Run `terraform des
37
37
| ------| --------| ---------|
38
38
| <a name =" module_docker_build " ></a > [ docker\_ build] ( #module\_ docker\_ build ) | ../../modules/docker-build | n/a |
39
39
| <a name =" module_docker_build_from_ecr " ></a > [ docker\_ build\_ from\_ ecr] ( #module\_ docker\_ build\_ from\_ ecr ) | ../../modules/docker-build | n/a |
40
+ | <a name =" module_docker_build_multistage " ></a > [ docker\_ build\_ multistage] ( #module\_ docker\_ build\_ multistage ) | ../../modules/docker-build | n/a |
40
41
| <a name =" module_ecr " ></a > [ ecr] ( #module\_ ecr ) | terraform-aws-modules/ecr/aws | n/a |
41
42
| <a name =" module_lambda_function_with_docker_build " ></a > [ lambda\_ function\_ with\_ docker\_ build] ( #module\_ lambda\_ function\_ with\_ docker\_ build ) | ../../ | n/a |
42
43
| <a name =" module_lambda_function_with_docker_build_from_ecr " ></a > [ lambda\_ function\_ with\_ docker\_ build\_ from\_ ecr] ( #module\_ lambda\_ function\_ with\_ docker\_ build\_ from\_ ecr ) | ../../ | n/a |
Original file line number Diff line number Diff line change 1
1
# `--platform` argument is used to be able to build docker images when using another platform (e.g. Apple M1)
2
- FROM --platform=linux/x86_64 scratch
2
+ FROM --platform=linux/x86_64 scratch AS first_stage
3
3
4
4
ARG FOO
5
5
6
6
ENV FOO $FOO
7
7
8
8
COPY empty /empty
9
+
10
+ FROM first_stage AS second_stage
11
+
12
+ COPY empty /empty_two
Original file line number Diff line number Diff line change @@ -123,6 +123,35 @@ module "docker_build_from_ecr" {
123
123
build_args = {
124
124
FOO = " bar"
125
125
}
126
+ # Can also use buildx
127
+ builder = " default"
128
+ docker_file_path = " ${ local . source_path } /Dockerfile"
129
+
130
+ triggers = {
131
+ dir_sha = local.dir_sha
132
+ }
133
+
134
+ cache_from = [" ${ module . ecr . repository_url } :latest" ]
135
+ }
136
+
137
+ module "docker_build_multistage" {
138
+ source = " ../../modules/docker-build"
139
+
140
+ ecr_repo = module. ecr . repository_name
141
+
142
+ use_image_tag = true
143
+ image_tag = " first_stage"
144
+
145
+ source_path = local. source_path
146
+ platform = " linux/amd64"
147
+ build_args = {
148
+ FOO = " bar"
149
+ }
150
+ builder = " default"
151
+ docker_file_path = " ${ local . source_path } /Dockerfile"
152
+
153
+ # multi-stage builds
154
+ build_target = " first_stage"
126
155
127
156
triggers = {
128
157
dir_sha = local.dir_sha
Original file line number Diff line number Diff line change @@ -59,15 +59,15 @@ module "docker_image" {
59
59
| ------| ---------|
60
60
| <a name =" requirement_terraform " ></a > [ terraform] ( #requirement\_ terraform ) | >= 1.0 |
61
61
| <a name =" requirement_aws " ></a > [ aws] ( #requirement\_ aws ) | >= 4.22 |
62
- | <a name =" requirement_docker " ></a > [ docker] ( #requirement\_ docker ) | >= 3.0 |
62
+ | <a name =" requirement_docker " ></a > [ docker] ( #requirement\_ docker ) | >= 3.5. 0 |
63
63
| <a name =" requirement_null " ></a > [ null] ( #requirement\_ null ) | >= 2.0 |
64
64
65
65
## Providers
66
66
67
67
| Name | Version |
68
68
| ------| ---------|
69
69
| <a name =" provider_aws " ></a > [ aws] ( #provider\_ aws ) | >= 4.22 |
70
- | <a name =" provider_docker " ></a > [ docker] ( #provider\_ docker ) | >= 3.0 |
70
+ | <a name =" provider_docker " ></a > [ docker] ( #provider\_ docker ) | >= 3.5. 0 |
71
71
| <a name =" provider_null " ></a > [ null] ( #provider\_ null ) | >= 2.0 |
72
72
73
73
## Modules
@@ -91,6 +91,8 @@ No modules.
91
91
| Name | Description | Type | Default | Required |
92
92
| ------| -------------| ------| ---------| :--------:|
93
93
| <a name =" input_build_args " ></a > [ build\_ args] ( #input\_ build\_ args ) | A map of Docker build arguments. | ` map(string) ` | ` {} ` | no |
94
+ | <a name =" input_build_target " ></a > [ build\_ target] ( #input\_ build\_ target ) | Set the target build stage to build | ` string ` | ` null ` | no |
95
+ | <a name =" input_builder " ></a > [ builder] ( #input\_ builder ) | The buildx builder to use for the Docker build. | ` string ` | ` null ` | no |
94
96
| <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 |
95
97
| <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 |
96
98
| <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 |
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ resource "docker_image" "this" {
16
16
context = var. source_path
17
17
dockerfile = var. docker_file_path
18
18
build_args = var. build_args
19
+ builder = var. builder
20
+ target = var. build_target
19
21
platform = var. platform
20
22
cache_from = var. cache_from
21
23
}
Original file line number Diff line number Diff line change @@ -71,12 +71,24 @@ variable "ecr_repo_tags" {
71
71
default = {}
72
72
}
73
73
74
+ variable "builder" {
75
+ description = " The buildx builder to use for the Docker build."
76
+ type = string
77
+ default = null
78
+ }
79
+
74
80
variable "build_args" {
75
81
description = " A map of Docker build arguments."
76
82
type = map (string )
77
83
default = {}
78
84
}
79
85
86
+ variable "build_target" {
87
+ description = " Set the target build stage to build"
88
+ type = string
89
+ default = null
90
+ }
91
+
80
92
variable "ecr_repo_lifecycle_policy" {
81
93
description = " A JSON formatted ECR lifecycle policy to automate the cleaning up of unused images."
82
94
type = string
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ terraform {
8
8
}
9
9
docker = {
10
10
source = " kreuzwerker/docker"
11
- version = " >= 3.0"
11
+ version = " >= 3.5. 0"
12
12
}
13
13
null = {
14
14
source = " hashicorp/null"
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ module "wrapper" {
4
4
for_each = var. items
5
5
6
6
build_args = try (each. value . build_args , var. defaults . build_args , {})
7
+ build_target = try (each. value . build_target , var. defaults . build_target , null )
8
+ builder = try (each. value . builder , var. defaults . builder , null )
7
9
cache_from = try (each. value . cache_from , var. defaults . cache_from , [])
8
10
create_ecr_repo = try (each. value . create_ecr_repo , var. defaults . create_ecr_repo , false )
9
11
create_sam_metadata = try (each. value . create_sam_metadata , var. defaults . create_sam_metadata , false )
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ terraform {
8
8
}
9
9
docker = {
10
10
source = " kreuzwerker/docker"
11
- version = " >= 3.0"
11
+ version = " >= 3.5. 0"
12
12
}
13
13
null = {
14
14
source = " hashicorp/null"
You can’t perform that action at this time.
0 commit comments