Make push a required param

This commit is contained in:
Bryce Lampe
2024-04-25 09:25:50 -07:00
parent 5175dbeb3f
commit f8796f9095
10 changed files with 91 additions and 67 deletions

File diff suppressed because one or more lines are too long

View File

@@ -99,7 +99,7 @@ type ImageArgs struct {
NoCache bool `pulumi:"noCache,optional"`
Platforms []Platform `pulumi:"platforms,optional"`
Pull bool `pulumi:"pull,optional"`
Push bool `pulumi:"push,optional"`
Push bool `pulumi:"push"`
Registries []Registry `pulumi:"registries,optional"`
Secrets map[string]string `pulumi:"secrets,optional"`
SSH []SSH `pulumi:"ssh,optional"`
@@ -907,11 +907,9 @@ func (*Image) Diff(
if !reflect.DeepEqual(olds.Context.Named, news.Context.Named) {
diff["context.named"] = update
}
if olds.Dockerfile.Location != news.Dockerfile.Location {
diff["dockerfile.location"] = update
}
if olds.Dockerfile.Inline != news.Dockerfile.Inline {
diff["dockerfile.inline"] = update
dockerfile, _, _ := news.Context.validate(true, news.Dockerfile)
if !reflect.DeepEqual(olds.Dockerfile, dockerfile) {
diff["dockerfile"] = update
}
// Use string comparison to ignore any manifests attached to the export.
if fmt.Sprint(olds.Exports) != fmt.Sprint(news.Exports) {
@@ -932,10 +930,10 @@ func (*Image) Diff(
if !reflect.DeepEqual(olds.Platforms, news.Platforms) {
diff["platforms"] = update
}
if olds.Pull != news.Pull {
if !reflect.DeepEqual(olds.Pull, news.Pull) {
diff["pull"] = update
}
if olds.Push != news.Push {
if !reflect.DeepEqual(olds.Push, news.Push) {
diff["push"] = update
}
if !reflect.DeepEqual(olds.Secrets, news.Secrets) {
@@ -960,7 +958,7 @@ func (*Image) Diff(
// Check if anything has changed in our build context.
hash, err := hashBuildContext(
news.Context.Location,
news.Dockerfile.Location,
dockerfile.Location,
news.Context.Named.Map(),
)
if err != nil {

View File

@@ -82,6 +82,7 @@ func TestImageLifecycle(t *testing.T) {
op: func(t *testing.T) integration.Operation {
return integration.Operation{
Inputs: resource.PropertyMap{
"push": resource.NewBoolProperty(false),
"tags": resource.NewArrayProperty(
[]resource.PropertyValue{
resource.NewStringProperty("docker.io/pulumibot/buildkit-e2e"),
@@ -129,6 +130,7 @@ func TestImageLifecycle(t *testing.T) {
op: func(t *testing.T) integration.Operation {
return integration.Operation{
Inputs: resource.PropertyMap{
"push": resource.NewBoolProperty(false),
"tags": resource.NewArrayProperty([]resource.PropertyValue{}),
"context": resource.NewObjectProperty(resource.PropertyMap{
"location": resource.NewStringProperty("testdata/noop"),
@@ -157,6 +159,7 @@ func TestImageLifecycle(t *testing.T) {
op: func(t *testing.T) integration.Operation {
return integration.Operation{
Inputs: resource.PropertyMap{
"push": resource.NewBoolProperty(false),
"tags": resource.NewArrayProperty(
[]resource.PropertyValue{resource.NewStringProperty("invalid-exports")},
),
@@ -189,6 +192,7 @@ func TestImageLifecycle(t *testing.T) {
op: func(t *testing.T) integration.Operation {
return integration.Operation{
Inputs: resource.PropertyMap{
"push": resource.NewBoolProperty(false),
"tags": resource.NewArrayProperty(
[]resource.PropertyValue{resource.NewStringProperty("foo")},
),
@@ -215,6 +219,7 @@ func TestImageLifecycle(t *testing.T) {
op: func(t *testing.T) integration.Operation {
return integration.Operation{
Inputs: resource.PropertyMap{
"push": resource.NewBoolProperty(false),
"tags": resource.NewArrayProperty(
[]resource.PropertyValue{resource.NewStringProperty("foo")},
),
@@ -246,6 +251,7 @@ func TestImageLifecycle(t *testing.T) {
op: func(t *testing.T) integration.Operation {
return integration.Operation{
Inputs: resource.PropertyMap{
"push": resource.NewBoolProperty(false),
"tags": resource.NewArrayProperty(
[]resource.PropertyValue{
resource.NewStringProperty("default-dockerfile"),

8
sdk/dotnet/Image.cs generated
View File

@@ -681,7 +681,7 @@ namespace Pulumi.DockerBuild
/// Equivalent to Docker's `--push` flag.
/// </summary>
[Output("push")]
public Output<bool?> Push { get; private set; } = null!;
public Output<bool> Push { get; private set; } = null!;
/// <summary>
/// If the image was pushed to any registries then this will contain a
@@ -765,7 +765,7 @@ namespace Pulumi.DockerBuild
/// <param name="name">The unique name of the resource</param>
/// <param name="args">The arguments used to populate this resource's properties</param>
/// <param name="options">A bag of options that control this resource's behavior</param>
public Image(string name, ImageArgs? args = null, CustomResourceOptions? options = null)
public Image(string name, ImageArgs args, CustomResourceOptions? options = null)
: base("docker-build:index:Image", name, args ?? new ImageArgs(), MakeResourceOptions(options, ""))
{
}
@@ -1018,8 +1018,8 @@ namespace Pulumi.DockerBuild
///
/// Equivalent to Docker's `--push` flag.
/// </summary>
[Input("push")]
public Input<bool>? Push { get; set; }
[Input("push", required: true)]
public Input<bool> Push { get; set; } = null!;
[Input("registries")]
private InputList<Inputs.RegistryArgs>? _registries;

View File

@@ -7,6 +7,7 @@ import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
@@ -655,7 +656,7 @@ type Image struct {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
Push pulumi.BoolPtrOutput `pulumi:"push"`
Push pulumi.BoolOutput `pulumi:"push"`
// If the image was pushed to any registries then this will contain a
// single fully-qualified tag including the build's digest.
//
@@ -712,9 +713,12 @@ type Image struct {
func NewImage(ctx *pulumi.Context,
name string, args *ImageArgs, opts ...pulumi.ResourceOption) (*Image, error) {
if args == nil {
args = &ImageArgs{}
return nil, errors.New("missing one or more required arguments")
}
if args.Push == nil {
return nil, errors.New("invalid value for required argument 'Push'")
}
if args.BuildOnPreview == nil {
args.BuildOnPreview = pulumi.BoolPtr(true)
}
@@ -862,7 +866,7 @@ type imageArgs struct {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
Push *bool `pulumi:"push"`
Push bool `pulumi:"push"`
// Registry credentials. Required if reading or exporting to private
// repositories.
//
@@ -1010,7 +1014,7 @@ type ImageArgs struct {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
Push pulumi.BoolPtrInput
Push pulumi.BoolInput
// Registry credentials. Required if reading or exporting to private
// repositories.
//
@@ -1271,8 +1275,8 @@ func (o ImageOutput) Pull() pulumi.BoolPtrOutput {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
func (o ImageOutput) Push() pulumi.BoolPtrOutput {
return o.ApplyT(func(v *Image) pulumi.BoolPtrOutput { return v.Push }).(pulumi.BoolPtrOutput)
func (o ImageOutput) Push() pulumi.BoolOutput {
return o.ApplyT(func(v *Image) pulumi.BoolOutput { return v.Push }).(pulumi.BoolOutput)
}
// If the image was pushed to any registries then this will contain a

View File

@@ -7,6 +7,7 @@ import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
@@ -655,7 +656,7 @@ type Image struct {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
Push pulumix.Output[*bool] `pulumi:"push"`
Push pulumix.Output[bool] `pulumi:"push"`
// If the image was pushed to any registries then this will contain a
// single fully-qualified tag including the build's digest.
//
@@ -712,9 +713,12 @@ type Image struct {
func NewImage(ctx *pulumi.Context,
name string, args *ImageArgs, opts ...pulumi.ResourceOption) (*Image, error) {
if args == nil {
args = &ImageArgs{}
return nil, errors.New("missing one or more required arguments")
}
if args.Push == nil {
return nil, errors.New("invalid value for required argument 'Push'")
}
if args.BuildOnPreview == nil {
args.BuildOnPreview = pulumix.Ptr(true)
}
@@ -862,7 +866,7 @@ type imageArgs struct {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
Push *bool `pulumi:"push"`
Push bool `pulumi:"push"`
// Registry credentials. Required if reading or exporting to private
// repositories.
//
@@ -1010,7 +1014,7 @@ type ImageArgs struct {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
Push pulumix.Input[*bool]
Push pulumix.Input[bool]
// Registry credentials. Required if reading or exporting to private
// repositories.
//
@@ -1274,9 +1278,9 @@ func (o ImageOutput) Pull() pulumix.Output[*bool] {
// Defaults to `false`.
//
// Equivalent to Docker's `--push` flag.
func (o ImageOutput) Push() pulumix.Output[*bool] {
value := pulumix.Apply[Image](o, func(v Image) pulumix.Output[*bool] { return v.Push })
return pulumix.Flatten[*bool, pulumix.Output[*bool]](value)
func (o ImageOutput) Push() pulumix.Output[bool] {
value := pulumix.Apply[Image](o, func(v Image) pulumix.Output[bool] { return v.Push })
return pulumix.Flatten[bool, pulumix.Output[bool]](value)
}
// If the image was pushed to any registries then this will contain a

View File

@@ -1023,7 +1023,7 @@ public class Image extends com.pulumi.resources.CustomResource {
*
*/
@Export(name="push", refs={Boolean.class}, tree="[0]")
private Output</* @Nullable */ Boolean> push;
private Output<Boolean> push;
/**
* @return When `true` the build will automatically include a `registry` export.
@@ -1033,8 +1033,8 @@ public class Image extends com.pulumi.resources.CustomResource {
* Equivalent to Docker&#39;s `--push` flag.
*
*/
public Output<Optional<Boolean>> push() {
return Codegen.optional(this.push);
public Output<Boolean> push() {
return this.push;
}
/**
* If the image was pushed to any registries then this will contain a
@@ -1209,7 +1209,7 @@ public class Image extends com.pulumi.resources.CustomResource {
* @param name The _unique_ name of the resulting resource.
* @param args The arguments to use to populate this resource's properties.
*/
public Image(String name, @Nullable ImageArgs args) {
public Image(String name, ImageArgs args) {
this(name, args, null);
}
/**
@@ -1218,7 +1218,7 @@ public class Image extends com.pulumi.resources.CustomResource {
* @param args The arguments to use to populate this resource's properties.
* @param options A bag of options that control this resource's behavior.
*/
public Image(String name, @Nullable ImageArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
public Image(String name, ImageArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super("docker-build:index:Image", name, args == null ? ImageArgs.Empty : args, makeResourceOptions(options, Codegen.empty()));
}

View File

@@ -16,6 +16,7 @@ import com.pulumi.dockerbuild.inputs.DockerfileArgs;
import com.pulumi.dockerbuild.inputs.ExportArgs;
import com.pulumi.dockerbuild.inputs.RegistryArgs;
import com.pulumi.dockerbuild.inputs.SSHArgs;
import com.pulumi.exceptions.MissingRequiredPropertyException;
import java.lang.Boolean;
import java.lang.String;
import java.util.List;
@@ -419,8 +420,8 @@ public final class ImageArgs extends com.pulumi.resources.ResourceArgs {
* Equivalent to Docker&#39;s `--push` flag.
*
*/
@Import(name="push")
private @Nullable Output<Boolean> push;
@Import(name="push", required=true)
private Output<Boolean> push;
/**
* @return When `true` the build will automatically include a `registry` export.
@@ -430,8 +431,8 @@ public final class ImageArgs extends com.pulumi.resources.ResourceArgs {
* Equivalent to Docker&#39;s `--push` flag.
*
*/
public Optional<Output<Boolean>> push() {
return Optional.ofNullable(this.push);
public Output<Boolean> push() {
return this.push;
}
/**
@@ -1158,7 +1159,7 @@ public final class ImageArgs extends com.pulumi.resources.ResourceArgs {
* @return builder
*
*/
public Builder push(@Nullable Output<Boolean> push) {
public Builder push(Output<Boolean> push) {
$.push = push;
return this;
}
@@ -1378,6 +1379,9 @@ public final class ImageArgs extends com.pulumi.resources.ResourceArgs {
public ImageArgs build() {
$.buildOnPreview = Codegen.booleanProp("buildOnPreview").output().arg($.buildOnPreview).def(true).getNullable();
$.network = Codegen.objectProp("network", NetworkMode.class).output().arg($.network).def(NetworkMode.Default_).getNullable();
if ($.push == null) {
throw new MissingRequiredPropertyException("ImageArgs", "push");
}
return $;
}
}

9
sdk/nodejs/image.ts generated
View File

@@ -640,7 +640,7 @@ export class Image extends pulumi.CustomResource {
*
* Equivalent to Docker's `--push` flag.
*/
public readonly push!: pulumi.Output<boolean | undefined>;
public readonly push!: pulumi.Output<boolean>;
/**
* If the image was pushed to any registries then this will contain a
* single fully-qualified tag including the build's digest.
@@ -711,10 +711,13 @@ export class Image extends pulumi.CustomResource {
* @param args The arguments to use to populate this resource's properties.
* @param opts A bag of options that control this resource's behavior.
*/
constructor(name: string, args?: ImageArgs, opts?: pulumi.CustomResourceOptions) {
constructor(name: string, args: ImageArgs, opts?: pulumi.CustomResourceOptions) {
let resourceInputs: pulumi.Inputs = {};
opts = opts || {};
if (!opts.id) {
if ((!args || args.push === undefined) && !opts.urn) {
throw new Error("Missing required property 'push'");
}
resourceInputs["addHosts"] = args ? args.addHosts : undefined;
resourceInputs["buildArgs"] = args ? args.buildArgs : undefined;
resourceInputs["buildOnPreview"] = (args ? args.buildOnPreview : undefined) ?? true;
@@ -918,7 +921,7 @@ export interface ImageArgs {
*
* Equivalent to Docker's `--push` flag.
*/
push?: pulumi.Input<boolean>;
push: pulumi.Input<boolean>;
/**
* Registry credentials. Required if reading or exporting to private
* repositories.

View File

@@ -17,6 +17,7 @@ __all__ = ['ImageArgs', 'Image']
@pulumi.input_type
class ImageArgs:
def __init__(__self__, *,
push: pulumi.Input[bool],
add_hosts: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
build_args: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
build_on_preview: Optional[pulumi.Input[bool]] = None,
@@ -33,7 +34,6 @@ class ImageArgs:
no_cache: Optional[pulumi.Input[bool]] = None,
platforms: Optional[pulumi.Input[Sequence[pulumi.Input['Platform']]]] = None,
pull: Optional[pulumi.Input[bool]] = None,
push: Optional[pulumi.Input[bool]] = None,
registries: Optional[pulumi.Input[Sequence[pulumi.Input['RegistryArgs']]]] = None,
secrets: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
ssh: Optional[pulumi.Input[Sequence[pulumi.Input['SSHArgs']]]] = None,
@@ -41,6 +41,11 @@ class ImageArgs:
target: Optional[pulumi.Input[str]] = None):
"""
The set of arguments for constructing a Image resource.
:param pulumi.Input[bool] push: When `true` the build will automatically include a `registry` export.
Defaults to `false`.
Equivalent to Docker's `--push` flag.
:param pulumi.Input[Sequence[pulumi.Input[str]]] add_hosts: Custom `host:ip` mappings to use during the build.
Equivalent to Docker's `--add-host` flag.
@@ -128,11 +133,6 @@ class ImageArgs:
:param pulumi.Input[bool] pull: Always pull referenced images.
Equivalent to Docker's `--pull` flag.
:param pulumi.Input[bool] push: When `true` the build will automatically include a `registry` export.
Defaults to `false`.
Equivalent to Docker's `--push` flag.
:param pulumi.Input[Sequence[pulumi.Input['RegistryArgs']]] registries: Registry credentials. Required if reading or exporting to private
repositories.
@@ -164,6 +164,7 @@ class ImageArgs:
Equivalent to Docker's `--target` flag.
"""
pulumi.set(__self__, "push", push)
if add_hosts is not None:
pulumi.set(__self__, "add_hosts", add_hosts)
if build_args is not None:
@@ -200,8 +201,6 @@ class ImageArgs:
pulumi.set(__self__, "platforms", platforms)
if pull is not None:
pulumi.set(__self__, "pull", pull)
if push is not None:
pulumi.set(__self__, "push", push)
if registries is not None:
pulumi.set(__self__, "registries", registries)
if secrets is not None:
@@ -213,6 +212,22 @@ class ImageArgs:
if target is not None:
pulumi.set(__self__, "target", target)
@property
@pulumi.getter
def push(self) -> pulumi.Input[bool]:
"""
When `true` the build will automatically include a `registry` export.
Defaults to `false`.
Equivalent to Docker's `--push` flag.
"""
return pulumi.get(self, "push")
@push.setter
def push(self, value: pulumi.Input[bool]):
pulumi.set(self, "push", value)
@property
@pulumi.getter(name="addHosts")
def add_hosts(self) -> Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]:
@@ -476,22 +491,6 @@ class ImageArgs:
def pull(self, value: Optional[pulumi.Input[bool]]):
pulumi.set(self, "pull", value)
@property
@pulumi.getter
def push(self) -> Optional[pulumi.Input[bool]]:
"""
When `true` the build will automatically include a `registry` export.
Defaults to `false`.
Equivalent to Docker's `--push` flag.
"""
return pulumi.get(self, "push")
@push.setter
def push(self, value: Optional[pulumi.Input[bool]]):
pulumi.set(self, "push", value)
@property
@pulumi.getter
def registries(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['RegistryArgs']]]]:
@@ -1030,7 +1029,7 @@ class Image(pulumi.CustomResource):
@overload
def __init__(__self__,
resource_name: str,
args: Optional[ImageArgs] = None,
args: ImageArgs,
opts: Optional[pulumi.ResourceOptions] = None):
"""
A Docker image built using buildx -- Docker's interface to the improved
@@ -1393,6 +1392,8 @@ class Image(pulumi.CustomResource):
__props__.__dict__["no_cache"] = no_cache
__props__.__dict__["platforms"] = platforms
__props__.__dict__["pull"] = pull
if push is None and not opts.urn:
raise TypeError("Missing required property 'push'")
__props__.__dict__["push"] = push
__props__.__dict__["registries"] = registries
__props__.__dict__["secrets"] = secrets
@@ -1676,7 +1677,7 @@ class Image(pulumi.CustomResource):
@property
@pulumi.getter
def push(self) -> pulumi.Output[Optional[bool]]:
def push(self) -> pulumi.Output[bool]:
"""
When `true` the build will automatically include a `registry` export.