aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.66k stars 3.92k forks source link

cdk-assets: [Windows] Failed to docker from Tarball assets. [100%] fail: spawn sh ENOENT #20731

Open yeDor opened 2 years ago

yeDor commented 2 years ago

Describe the bug

command: cdk deploy *-dev under linux deploy process works fine, but the same project under windows ends with error. Looks like cdk tries to spawn a sh process and fails under windows.

Expected Behavior

same behavior on windows and linux machine. Probably not spawn "sh" during publishing docker image from Tarball.

Current Behavior

app-dev
app-dev: deploying...
Retrieved account ID XXXXXXXXXXX from disk cache
Assuming role 'arn:aws:iam::XXXXXXXXXXX:role/cdk-hnb659fds-deploy-role-XXXXXXXXXXX-eu-central-1'.
Waiting for stack CDKToolkit to finish creating or updating...
[0%] start: Publishing d2922772e7f7c307b3e65a4e5338de4859973b8ce43567f974d87d86806153cf:XXXXXXXXXXX-eu-central-1
[0%] start: Publishing 60444682739e7d4b7433c805f6a6c40abd1aba2f779ea396ae2d04971fc96311:XXXXXXXXXXX-eu-central-1
Retrieved account ID XXXXXXXXXXX from disk cache
Assuming role 'arn:aws:iam::XXXXXXXXXXX:role/cdk-hnb659fds-file-publishing-role-XXXXXXXXXXX-eu-central-1'.
Retrieved account ID XXXXXXXXXXX from disk cache
Assuming role 'arn:aws:iam::XXXXXXXXXXX:role/cdk-hnb659fds-image-publishing-role-XXXXXXXXXXX-eu-central-1'.
[0%] check: Check s3://cdk-hnb659fds-assets-XXXXXXXXXXX-eu-central-1/d2922772e7f7c307b3e65a4e5338de4859973b8ce43567f974d87d86806153cf.json
[0%] check: Check XXXXXXXXXXX.dkr.ecr.eu-central-1.amazonaws.com/cdk-hnb659fds-container-assets-XXXXXXXXXXX-eu-central-1:60444682739e7d4b7433c805f6a6c40abd1aba2f779ea396ae2d04971fc96311 Call failed: describeImages({"repositoryName":"cdk-hnb659fds-container-assets-XXXXXXXXXXX-eu-central-1","imageIds":[{"imageTag":"60444682739e7d4b7433c805f6a6c40abd1aba2f779ea396ae2d04971fc96311"}]}) => The image with imageId {imageDigest:'null', imageTag:'60444682739e7d4b7433c805f6a6c40abd1aba2f779ea396ae2d04971fc96311'} does not exist within the repository with name 'cdk-hnb659fds-container-assets-XXXXXXXXXXX-eu-central-1' in the registry with id 'XXXXXXXXXXX' (code=ImageNotFoundException)
[0%] debug: docker login --username AWS --password-stdin https://XXXXXXXXXXX.dkr.ecr.eu-central-1.amazonaws.com
[0%] upload: Upload s3://cdk-hnb659fds-assets-XXXXXXXXXXX-eu-central-1/d2922772e7f7c307b3e65a4e5338de4859973b8ce43567f974d87d86806153cf.json
[50%] success: Published d2922772e7f7c307b3e65a4e5338de4859973b8ce43567f974d87d86806153cf:XXXXXXXXXXX-eu-central-1
[50%] build: Building Docker image using command 'sh,-c,docker load -i asset.60444682739e7d4b7433c805f6a6c40abd1aba2f779ea396ae2d04971fc96311.tar | sed "s/Loaded image: //g"'
[100%] fail: spawn sh ENOENT

 ❌  app-dev failed: Error: Failed to publish one or more assets. See the error messages above for more information.
    at publishAssets (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\util\asset-publishing.ts:44:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at CloudFormationDeployments.publishStackAssets (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\api\cloudformation-deployments.ts:464:7)
    at CloudFormationDeployments.deployStack (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\api\cloudformation-deployments.ts:339:7)
    at CdkToolkit.deploy (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\cdk-toolkit.ts:209:24)
    at initCommandLine (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\cli.ts:341:12)
Reading cached notices from C:\Users\Yevgen\.cdk\cache\notices.json

Failed to publish one or more assets. See the error messages above for more information.
Error: Failed to publish one or more assets. See the error messages above for more information.
    at publishAssets (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\util\asset-publishing.ts:44:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at CloudFormationDeployments.publishStackAssets (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\api\cloudformation-deployments.ts:464:7)
    at CloudFormationDeployments.deployStack (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\api\cloudformation-deployments.ts:339:7)
    at CdkToolkit.deploy (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\cdk-toolkit.ts:209:24)
    at initCommandLine (C:\Users\Yevgen\AppData\Roaming\npm\node_modules\aws-cdk\lib\cli.ts:341:12)

Reproduction Steps

dwcDownloadTaskDefinition = FargateTaskDefinition.Builder.create(this, "TaskDefinition").build();

containerDefinition = dwcDownloadTaskDefinition.addContainer("AppContainer",
    ContainerDefinitionOptions.builder()
                              .image(ContainerImage.fromTarball("build/assets/app.tar"))
                              .build());

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.27.0 (build 8e89048)

Framework Version

No response

Node.js Version

v16.5.0

OS

Windows 10

Language

Java

Language Version

8

Other information

No response

eesquibel commented 2 years ago

I am also having this issue when trying to use the ContainerImage.fromTarball method on Windows 11.

cdk --version 2.28.1 (build d035432)

npm --version 8.12.1

node --version v16.15.1

andreasdamm commented 2 years ago

Looks like https://github.com/aws/aws-cdk/blob/76e0768f6d69b555925bb3c016861f517a01ecae/packages/%40aws-cdk/aws-ecr-assets/lib/tarball-asset.ts#L72 really wants to pass the output of "docker load" through sed and hence it is trying to launch sh. Really, that output manipulation needs to be done in code.