https://pulumi.com logo
#general
Title
# general
s

stale-park-1622

09/27/2019, 2:08 PM
why is the following code, creating 6 resources instead of 3? If I understood the api correctly, i can create a ECR repository and pass it into the buildAndPushImage
Copy code
export function createApiImage(name: string, port: number, contextDir: string): {repositoryUrl: pulumi.Output<string>, image: awsx.ecr.RepositoryImage} {
  
  const gitCommit = 'e0e5162';

  // set up ECR Lifecycle Policies (<https://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html>) 
  // remove any images that are older than one week that are untagged
  const repository = new awsx.ecr.Repository(`pulumi-${pulumi.getStack()}-repository`, {
    lifeCyclePolicyArgs: {
      rules: [{
          selection: "untagged",
          maximumAgeLimit: 7,
      }],
    }
  });

  // And publish its URL, so we can push to it if we'd like.
  const repositoryUrl = repository.repository.repositoryUrl;

  const build: docker.DockerBuild = {
    context: contextDir, // context is a path to a directory to use for the Docker build context
    dockerfile: path.join(contextDir, './docker/api.v2.Dockerfile'), // dockerfile may be used to override the default Dockerfile name and/or location
    args: {
      EXPOSE_PORT: String(port),
    },
  };

  // Invoke 'docker' to actually build the DockerFile that is in the folder relative to
  // this program. Once built, push that image up to the ECR repo.
  //const image = repository.buildAndPushImage(build);
  const image = awsx.ecr.buildAndPushImage(
    `${name}:${gitCommit}`,
    build,
    {
      repository: repository.repository,
    }
  );

  return {repositoryUrl, image};
}
Copy code
→ pulumi up
Previewing update (dev):

     Type                           Name                          Plan
 +   pulumi:pulumi:Stack            dev                    create
 +   ├─ awsx:ecr:Repository         dev-api-image:e0e5162  create
 +   │  └─ aws:ecr:LifecyclePolicy  dev-api-image:e0e5162  create
 +   └─ awsx:ecr:Repository         pulumi-dev-repository         create
 +      ├─ aws:ecr:Repository       pulumi-dev-repository         create
 +      └─ aws:ecr:LifecyclePolicy  pulumi-dev-repository         create

Resources:
    + 6 to create

Do you want to perform this update?
  yes
> no
  details
t

tall-librarian-49374

09/27/2019, 2:13 PM
There are only 3 actual resources here. 2 others are "component resources" virtual containers that don't map to anything in AWS on their own. And the last one is a stack, the top-level container.
Maybe it would be useful to differentiate them visually
h

handsome-actor-1155

09/27/2019, 5:14 PM
I think differentiating them would be a nice touch. Would certainly provide better visual feedback when watching the output as a stack completes as well.
s

stale-park-1622

09/27/2019, 5:38 PM
thank you for the explanation. Yes, it would be nice to see, what resources are actually created on aws.
t

tall-librarian-49374

09/27/2019, 6:51 PM
Do you mind creating an issue for this in https://github.com/pulumi/pulumi/ ?
s

stale-park-1622

10/15/2019, 10:05 AM
sorry, just saw this message now. certianly i can do that
t

tall-librarian-49374

10/15/2019, 8:39 PM
❤️
3 Views