aws / aws/aws-cdk

(aws_ecr_assets): DockerImageAsset cache_from not compatible with Docker < V23

Open
#27,752 2 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-ecr-assets bug effort/medium p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

In `aws-cdk=2.83.0`, the `--cache-from` option in DockerImageAsset is generated in an incorrect format for Docker versions below v23. This conflicts with the default CodeBuild image and the available options in LinuxBuildImage, all using Docker v20, rendering the argument incompatible. Upgrading to version `aws-cdk=2.103.1` resolves the issue as the default CodeBuild image shifts to the latest version using Docker v23.

### Expected Behavior

As I understand for docker versions < 23.0 the argument should be:
```
docker build --build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from aws_account_id.dkr.ecr.region.amazonaws.com/test-cache:latest --tag aws_account_id.dkr.ecr.region.amazonaws.com/test-cache:latest .

```
Note:
- The specific image must be pulled before executing the build command.
- Setting DOCKER_BUILDKIT=1

### Current Behavior

`--cache-from` arguments passed this way does not work.

```
docker build --build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from type=registry,ref=aws_account_id.dkr.ecr.region.amazonaws.com/test-cache:latest --tag aws_account_id.dkr.ecr.region.amazonaws.com/test-cache:latest .
```

Logs:
```
#4 importing cache manifest from type=registry
#4 sha256:93f1eeb6dd5502f7b6fb1241aec4210182a26fdda27e6428206dbb834c4cb716
#4 ERROR: invalid reference format
 
#10 importing cache manifest from ref=aws_account_id.dkr.ecr.region.amazonaws.com/test-cache:latest
#10 sha256:211a9356f59d3fa5e67b3c2ce00d0d0c859b8ecc2c83ab2fe18913486a993e6b
#10 ERROR: invalid reference format
```

### Reproduction Steps

I can provide a small example or a repository if needed for further clarification.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.83.0

### Framework Version

_No response_

### Node.js Version

v18.18.2

### OS

mac

### Language

Python

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the aws_ecr_assets DockerImageAsset implementation and trace how cache_from becomes the docker build command. Compare the generated --cache-from format and required image-pull behavior for Docker versions below v23 with the v23 format. Done means Docker v20 accepts the generated command while the existing Docker v23 behavior remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, typescript
Domain
cloud, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.