Skip to content
This repository was archived by the owner on Mar 11, 2023. It is now read-only.

Commit eb4b99e

Browse files
authored
Merge pull request #18 from MaterializeInc/build-arg-support
Add Docker build args support
2 parents 0d2ccaf + 0f3dc03 commit eb4b99e

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

cmd/pulumi-resource-docker-buildkit/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,25 @@ func (k *dockerBuildkitProvider) dockerBuild(
264264
for _, v := range inputs["platforms"].ArrayValue() {
265265
platforms = append(platforms, v.StringValue())
266266
}
267-
cmd := exec.Command(
268-
"docker", "buildx", "build",
267+
268+
args := []string{
269+
"buildx", "build",
269270
"--platform", strings.Join(platforms, ","),
270271
"--cache-from", name,
271272
"--cache-to", "type=inline",
272273
"-f", filepath.Join(context, dockerfile),
273274
"--target", target,
274275
"-t", name, "--push",
275-
context,
276-
)
276+
}
277+
if !inputs["args"].IsNull() {
278+
for _, v := range inputs["args"].ArrayValue() {
279+
name := v.ObjectValue()["name"].StringValue()
280+
value := v.ObjectValue()["value"].StringValue()
281+
args = append(args, "--build-arg", fmt.Sprintf("%s=%s", name, value))
282+
}
283+
}
284+
args = append(args, context)
285+
cmd := exec.Command("docker", args...)
277286
if err := runCommand(ctx, k.host, urn, cmd); err != nil {
278287
return nil, fmt.Errorf("docker build failed: %w", err)
279288
}

cmd/pulumi-sdkgen-docker-buildkit/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ func run(version string) error {
128128
TypeSpec: schema.TypeSpec{Type: "string"},
129129
Default: "",
130130
},
131+
"args": {
132+
Description: "The build arguments.",
133+
TypeSpec: schema.TypeSpec{
134+
Type: "array",
135+
Items: &schema.TypeSpec{
136+
Ref: "#/types/docker-buildkit:index:BuildArg",
137+
},
138+
},
139+
},
131140
},
132141
RequiredInputs: []string{"name", "registry"},
133142
},
@@ -154,6 +163,23 @@ func run(version string) error {
154163
Required: []string{"server"},
155164
},
156165
},
166+
"docker-buildkit:index:BuildArg": {
167+
ObjectTypeSpec: schema.ObjectTypeSpec{
168+
Description: "Describes a Docker build argument.",
169+
Type: "object",
170+
Properties: map[string]schema.PropertySpec{
171+
"name": {
172+
Description: "The name of the Docker build argument.",
173+
TypeSpec: schema.TypeSpec{Type: "string"},
174+
},
175+
"value": {
176+
Description: "The value of the Docker build argument.",
177+
TypeSpec: schema.TypeSpec{Type: "string"},
178+
},
179+
},
180+
Required: []string{"name", "value"},
181+
},
182+
},
157183
},
158184
Language: map[string]schema.RawMessage{
159185
"python": schema.RawMessage("{}"),

examples/aws-nodejs/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
FROM ubuntu
22

3-
RUN apt-get update && apt-get install -qy python-is-python3 python3
3+
ARG command=false
4+
5+
RUN $command

examples/aws-nodejs/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ const registryInfo = repo.registryId.apply(async id => {
1212

1313
export const image = new dockerBuildkit.Image(
1414
"image",
15-
{ name: repo.repositoryUrl, registry: registryInfo },
15+
{
16+
name: repo.repositoryUrl,
17+
registry: registryInfo,
18+
args: [{name: "command", value: "true"}],
19+
},
1620
).repoDigest;

examples/aws-python/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
FROM ubuntu
22

3-
RUN apt-get update && apt-get install -qy python-is-python3 python3
3+
ARG command=false
4+
5+
RUN $command

examples/aws-python/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def get_registry_info(registry_id):
1919
"image",
2020
name=repo.repository_url,
2121
registry=repo.registry_id.apply(get_registry_info),
22+
args=[docker_buildkit.BuildArgArgs(name="command", value="true")]
2223
)
2324
pulumi.export("image", image.repo_digest)
2425

0 commit comments

Comments
 (0)