This message was deleted.
# typescript
s
This message was deleted.
g
Haven’t tested it myself, but looks like you could use
const image = awsx.ecr.buildAndPushImage(apiRepoName, config.dockerContextPath, ...).imageValue;
to get the image name for k8s. If you need the fully-qualified name, you could do something like
Copy code
const repoImage = awsx.ecr.buildAndPushImage(apiRepoName, config.dockerContextPath, ...);

const fqImage = pulumi.concat(repoImage.repository, ":", repoImage.imageValue);
a
Hi @gorgeous-egg-16927, thanks for an answer, however it's different types:
Copy code
export declare abstract class Image implements ecs.ContainerImageProvider
and
Copy code
export declare class RepositoryImage implements ecs.ContainerImageProvider
awsx.ecr.buildAndPushImage
seems returns instance of some class which inherits abstract
Image
, while you suggest to use properties (
.imageValue
or
.repository
) from
RepositoryImage
(
ContainerImageProvider
does not have such properties defined...)
g
Copy code
const repoImage = awsx.ecr.buildAndPushImage("test", ".");
const appLabels = { app: "test" };
const deployment = new k8s.apps.v1.Deployment("test", {
        spec: {
            selector: { matchLabels: appLabels },
            replicas: 1,
            template: {
                metadata: { labels: appLabels },
                spec: {
                    containers: [{ name: "test", image: repoImage.imageValue}],
                },
            },
        }
    },
);
worked for me. Apparently you just need the
imageValue
property
a
@gorgeous-egg-16927 sorry I confuse you and myself... I am using
Copy code
const apiImage = awsx.ecs.Image.fromDockerBuild(repositoryApi, {
    context: config.dockerContextPath,
    dockerfile: config.dockerAPIFile
  });
i.e.
fromDockerBuild
, not
buildAndPushImage
so, return type is not
awsx.ecr.RepositoryImage
(which has property imageValue), but return type is
awsx.ecs.Image
@gorgeous-egg-16927 thanks for your help, but I was unable to "convert" between 2 of this types, so for now I generate images for usage in k8s with
buildAndPushImage
and for usage in Fargate with `fromDockerBuild`:
Copy code
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import * as config from "./config";
import { Environment } from "./environments";

export const createDockerImages = async (environment: Environment) => {
    
  const apiRepoName = `gauzy/api-${environment.toLowerCase()}`;

  const repositoryApi = new aws.ecr.Repository(apiRepoName, {
    name: apiRepoName
  });

  const webappRepoName = `gauzy/webapp-${environment.toLowerCase()}`;

  const repositoryWebapp = new aws.ecr.Repository(webappRepoName, {
    name: webappRepoName
  });

  let apiImage;

  // Build and publish a Docker image to a private ECR registry for API.
  if (environment !== Environment.Prod)
  {  
    apiImage = awsx.ecs.Image.fromDockerBuild(repositoryApi, {
      context: config.dockerContextPath,
      dockerfile: config.dockerAPIFile
    });
  }
  else 
  {
    apiImage = awsx.ecr.buildAndPushImage(
      apiRepoName,
      {
        context: config.dockerContextPath,
        dockerfile: config.dockerAPIFile
      },
      { repository: repositoryApi }
    );
  }

  let webappImage;
  
  // Build and publish a Docker image to a private ECR registry for Web App.
  if (environment !== Environment.Prod)
  {      
    webappImage = awsx.ecs.Image.fromDockerBuild(repositoryWebapp, {
      context: config.dockerContextPath,
      dockerfile: config.dockerWebappFile
    });
  } 
  else 
  {
    webappImage = awsx.ecr.buildAndPushImage(
      webappRepoName,
      {
        context: config.dockerContextPath,
        dockerfile: config.dockerWebappFile
      },
      { repository: repositoryWebapp }
    );
  }

  return { apiImage, webappImage };
};