-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support to explicitly specify a CPU architecture for the to…
…-be-copied image instead of relying on auto-detection (#961) ### What's the problem? It's observed that when copying a multi-arch source image from location A to B in ECR, we always end up with `amd64` in the destination image at location B. The hypothesis is that the underlying lambda function used to auto-detect the architecture is backed up by Dockerfile with [a hard-coded runtime.GOARCH](https://github.com/cdklabs/cdk-ecr-deployment/blob/dcd74cdfc394d6a43a5517cb5cce1843e1fe3111/lambda/Dockerfile#L11). ### Proposed Solution Instead of solely relying on an auto-detection mechanism, this PR is meant to add a feature to allow users to explicitly specify a CPU architecture for the to-be-copied image, by triggering the underlying logic [here](https://github.com/containers/image/blob/5263462aa97ae23d3a620b4dcdbbc557665a42c8/internal/pkg/platform/platform_matcher.go#L164). This will unblock the usage of Graviton instances for [Amazon SageMaker](https://aws.amazon.com/sagemaker/) and other computing platforms. As a side note, I've run `npm run release` on my dev box to refresh `API.md` --------- Co-authored-by: Bo Xiong <[email protected]> Co-authored-by: Rico Huijbers <[email protected]>
- Loading branch information
1 parent
093ad7b
commit fbab401
Showing
9 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Stack, App, aws_ecr as ecr, assertions } from 'aws-cdk-lib'; | ||
import { DockerImageName, ECRDeployment } from '../src'; | ||
|
||
// Yes, it's a lie. It's also the truth. | ||
const CUSTOM_RESOURCE_TYPE = 'Custom::CDKBucketDeployment'; | ||
|
||
let app: App; | ||
let stack: Stack; | ||
|
||
const src = new DockerImageName('javacs3/javacs3:latest', 'dockerhub'); | ||
let dest: DockerImageName; | ||
beforeEach(() => { | ||
app = new App(); | ||
stack = new Stack(app, 'Stack'); | ||
|
||
const repo = new ecr.Repository(stack, 'Repo', { | ||
repositoryName: 'repo', | ||
}); | ||
dest = new DockerImageName(`${repo.repositoryUri}:copied`); | ||
|
||
// Otherwise we do a Docker build :x | ||
process.env.FORCE_PREBUILT_LAMBDA = 'true'; | ||
}); | ||
|
||
test('ImageArch is missing from custom resource if argument not specified', () => { | ||
// WHEN | ||
new ECRDeployment(stack, 'ECR', { | ||
src, | ||
dest, | ||
}); | ||
|
||
// THEN | ||
const template = assertions.Template.fromStack(stack); | ||
template.hasResourceProperties(CUSTOM_RESOURCE_TYPE, { | ||
ImageArch: assertions.Match.absent(), | ||
}); | ||
}); | ||
|
||
test('ImageArch is in custom resource properties if specified', () => { | ||
// WHEN | ||
new ECRDeployment(stack, 'ECR', { | ||
src, | ||
dest, | ||
imageArch: ['banana'], | ||
}); | ||
|
||
// THEN | ||
const template = assertions.Template.fromStack(stack); | ||
template.hasResourceProperties(CUSTOM_RESOURCE_TYPE, { | ||
ImageArch: 'banana', | ||
}); | ||
}); | ||
|
||
test('Cannot specify more or fewer than 1 elements in imageArch', () => { | ||
// WHEN | ||
expect(() => new ECRDeployment(stack, 'ECR', { | ||
src, | ||
dest, | ||
imageArch: ['banana', 'pear'], | ||
})).toThrow(/imageArch must contain exactly 1 element/); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters