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

Commit

Permalink
Merge pull request #18 from MaterializeInc/build-arg-support
Browse files Browse the repository at this point in the history
Add Docker build args support
  • Loading branch information
benesch authored Apr 19, 2022
2 parents 0d2ccaf + 0f3dc03 commit eb4b99e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
17 changes: 13 additions & 4 deletions cmd/pulumi-resource-docker-buildkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,25 @@ func (k *dockerBuildkitProvider) dockerBuild(
for _, v := range inputs["platforms"].ArrayValue() {
platforms = append(platforms, v.StringValue())
}
cmd := exec.Command(
"docker", "buildx", "build",

args := []string{
"buildx", "build",
"--platform", strings.Join(platforms, ","),
"--cache-from", name,
"--cache-to", "type=inline",
"-f", filepath.Join(context, dockerfile),
"--target", target,
"-t", name, "--push",
context,
)
}
if !inputs["args"].IsNull() {
for _, v := range inputs["args"].ArrayValue() {
name := v.ObjectValue()["name"].StringValue()
value := v.ObjectValue()["value"].StringValue()
args = append(args, "--build-arg", fmt.Sprintf("%s=%s", name, value))
}
}
args = append(args, context)
cmd := exec.Command("docker", args...)
if err := runCommand(ctx, k.host, urn, cmd); err != nil {
return nil, fmt.Errorf("docker build failed: %w", err)
}
Expand Down
26 changes: 26 additions & 0 deletions cmd/pulumi-sdkgen-docker-buildkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ func run(version string) error {
TypeSpec: schema.TypeSpec{Type: "string"},
Default: "",
},
"args": {
Description: "The build arguments.",
TypeSpec: schema.TypeSpec{
Type: "array",
Items: &schema.TypeSpec{
Ref: "#/types/docker-buildkit:index:BuildArg",
},
},
},
},
RequiredInputs: []string{"name", "registry"},
},
Expand All @@ -154,6 +163,23 @@ func run(version string) error {
Required: []string{"server"},
},
},
"docker-buildkit:index:BuildArg": {
ObjectTypeSpec: schema.ObjectTypeSpec{
Description: "Describes a Docker build argument.",
Type: "object",
Properties: map[string]schema.PropertySpec{
"name": {
Description: "The name of the Docker build argument.",
TypeSpec: schema.TypeSpec{Type: "string"},
},
"value": {
Description: "The value of the Docker build argument.",
TypeSpec: schema.TypeSpec{Type: "string"},
},
},
Required: []string{"name", "value"},
},
},
},
Language: map[string]schema.RawMessage{
"python": schema.RawMessage("{}"),
Expand Down
4 changes: 3 additions & 1 deletion examples/aws-nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM ubuntu

RUN apt-get update && apt-get install -qy python-is-python3 python3
ARG command=false

RUN $command
6 changes: 5 additions & 1 deletion examples/aws-nodejs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ const registryInfo = repo.registryId.apply(async id => {

export const image = new dockerBuildkit.Image(
"image",
{ name: repo.repositoryUrl, registry: registryInfo },
{
name: repo.repositoryUrl,
registry: registryInfo,
args: [{name: "command", value: "true"}],
},
).repoDigest;
4 changes: 3 additions & 1 deletion examples/aws-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM ubuntu

RUN apt-get update && apt-get install -qy python-is-python3 python3
ARG command=false

RUN $command
1 change: 1 addition & 0 deletions examples/aws-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get_registry_info(registry_id):
"image",
name=repo.repository_url,
registry=repo.registry_id.apply(get_registry_info),
args=[docker_buildkit.BuildArgArgs(name="command", value="true")]
)
pulumi.export("image", image.repo_digest)

0 comments on commit eb4b99e

Please sign in to comment.