Issue
BackGround
We are trying to create a Docker image from a Dockerfile in a specified directory, push it to the default repository of cdk, copy the image to a newly created repository, and call it from a lambda function.
The directory structure and the contents of the ecr.ts file that is causing the problem are as follows.
root
└ services
├ download_pdf
│ ├ lambda
: │ └ Dockerfile
└ infra
├ cdk.json
├ package.json
:
├ dist
└ src
├ index.ts
├ resource
│ ├ api-gateway.ts
│ ├ lambda.ts
│ └ ecr.ts
└ stack
└ download-pdf-stack.ts
import {createResourceName} from '@packages/infra-lib';
import {RemovalPolicy} from 'aws-cdk-lib';
import {Repository} from 'aws-cdk-lib/aws-ecr';
import {DockerImageAsset} from 'aws-cdk-lib/aws-ecr-assets';
import {DockerImageName, ECRDeployment} from 'cdk-ecr-deployment';
import {Construct} from 'constructs';
import path from 'path';
export function createRepositoryPuppeteer(scope: Construct): Repository {
const repo = new Repository(scope, 'RepositoryForPuppeteer', {
repositoryName: createResourceName(scope, 'repository-puppeteer'),
removalPolicy: RemovalPolicy.DESTROY,
});
const image = new DockerImageAsset(scope, 'DockerImageAssetPuppeteer', {
directory: path.join(__dirname, '../../../lambda'),
});
new ECRDeployment(scope, 'ECRDeploymentPuppeteer', {
src: new DockerImageName(image.imageUri),
dest: new DockerImageName(`${repo.repositoryUri}:latest`),
});
return repo;
}
Problem
When We try to deploy with the above, We get the following error.
$ yarn workspace @download-pdf/infra cdk deploy -vv DownloadPdfStack
[50%] check: Check xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/cdk-yyyyyyyyy-container-assets-xxxxxxxxxxxx-ap-northeast-1:zzzzzzzzzzzzzzzzzzzzzzzz
[AWS ecr 400 0.116s 0 retries] describeImages({
repositoryName: 'cdk-hnb659fds-container-assets-xxxxxxxxxxxx-ap-northeast-1',
imageIds: [
{
imageTag: 'zzzzzzzzzzzzzzzzzzzzzzzz'
},
[length]: 1
]
})
Call failed: describeImages({"repositoryName":"cdk-yyyyyyyyy-container-assets-xxxxxxxxxxxx-ap-northeast-1","imageIds":[{"imageTag":"zzzzzzzzzzzzzzzzzzzzzzzz"}]}) => The image with imageId {imageDigest:'null', imageTag:'zzzzzzzzzzzzzzzzzzzzzzzz'} does not exist within the repository with name 'cdk-yyyyyyyyy-container-assets-xxxxxxxxxxxx-ap-northeast-1' in the registry with id 'xxxxxxxxxxxx' (code=ImageNotFoundException)
[AWS ecr 200 0.099s 0 retries] getAuthorizationToken({})
[50%] debug: docker login --username AWS --password-stdin https://xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com
Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:156:25)
at writeGeneric (internal/stream_base_commons.js:147:3)
at Socket._writeGeneric (net.js:798:11)
at Socket._write (net.js:810:8)
at writeOrBuffer (internal/streams/writable.js:358:12)
at Socket.Writable.write (internal/streams/writable.js:303:10)
at /app/node_modules/cdk-assets/lib/private/shell.ts:28:19
at new Promise (<anonymous>)
at Object.shell (/app/node_modules/cdk-assets/lib/private/shell.ts:26:10)
at Docker.execute (/app/node_modules/cdk-assets/lib/private/docker.ts:131:13)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
We experimented with commenting it out and it seems that the error occurs in the sentence of 'new DockerImageAsset', but We don't know the cause of the error. We would like to know the cause of the above and how to solve the problem.
Solution
I found the cause of this problem: I was using cdk in a docker container, but since docker was not installed in this container, I could not create and push an image from the Dockerfile.
Answered By - k-akari
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.