kind-school-28825
10/23/2020, 6:19 AM+ infra/
++ ecr/
+++ index.js <-- ecr.Repository & ecs.Image.fromPath
++ ecs/
+++ index.js <-- ecs.FargateService
++ index.js <-- main entry point
+ src/
+ Dockerfile
infra/ecr/index.js
var pulumi = require("@pulumi/pulumi");
var awsx = require("@pulumi/awsx");
var ecrRepo = new awsx.ecr.Repository("core", {
tags: {
Name: `core ${pulumi.getStack()} repository`,
},
});
var ecrRepoUrl = ecrRepo.repository.repositoryUrl;
var dockerImage = awsx.ecs.Image.fromPath(ecrRepo, "../../");
module.exports = { ecrRepoUrl, dockerImage };
infra/ecs/index.js
var awsx = require("@pulumi/awsx");
var { loadBalancerListener, securityGroup, vpc } = require("../network");
var { atlasCluster } = require("../mongodb");
var { dockerImage } = require("../ecr");
var { getEnvironmentVariables } = require("./helpers");
var ecsCluster = new awsx.ecs.Cluster("core-cluster", {
vpc,
securityGroups: [securityGroup],
});
var fargateService = new awsx.ecs.FargateService("core-fgs", {
ecsCluster,
taskDefinitionArgs: {
container: {
image: dockerImage,
cpu: 202,
memory: 1024,
portMappings: [loadBalancerListener],
healthCheck: {
command: ["CMD-SHELL", "curl -f <http://localhost:3000/> || exit 1"],
startPeriod: 10,
retries: 3,
},
environment: [
...getEnvironmentVariables(),
{
name: "DB_CONNECTION_URL",
value:
process.env.DB_CONNECTION_URL ||
atlasCluster.connectionStrings.standardSrv,
},
],
},
},
desiredCount: 1,
});
module.exports = { ecsCluster, fargateService };
infra/index.js
var { ecrRepoUrl, dockerImage } = require("./ecr");
var { fargateService } = require("./ecs");
module.exports = {
ecrRepositoryUrl: ecrRepoUrl,
image: dockerImage.environment,
fargateService: fargateService.urn,
};
When running pulumi I get the following errorfaint-table-42725
10/23/2020, 4:13 PMvar dockerImage = awsx.ecs.Image.fromPath(ecrRepo, "../../");
ecrRepo
should be an aws.ecr.Repository
and not awsx.ecr.Repository
(this is slightly confusing, but becomes more clear if this example is run under TypeScript since the type-checking will fail). If you pass in ecrRepo.repistory
does it work for you?kind-school-28825
10/23/2020, 10:02 PMfaint-table-42725
10/23/2020, 10:21 PMawsx
is a higher-level component library that abstracts away some of the complexities of working with the ‘raw’ AWS resources in aws
. awsx
makes various opinionated defaults about how to set things up so you don’t have to think about it. In this case, the ecs
part of awsx
was built so that it could interop with any repository (awsx or not), which is why it takes an aws.ecr.Repository
— probably what could be done to make this even easier is to accept an awsx.ecr.Repository
object as well and if it gets one of those, just grab the repository
property from that object. Feel free to file an issue if you think that is a worthwhile ergonomic change.