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

[wip]diable digest resolution for manifest v2 schema 1 #4248

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,22 @@ func (engine *DockerTaskEngine) pullContainerManifest(
})
return dockerapi.DockerContainerMetadata{Error: manifestPullErr}
}
imageManifestMediatype := distInspect.Descriptor.MediaType
logger.Info("Fetched image manifest Mediatype for container from registry", logger.Fields{
field.TaskARN: task.Arn,
field.ContainerName: container.Name,
field.ImageMediatype: imageManifestMediatype,
field.Image: container.Image,
})
if strings.Contains(imageManifestMediatype, "application/vnd.docker.distribution.manifest.v1") {
logger.Info("skipping digest resolution for manifest v2 schema 1,", logger.Fields{
field.TaskARN: task.Arn,
field.ContainerName: container.Name,
field.ImageMediatype: imageManifestMediatype,
field.Image: container.Image,
})
return dockerapi.DockerContainerMetadata{}
}
imageManifestDigest = distInspect.Descriptor.Digest
logger.Info("Fetched image manifest digest for container from registry", logger.Fields{
field.TaskARN: task.Arn,
Expand Down
47 changes: 44 additions & 3 deletions agent/engine/docker_task_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,40 @@ func TestPullContainerManifest(t *testing.T) {
name: "digest is not resolved if already available in image reference",
image: "public.ecr.aws/library/alpine@" + testDigest.String(),
},
{
name: "schema1 image - skip digest resolution",
image: "myimage",
imagePullBehavior: config.ImagePullAlwaysBehavior,
setDockerClientExpectations: func(c *gomock.Controller, d *mock_dockerapi.MockDockerClient) {
versioned := mock_dockerapi.NewMockDockerClient(c)
versioned.EXPECT().
PullImageManifest(gomock.Any(), "myimage", nil).
Return(
registry.DistributionInspect{
Descriptor: ocispec.Descriptor{MediaType: "application/vnd.docker.distribution.manifest.v1+json"},
},
nil)
d.EXPECT().WithVersion(dockerclient.Version_1_35).Return(versioned, nil)
},
expectedResult: dockerapi.DockerContainerMetadata{},
},
{
name: "schema1 image - skip digest resolution",
image: "myimage",
imagePullBehavior: config.ImagePullAlwaysBehavior,
setDockerClientExpectations: func(c *gomock.Controller, d *mock_dockerapi.MockDockerClient) {
versioned := mock_dockerapi.NewMockDockerClient(c)
versioned.EXPECT().
PullImageManifest(gomock.Any(), "myimage", nil).
Return(
registry.DistributionInspect{
Descriptor: ocispec.Descriptor{MediaType: "application/vnd.docker.distribution.manifest.v1+json"},
},
nil)
d.EXPECT().WithVersion(dockerclient.Version_1_35).Return(versioned, nil)
},
expectedResult: dockerapi.DockerContainerMetadata{},
},
{
name: "image pull not required - image inspect fails",
image: "myimage",
Expand Down Expand Up @@ -4229,7 +4263,12 @@ func TestPullContainerManifest(t *testing.T) {
versioned.EXPECT().
PullImageManifest(gomock.Any(), "myimage", nil).
Return(
registry.DistributionInspect{Descriptor: ocispec.Descriptor{Digest: testDigest}},
registry.DistributionInspect{
Descriptor: ocispec.Descriptor{
MediaType: "application/vnd.docker.distribution.manifest.v2+json",
Digest: testDigest,
},
},
nil)
d.EXPECT().WithVersion(dockerclient.Version_1_35).Return(versioned, nil)
},
Expand Down Expand Up @@ -4261,8 +4300,10 @@ func TestPullContainerManifest(t *testing.T) {
PullImageManifest(gomock.Any(), "myimage", expectedRegistryAuthData).
Return(
registry.DistributionInspect{
Descriptor: ocispec.Descriptor{Digest: digest.Digest(testDigest.String())},
},
Descriptor: ocispec.Descriptor{
MediaType: "application/vnd.docker.distribution.manifest.v2+json",
Digest: testDigest,
}},
nil)
d.EXPECT().WithVersion(dockerclient.Version_1_35).Return(versioned, nil)
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 9 additions & 57 deletions build-infrastructure/codebuild-devbuild-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Resources:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled: true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -46,18 +47,12 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE
UbuntuArmProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled: true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -81,18 +76,12 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE
ArmProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled: true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -116,18 +105,12 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE
AmdProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled: true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -151,20 +134,14 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE

# Creates a CodeBuild project for Amazon Linux 2 ARM
Amzn2ArmProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled: true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -188,20 +165,14 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE

# Creates a CodeBuild project for Amazon Linux 2 AMD
Amzn2AmdProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled: true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -225,20 +196,14 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE

# Creates a CodeBuild project for Amazon Linux 2023 ARM
Amzn2023ArmProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled: true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -262,20 +227,14 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE

# Creates a CodeBuild project for Amazon Linux 2023 AMD
Amzn2023AmdProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
EncryptionDisabled : true
Location: !Ref BuildBucketName
NamespaceType: NONE
OverrideArtifactName: true
Expand All @@ -299,13 +258,6 @@ Resources:
Location: !Ref GithubFullRepoName
Type: GITHUB
TimeoutInMinutes: 60
Triggers:
BuildType: BUILD
# Config list of developers allowlisted to create builds when creating PRs to GithubBranchName
# This allow list can be modified using aws-cli or aws-sdk
# CodeBuild also supports pattern matches using regex, but this is not useful for listing different Github IDs
# so they have to be listed separately
Webhook: true
Visibility: PRIVATE

# Defines the service roles for the CodeBuild projects
Expand Down Expand Up @@ -652,4 +604,4 @@ Resources:
- 's3:GetBucketAcl'
- 's3:GetBucketLocation'
PolicyName: !Sub '${AWS::StackName}-ServicePolicyAmzn2023Amd'
RoleName: !Sub '${AWS::StackName}-ServiceRoleAmzn2023Amd'
RoleName: !Sub '${AWS::StackName}-ServiceRoleAmzn2023Amd'
1 change: 1 addition & 0 deletions ecs-agent/logger/field/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
ImageLastUsedAt = "imageLastUsedAt"
ImagePullSucceeded = "imagePullSucceeded"
ImageDigest = "imageDigest"
ImageMediatype = "imageMediatype"
ContainerName = "containerName"
ContainerImage = "containerImage"
ContainerExitCode = "containerExitCode"
Expand Down
Loading