Commit 009680d
authored
fix(ecr-assets): handle Docker 27.4+ output format in TarballImageAsset (#33967)
### Issue # (if applicable)
Closes #33428.
### Reason for this change
The TarballImageAsset class was failing to properly extract image IDs from Docker 27.4+ output due to a format change from "Loaded image: <digest>" to "Loaded image ID: <digest>". This caused the sed command to fail to properly extract the image ID, resulting in an invalid tag format.
After reviewing Docker CLI issue docker/cli#2212 (open since 2019), I found that Docker has actually had two distinct output formats for the `docker load` command for some time:
- For images with tags: "Loaded image: <image-name>"
- For images without tags: "Loaded image ID: <digest>"
See:
https://github.com/moby/moby/blob/37f866285af6910f838c762912dfd57396783b72/image/tarexport/load.go#L140-L159
While the issue was triggered by Docker 27.4, the underlying problem is that our code was only handling one of these output formats. We need a solution that handles both formats.
### Description of changes
- Introduced a more flexible regex pattern (`s/Loaded image[^:]*: //g`) that handles both output formats
- Extracted the pattern to a shared constant `DOCKER_LOAD_OUTPUT_REGEX` for consistency and maintainability
- Updated the code in `tarball-asset.ts` to use the new regex pattern
- Added unit tests to verify compatibility with both Docker output formats
- Ensured backward compatibility with older Docker versions
This approach makes our code more robust against variations in Docker's output format.
### Describe any new or updated permissions being added
No new or updated IAM permissions are needed for this change.
### Description of how you validated changes
- Created unit tests that verify the new regex pattern works with both formats using hardcoded test strings:
- "Loaded image: <digest>" (older Docker versions)
- "Loaded image ID: <digest>" (Docker 27.4+)
- Verified that the old sed expression fails with the new format
- Confirmed all existing tests pass with the new implementation
### Checklist
- [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*1 parent a8edf69 commit 009680d
File tree
2 files changed
+42
-3
lines changed- packages/aws-cdk-lib/aws-ecr-assets
- lib
- test
2 files changed
+42
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
8 | 16 | | |
9 | 17 | | |
10 | 18 | | |
| |||
99 | 107 | | |
100 | 108 | | |
101 | 109 | | |
102 | | - | |
| 110 | + | |
103 | 111 | | |
104 | 112 | | |
105 | 113 | | |
| |||
Lines changed: 33 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
163 | 194 | | |
164 | 195 | | |
165 | 196 | | |
| |||
0 commit comments