Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cross platform builds #471

Merged
merged 2 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions provider/cmd/pulumi-resource-docker/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3074,6 +3074,10 @@
"description": "The path to the Dockerfile to use.",
"default": "Dockerfile"
},
"platform": {
"type": "string",
"description": " Set platform if server is multi-platform capable"
},
"target": {
"type": "string",
"description": "The target of the Dockerfile to build"
Expand Down
7 changes: 7 additions & 0 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Build struct {
CachedImages []string
Args map[string]*string
Target string
Platform string
BuilderVersion types.BuilderVersion
}

Expand Down Expand Up @@ -112,6 +113,7 @@ func (p *dockerNativeProvider) dockerBuild(ctx context.Context,
CacheFrom: img.Build.CachedImages,
BuildArgs: build.Args,
Version: build.BuilderVersion,
Platform: build.Platform,

AuthConfigs: authConfigs,
}
Expand Down Expand Up @@ -306,6 +308,11 @@ func marshalBuildAndApplyDefaults(b resource.PropertyValue) (Build, error) {
if !buildObject["target"].IsNull() {
build.Target = buildObject["target"].StringValue()
}

// Platform
if !buildObject["platform"].IsNull() {
build.Platform = buildObject["platform"].StringValue()
}
return build, nil
}

Expand Down
16 changes: 16 additions & 0 deletions provider/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ func TestMarshalBuildAndApplyDefaults(t *testing.T) {
assert.Equal(t, expected, actual)
assert.NoError(t, err)
})
t.Run("Sets Platform", func(t *testing.T) {
expected := Build{
Context: ".",
Dockerfile: "Dockerfile",
Platform: "linux/leg32",
BuilderVersion: "2",
}

input := resource.NewObjectProperty(resource.PropertyMap{
"platform": resource.NewStringProperty("linux/leg32"),
})

actual, err := marshalBuildAndApplyDefaults(input)
assert.Equal(t, expected, actual)
assert.NoError(t, err)
})
t.Run("Sets Builder to classic V1 builder", func(t *testing.T) {
expected := Build{
Context: ".",
Expand Down
4 changes: 4 additions & 0 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func Provider() tfbridge.ProviderInfo {
},
Default: "BuilderBuildKit",
},
"platform": {
Description: " Set platform if server is multi-platform capable",
TypeSpec: schema.TypeSpec{Type: "string"},
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions sdk/dotnet/Inputs/DockerBuildArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public InputMap<string> Args
[Input("dockerfile")]
public Input<string>? Dockerfile { get; set; }

/// <summary>
/// Set platform if server is multi-platform capable
/// </summary>
[Input("platform")]
public Input<string>? Platform { get; set; }

/// <summary>
/// The target of the Dockerfile to build
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions sdk/go/docker/pulumiTypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ public Optional<Output<String>> dockerfile() {
return Optional.ofNullable(this.dockerfile);
}

/**
* Set platform if server is multi-platform capable
*
*/
@Import(name="platform")
private @Nullable Output<String> platform;

/**
* @return Set platform if server is multi-platform capable
*
*/
public Optional<Output<String>> platform() {
return Optional.ofNullable(this.platform);
}

/**
* The target of the Dockerfile to build
*
Expand All @@ -121,6 +136,7 @@ private DockerBuildArgs(DockerBuildArgs $) {
this.cacheFrom = $.cacheFrom;
this.context = $.context;
this.dockerfile = $.dockerfile;
this.platform = $.platform;
this.target = $.target;
}

Expand Down Expand Up @@ -247,6 +263,27 @@ public Builder dockerfile(String dockerfile) {
return dockerfile(Output.of(dockerfile));
}

/**
* @param platform Set platform if server is multi-platform capable
*
* @return builder
*
*/
public Builder platform(@Nullable Output<String> platform) {
$.platform = platform;
return this;
}

/**
* @param platform Set platform if server is multi-platform capable
*
* @return builder
*
*/
public Builder platform(String platform) {
return platform(Output.of(platform));
}

/**
* @param target The target of the Dockerfile to build
*
Expand Down
4 changes: 4 additions & 0 deletions sdk/nodejs/types/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export interface DockerBuild {
* The path to the Dockerfile to use.
*/
dockerfile?: pulumi.Input<string>;
/**
* Set platform if server is multi-platform capable
*/
platform?: pulumi.Input<string>;
/**
* The target of the Dockerfile to build
*/
Expand Down
16 changes: 16 additions & 0 deletions sdk/python/pulumi_docker/_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4059,6 +4059,7 @@ def __init__(__self__, *,
cache_from: Optional[pulumi.Input['CacheFromArgs']] = None,
context: Optional[pulumi.Input[str]] = None,
dockerfile: Optional[pulumi.Input[str]] = None,
platform: Optional[pulumi.Input[str]] = None,
target: Optional[pulumi.Input[str]] = None):
"""
The Docker build context
Expand All @@ -4067,6 +4068,7 @@ def __init__(__self__, *,
:param pulumi.Input['CacheFromArgs'] cache_from: A list of images to use as build cache
:param pulumi.Input[str] context: The path to the build context to use.
:param pulumi.Input[str] dockerfile: The path to the Dockerfile to use.
:param pulumi.Input[str] platform: Set platform if server is multi-platform capable
:param pulumi.Input[str] target: The target of the Dockerfile to build
"""
if args is not None:
Expand All @@ -4085,6 +4087,8 @@ def __init__(__self__, *,
dockerfile = 'Dockerfile'
if dockerfile is not None:
pulumi.set(__self__, "dockerfile", dockerfile)
if platform is not None:
pulumi.set(__self__, "platform", platform)
if target is not None:
pulumi.set(__self__, "target", target)

Expand Down Expand Up @@ -4148,6 +4152,18 @@ def dockerfile(self) -> Optional[pulumi.Input[str]]:
def dockerfile(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "dockerfile", value)

@property
@pulumi.getter
def platform(self) -> Optional[pulumi.Input[str]]:
"""
Set platform if server is multi-platform capable
"""
return pulumi.get(self, "platform")

@platform.setter
def platform(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "platform", value)

@property
@pulumi.getter
def target(self) -> Optional[pulumi.Input[str]]:
Expand Down