1

I have two stacks CdkVrStack and CdkVrDeployStack

in CdkVrStack, repository my-repo-name is created.

export class CdkVrStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    const repo_ = new ecr.Repository(this, 'TestRepoId', {
      repositoryName: "my-repo-name",
      removalPolicy: RemovalPolicy.DESTROY
    });

then in CdkVrDeployStack I try to upload the docker image

export class CdkVrDeployStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);
    //maybe repositoryName is deprecated, so how can I set the repository which CdkVrStack created
    
    this.synthesizer.addDockerImageAsset({
      directoryName: path.join(__dirname, 'app1'), 
      repositoryName: "my-repo-name", // this is deprecated how can I se the repository?
      sourceHash: "image-tag",
    });
  }
}

I can't compile CdkVrStack

lib/cdk_vr-deploy-stack.ts:19:7 - error TS2345: Argument of type '{ directoryName: string; repositoryName: string; sourceHash: string; }' is not assignable to parameter of type 'DockerImageAssetSource'.
  Object literal may only specify known properties, and 'repositoryName' does not exist in type 'DockerImageAssetSource'.

19       repositoryName: "my-repo-name", 
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[0:39:30] Found 1 error. Watching for file changes.


I tested this code in one stack, from this document

const repo_ = new ecr.Repository(this, 'TestRepoId', {
  repositoryName: "my-repo-name",
  removalPolicy: RemovalPolicy.DESTROY
});

new DockerImageAsset(this,'mydockerimageassets',{
  directory: path.join(__dirname, '../docker-lambda'),
  repository:repo_
});

However ,theter comes error

lib/cdk_vr-base-stack.ts:63:7 - error TS2345: Argument of type '{ directory: string; repository: ecr.Repository; }' is not assignable to parameter of type 'DockerImageAssetProps'.
  Object literal may only specify known properties, and 'repository' does not exist in type 'DockerImageAssetProps'.

63       repository:repo_
         ~~~~~~~~~~~~~~~~

repository is the properties of DockerImageAsset, where am I wrong?

gshpychka
  • 8,523
  • 1
  • 11
  • 31
whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

3

I use https://github.com/cdklabs/cdk-ecr-deployment

I can make repository and push image with this code.

import * as ecrdeploy from 'cdk-ecr-deployment';

    
const repo_ = new ecr.Repository(this, 'TestRepoId', {
  repositoryName: "my-repo-name",
  removalPolicy: RemovalPolicy.DESTROY
});

const image_ = new DockerImageAsset(this,'mydockerimageassets',{
  directory: path.join(__dirname, '../docker-lambda'),
  
});
new ecrdeploy.ECRDeployment(this, 'DeployDockerImage', {
  src: new ecrdeploy.DockerImageName(image_.imageUri),
  dest: new ecrdeploy.DockerImageName(`${repo_.repositoryUri}:latest`),
});
gshpychka
  • 8,523
  • 1
  • 11
  • 31
whitebear
  • 11,200
  • 24
  • 114
  • 237
  • FYI you're still uploading to the asset ECR repo, then copying it to your own repo. – gshpychka Jan 27 '22 at 10:58
  • Not really, by default `DockerImageAsset` won't push to any repo unless its attached to another resource. The `ECRDeployment` provides that attachment. – Chris Rice Jul 10 '23 at 15:49