Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@aws-cdk/aws-ecr-assets: TarballImageAsset is not properly docker-loading image with docker 27.4 #33428

Open
1 task
ajaest opened this issue Feb 13, 2025 · 1 comment · May be fixed by #33430
Open
1 task
Labels
@aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@ajaest
Copy link

ajaest commented Feb 13, 2025

Describe the bug

Hi,

I am having a problem using TarballImageAsset as a grep expression used to get the image digest is not ok for the docker version/OS I am currently using.

My code:

const image = new TarballImageAsset(this, `${taskEnvId}ContainerImage`,{
      tarballFile: path.join(__dirname, '..', '..', 'image.tar.gz')
})

The error:

[11:37:20] my-app: build: Building Docker image using command 'sh,-c,docker load -i asset.2fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafaf.tar.gz | tail -n 1 | sed "s/Loaded image: //g"'
my-app: success: Published c12098d40a4cc1e247b7041b9e6fefa4c1596ff63692672b5c386d002d00862c:123123123123-eu-central-1
[11:37:23] my-app: debug: docker tag 'Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a' 123123123123.dkr.ecr.eu-central-1.amazonaws.com/cdk-hnb659fds-container-assets-123123123123-eu-central-1:2fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafaf
Error parsing reference: "Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a" is not a valid repository/tag: invalid reference format: repository name (library/Loaded image ID) must be lowercase
my-app: fail: docker tag 'Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a' 123123123123.dkr.ecr.eu-central-1.amazonaws.com/cdk-hnb659fds-container-assets-123123123123-eu-central-1:2fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafaf exited with error code 1: Error parsing reference: "Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a" is not a valid repository/tag: invalid reference format: repository name (library/Loaded image ID) must be lowercase

My docker environment (Mac):

$> docker version

Client:
 Version:           27.4.0
 API version:       1.47
 Go version:        go1.22.10
 Git commit:        bde2b89
 Built:             Sat Dec  7 10:35:43 2024
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.37.2 (179585)
 Engine:
  Version:          27.4.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.10
  Git commit:       92a8393
  Built:            Sat Dec  7 10:38:33 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.21
  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The asset tarball should be imported to local docker image cache, tagged and uploaded to ECR.

Current Behavior

The asset tarball cannot be imported to local docker image cache as the image tag is is cleaned with a sed expression that is not properly built for latest docker clients.

Reproduction Steps

Ensure you use the latest docker version for mac, similar to this one:

$> docker version

Client:
 Version:           27.4.0
 API version:       1.47
 Go version:        go1.22.10
 Git commit:        bde2b89
 Built:             Sat Dec  7 10:35:43 2024
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.37.2 (179585)
 Engine:
  Version:          27.4.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.10
  Git commit:       92a8393
  Built:            Sat Dec  7 10:38:33 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.21
  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Create a tarball image asset as follows:

const image = new TarballImageAsset(this, `${taskEnvId}ContainerImage`,{
      tarballFile: path.join(__dirname, '..', '..', 'image.tar.gz')
})

Run a CDK synth stack with that asset.

Possible Solution

The problem seems to be the sed expression used here, that expects docker load output to match the expression Loaded image: <digest>.

However, in the attached docker version docker load actually prints Loaded image ID: <digest>.

Just changing the sed expression from sed "s/Loaded image: //g" to sed "s/Loaded image[^:]*: //g" or similar should work for every scenario. For example:

$> echo 'Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'| sed  "s/Loaded image[^:]*: //g"
sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a

$> echo 'Loaded image: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'| sed  "s/Loaded image[^:]*: //g"
sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a

Additional Information/Context

No response

CDK CLI Version

2.176.0 (build 899965d)

Framework Version

No response

Node.js Version

v23.6.1

OS

Mac OS

Language

TypeScript

Language Version

typescript@^5.7.3

Other information

No response

@ajaest ajaest added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 13, 2025
@github-actions github-actions bot added the @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets label Feb 13, 2025
@ajaest ajaest changed the title @aws-cdk/aws-ecr-assets: (short issue description) @aws-cdk/aws-ecr-assets: TarballImageAsset is not properly docker-loading image with docker 27.4 Feb 13, 2025
ajaest added a commit to ajaest/aws-cdk that referenced this issue Feb 13, 2025
@pahud
Copy link
Contributor

pahud commented Feb 13, 2025

Yes, we should get it fixed as it's blocking the users. Thank you for your PR!

@pahud pahud added p1 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
2 participants