acoustic-noon-6208
10/06/2019, 12:05 PMawsx.ecs.Image
) to be used with k8s deployments, however I narrow down issues to this:
// generate and push ECR image
const image = awsx.ecr.buildAndPushImage(apiRepoName, config.dockerContextPath, ...);
How can I use that image
in the k8s.apps.v1.Deployment container spec? It expects string value of path to the image published in some registry and all samples I can found in Pulumi just use some 'nginx' image, not custom build image like above with buildAndPushImage
method, which returns awsx.ecs.Image
type object. It's also very confusing how to get any information from image
object above, e.g. say registry path or even how to "await" such image to be built... (assuming I somehow can interpolate path to use it later).
Totally stuck, please HELP 🙂
(more details in https://pulumi-community.slack.com/archives/C84L4E3N1/p1569874384140300)gorgeous-egg-16927
10/07/2019, 3:28 PMconst 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
const repoImage = awsx.ecr.buildAndPushImage(apiRepoName, config.dockerContextPath, ...);
const fqImage = pulumi.concat(repoImage.repository, ":", repoImage.imageValue);
acoustic-noon-6208
10/07/2019, 4:54 PMexport declare abstract class Image implements ecs.ContainerImageProvider
and
export declare class RepositoryImage implements ecs.ContainerImageProvider
acoustic-noon-6208
10/07/2019, 4:55 PMawsx.ecr.buildAndPushImage
seems returns instance of some class which inherits abstract Image
, while you suggest to use properties (.imageValue
or .repository
) from RepositoryImage
acoustic-noon-6208
10/07/2019, 4:56 PMContainerImageProvider
does not have such properties defined...)gorgeous-egg-16927
10/08/2019, 7:23 PMconst 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
propertyacoustic-noon-6208
10/09/2019, 11:04 AMconst apiImage = awsx.ecs.Image.fromDockerBuild(repositoryApi, {
context: config.dockerContextPath,
dockerfile: config.dockerAPIFile
});
i.e. fromDockerBuild
, not buildAndPushImage
acoustic-noon-6208
10/09/2019, 11:06 AMawsx.ecr.RepositoryImage
(which has property imageValue), but return type is awsx.ecs.Image
acoustic-noon-6208
10/11/2019, 11:20 PMbuildAndPushImage
and for usage in Fargate with `fromDockerBuild`:
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 };
};