Skip to content

Commit

Permalink
Add imageName param to ECR image args (#1257)
Browse files Browse the repository at this point in the history
Fixes #1171

This allows the user to manually choose the name of the underlying
Pulumi Docker image resource

When not defined it will fall back to the original behavior (use the
image tag as the name of the underlying resource)

---------

Co-authored-by: Anton Tayanovskyy <anton@pulumi.com>
  • Loading branch information
sav-valerio and t0yv0 committed Apr 12, 2024
1 parent 9318293 commit 7d35941
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 1 deletion.
7 changes: 6 additions & 1 deletion awsx/ecr/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export function computeImageFromAsset(

pulumi.log.debug(`Building container image at '${JSON.stringify(dockerInputs)}'`, parent);

const imageName = imageTag ? imageTag : createUniqueImageName(dockerInputs);
const imageName = args.imageName
? args.imageName
: imageTag
? imageTag
: createUniqueImageName(dockerInputs);

// Note: the tag, if provided, is included in the image name.
const canonicalImageName = `${repositoryUrl}:${imageName}`;

Expand Down
3 changes: 3 additions & 0 deletions awsx/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface ImageArgs {
readonly cacheFrom?: pulumi.Input<pulumi.Input<string>[]>;
readonly context?: pulumi.Input<string>;
readonly dockerfile?: pulumi.Input<string>;
readonly imageName?: pulumi.Input<string>;
readonly imageTag?: pulumi.Input<string>;
readonly platform?: pulumi.Input<string>;
readonly registryId?: pulumi.Input<string>;
Expand Down Expand Up @@ -640,6 +641,7 @@ export interface DockerBuildInputs {
readonly cacheFrom?: pulumi.Input<pulumi.Input<string>[]>;
readonly context?: pulumi.Input<string>;
readonly dockerfile?: pulumi.Input<string>;
readonly imageName?: pulumi.Input<string>;
readonly imageTag?: pulumi.Input<string>;
readonly platform?: pulumi.Input<string>;
readonly target?: pulumi.Input<string>;
Expand All @@ -650,6 +652,7 @@ export interface DockerBuildOutputs {
readonly cacheFrom?: pulumi.Output<string[]>;
readonly context?: pulumi.Output<string>;
readonly dockerfile?: pulumi.Output<string>;
readonly imageName?: pulumi.Output<string>;
readonly imageTag?: pulumi.Output<string>;
readonly platform?: pulumi.Output<string>;
readonly target?: pulumi.Output<string>;
Expand Down
8 changes: 8 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@
"type": "string",
"description": "dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context."
},
"imageName": {
"type": "string",
"description": "Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used"
},
"imageTag": {
"type": "string",
"description": "Custom image tag for the resulting docker image. If omitted a random string will be used"
Expand Down Expand Up @@ -2154,6 +2158,10 @@
"type": "string",
"description": "dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context."
},
"imageName": {
"type": "string",
"description": "Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used"
},
"imageTag": {
"type": "string",
"description": "Custom image tag for the resulting docker image. If omitted a random string will be used"
Expand Down
6 changes: 6 additions & 0 deletions schemagen/pkg/gen/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ func dockerBuildProperties(dockerSpec schema.PackageSpec) map[string]schema.Prop
Type: "string",
},
},
"imageName": {
Description: "Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used",
TypeSpec: schema.TypeSpec{
Type: "string",
},
},
"imageTag": {
Description: "Custom image tag for the resulting docker image. If omitted a random string will be used",
TypeSpec: schema.TypeSpec{
Expand Down
6 changes: 6 additions & 0 deletions sdk/dotnet/Ecr/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public InputList<string> CacheFrom
[Input("dockerfile")]
public Input<string>? Dockerfile { get; set; }

/// <summary>
/// Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
/// </summary>
[Input("imageName")]
public Input<string>? ImageName { get; set; }

/// <summary>
/// Custom image tag for the resulting docker image. If omitted a random string will be used
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions sdk/go/awsx/ecr/image.go

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

2 changes: 2 additions & 0 deletions sdk/go/awsx/ecr/pulumiTypes.go

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

37 changes: 37 additions & 0 deletions sdk/java/src/main/java/com/pulumi/awsx/ecr/ImageArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ public Optional<Output<String>> dockerfile() {
return Optional.ofNullable(this.dockerfile);
}

/**
* Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
*
*/
@Import(name="imageName")
private @Nullable Output<String> imageName;

/**
* @return Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
*
*/
public Optional<Output<String>> imageName() {
return Optional.ofNullable(this.imageName);
}

/**
* Custom image tag for the resulting docker image. If omitted a random string will be used
*
Expand Down Expand Up @@ -176,6 +191,7 @@ private ImageArgs(ImageArgs $) {
this.cacheFrom = $.cacheFrom;
this.context = $.context;
this.dockerfile = $.dockerfile;
this.imageName = $.imageName;
this.imageTag = $.imageTag;
this.platform = $.platform;
this.registryId = $.registryId;
Expand Down Expand Up @@ -306,6 +322,27 @@ public Builder dockerfile(String dockerfile) {
return dockerfile(Output.of(dockerfile));
}

/**
* @param imageName Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
*
* @return builder
*
*/
public Builder imageName(@Nullable Output<String> imageName) {
$.imageName = imageName;
return this;
}

/**
* @param imageName Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
*
* @return builder
*
*/
public Builder imageName(String imageName) {
return imageName(Output.of(imageName));
}

/**
* @param imageTag Custom image tag for the resulting docker image. If omitted a random string will be used
*
Expand Down
5 changes: 5 additions & 0 deletions sdk/nodejs/ecr/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class Image extends pulumi.ComponentResource {
resourceInputs["cacheFrom"] = args ? args.cacheFrom : undefined;
resourceInputs["context"] = args ? args.context : undefined;
resourceInputs["dockerfile"] = args ? args.dockerfile : undefined;
resourceInputs["imageName"] = args ? args.imageName : undefined;
resourceInputs["imageTag"] = args ? args.imageTag : undefined;
resourceInputs["platform"] = args ? args.platform : undefined;
resourceInputs["registryId"] = args ? args.registryId : undefined;
Expand Down Expand Up @@ -87,6 +88,10 @@ export interface ImageArgs {
* dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.
*/
dockerfile?: pulumi.Input<string>;
/**
* Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
*/
imageName?: pulumi.Input<string>;
/**
* Custom image tag for the resulting docker image. If omitted a random string will be used
*/
Expand Down
20 changes: 20 additions & 0 deletions sdk/python/pulumi_awsx/ecr/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(__self__, *,
cache_from: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
context: Optional[pulumi.Input[str]] = None,
dockerfile: Optional[pulumi.Input[str]] = None,
image_name: Optional[pulumi.Input[str]] = None,
image_tag: Optional[pulumi.Input[str]] = None,
platform: Optional[pulumi.Input[str]] = None,
registry_id: Optional[pulumi.Input[str]] = None,
Expand All @@ -33,6 +34,7 @@ def __init__(__self__, *,
:param pulumi.Input[Sequence[pulumi.Input[str]]] cache_from: Images to consider as cache sources
:param pulumi.Input[str] context: Path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.
:param pulumi.Input[str] dockerfile: dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.
:param pulumi.Input[str] image_name: Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
:param pulumi.Input[str] image_tag: Custom image tag for the resulting docker image. If omitted a random string will be used
:param pulumi.Input[str] platform: The architecture of the platform you want to build this image for, e.g. `linux/arm64`.
:param pulumi.Input[str] registry_id: ID of the ECR registry in which to store the image. If not provided, this will be inferred from the repository URL)
Expand All @@ -49,6 +51,8 @@ def __init__(__self__, *,
pulumi.set(__self__, "context", context)
if dockerfile is not None:
pulumi.set(__self__, "dockerfile", dockerfile)
if image_name is not None:
pulumi.set(__self__, "image_name", image_name)
if image_tag is not None:
pulumi.set(__self__, "image_tag", image_tag)
if platform is not None:
Expand Down Expand Up @@ -130,6 +134,18 @@ def dockerfile(self) -> Optional[pulumi.Input[str]]:
def dockerfile(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "dockerfile", value)

@property
@pulumi.getter(name="imageName")
def image_name(self) -> Optional[pulumi.Input[str]]:
"""
Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
"""
return pulumi.get(self, "image_name")

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

@property
@pulumi.getter(name="imageTag")
def image_tag(self) -> Optional[pulumi.Input[str]]:
Expand Down Expand Up @@ -189,6 +205,7 @@ def __init__(__self__,
cache_from: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
context: Optional[pulumi.Input[str]] = None,
dockerfile: Optional[pulumi.Input[str]] = None,
image_name: Optional[pulumi.Input[str]] = None,
image_tag: Optional[pulumi.Input[str]] = None,
platform: Optional[pulumi.Input[str]] = None,
registry_id: Optional[pulumi.Input[str]] = None,
Expand All @@ -205,6 +222,7 @@ def __init__(__self__,
:param pulumi.Input[Sequence[pulumi.Input[str]]] cache_from: Images to consider as cache sources
:param pulumi.Input[str] context: Path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.
:param pulumi.Input[str] dockerfile: dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.
:param pulumi.Input[str] image_name: Custom name for the underlying Docker image resource. If omitted, the image tag assigned by the provider will be used
:param pulumi.Input[str] image_tag: Custom image tag for the resulting docker image. If omitted a random string will be used
:param pulumi.Input[str] platform: The architecture of the platform you want to build this image for, e.g. `linux/arm64`.
:param pulumi.Input[str] registry_id: ID of the ECR registry in which to store the image. If not provided, this will be inferred from the repository URL)
Expand Down Expand Up @@ -240,6 +258,7 @@ def _internal_init(__self__,
cache_from: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
context: Optional[pulumi.Input[str]] = None,
dockerfile: Optional[pulumi.Input[str]] = None,
image_name: Optional[pulumi.Input[str]] = None,
image_tag: Optional[pulumi.Input[str]] = None,
platform: Optional[pulumi.Input[str]] = None,
registry_id: Optional[pulumi.Input[str]] = None,
Expand All @@ -261,6 +280,7 @@ def _internal_init(__self__,
__props__.__dict__["cache_from"] = cache_from
__props__.__dict__["context"] = context
__props__.__dict__["dockerfile"] = dockerfile
__props__.__dict__["image_name"] = image_name
__props__.__dict__["image_tag"] = image_tag
__props__.__dict__["platform"] = platform
__props__.__dict__["registry_id"] = registry_id
Expand Down

0 comments on commit 7d35941

Please sign in to comment.