通过 aws-cdk 将 docker 图像推送到目标存储库
Pushing docker image to the target repository by aws-cdk
我有两个堆栈 CdkVrStack
和 CdkVrDeployStack
在 CdkVrStack
中,已创建存储库 my-repo-name。
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
});
然后在 CdkVrDeployStack
我尝试上传 docker 图片
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",
});
}
}
我无法编译 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] 发现 1 个错误。正在监视文件更改。
我在一个堆栈中测试了这段代码,从这个 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_
});
然而,随后出现错误
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
是DockerImageAsset
的属性,我哪里错了?
我用https://github.com/cdklabs/cdk-ecr-deployment
我可以用这段代码制作存储库和推送图像。
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`),
});
我有两个堆栈 CdkVrStack
和 CdkVrDeployStack
在 CdkVrStack
中,已创建存储库 my-repo-name。
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
});
然后在 CdkVrDeployStack
我尝试上传 docker 图片
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",
});
}
}
我无法编译 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] 发现 1 个错误。正在监视文件更改。
我在一个堆栈中测试了这段代码,从这个 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_
});
然而,随后出现错误
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
是DockerImageAsset
的属性,我哪里错了?
我用https://github.com/cdklabs/cdk-ecr-deployment
我可以用这段代码制作存储库和推送图像。
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`),
});