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
feat(ecr-assets): Support cache-from and cache-to flags #24024
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3011b72
feat(ecr-assets): Support cache-from and cache-to flags
RichiCoder1 7eab644
chore: fixup cloud assembly test
RichiCoder1 4886756
Merge branch 'main' into feat/ecr-assets-cache-flags
RichiCoder1 738553c
fix: strongishly type docker cache options
RichiCoder1 060461c
fix: add missing unsaved changes
RichiCoder1 0bda8b1
fix: integ tests
RichiCoder1 018424b
Merge branch 'main' into feat/ecr-assets-cache-flags
RichiCoder1 ee8d345
Merge branch 'main' into feat/ecr-assets-cache-flags
RichiCoder1 fe20218
Merge branch 'main' into feat/ecr-assets-cache-flags
RichiCoder1 0e6f0ee
Merge branch 'main' into feat/ecr-assets-cache-flags
RichiCoder1 c2ff00b
Merge branch 'main' into feat/ecr-assets-cache-flags
RichiCoder1 bc87be0
chore: add basic unit tests for cache options
RichiCoder1 1e786ee
Merge branch 'main' into feat/ecr-assets-cache-flags
RichiCoder1 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
88 changes: 88 additions & 0 deletions
88
packages/@aws-cdk/aws-ecr-assets/test/build-image-cache.test.ts
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,88 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { AssetManifest } from '@aws-cdk/cloud-assembly-schema'; | ||
import { App, Stack } from '@aws-cdk/core'; | ||
import { AssetManifestArtifact, CloudArtifact, CloudAssembly } from '@aws-cdk/cx-api'; | ||
import { DockerImageAsset } from '../lib'; | ||
|
||
describe('build cache', () => { | ||
test('manifest contains cache from options ', () => { | ||
// GIVEN | ||
const app = new App(); | ||
const stack = new Stack(app); | ||
const asset = new DockerImageAsset(stack, 'DockerImage6', { | ||
directory: path.join(__dirname, 'demo-image'), | ||
cacheFrom: [{ type: 'registry', params: { image: 'foo' } }], | ||
}); | ||
|
||
// WHEN | ||
const asm = app.synth(); | ||
|
||
// THEN | ||
const manifestArtifact = getAssetManifest(asm); | ||
const manifest = readAssetManifest(manifestArtifact); | ||
|
||
expect(Object.keys(manifest.dockerImages ?? {}).length).toBe(1); | ||
expect(manifest.dockerImages?.[asset.assetHash]?.source.cacheFrom?.length).toBe(1); | ||
expect(manifest.dockerImages?.[asset.assetHash]?.source.cacheFrom?.[0]).toStrictEqual({ | ||
type: 'registry', | ||
params: { image: 'foo' }, | ||
}); | ||
}); | ||
test('manifest contains cache to options ', () => { | ||
// GIVEN | ||
const app = new App(); | ||
const stack = new Stack(app); | ||
const asset = new DockerImageAsset(stack, 'DockerImage6', { | ||
directory: path.join(__dirname, 'demo-image'), | ||
cacheTo: { type: 'inline' }, | ||
}); | ||
|
||
// WHEN | ||
const asm = app.synth(); | ||
|
||
// THEN | ||
const manifestArtifact = getAssetManifest(asm); | ||
const manifest = readAssetManifest(manifestArtifact); | ||
|
||
expect(Object.keys(manifest.dockerImages ?? {}).length).toBe(1); | ||
expect(manifest.dockerImages?.[asset.assetHash]?.source.cacheTo).toStrictEqual({ | ||
type: 'inline', | ||
}); | ||
}); | ||
|
||
test('manifest does not contain options when not specified', () => { | ||
// GIVEN | ||
const app = new App(); | ||
const stack = new Stack(app); | ||
const asset = new DockerImageAsset(stack, 'DockerImage6', { | ||
directory: path.join(__dirname, 'demo-image'), | ||
}); | ||
|
||
// WHEN | ||
const asm = app.synth(); | ||
|
||
// THEN | ||
const manifestArtifact = getAssetManifest(asm); | ||
const manifest = readAssetManifest(manifestArtifact); | ||
expect(Object.keys(manifest.dockerImages ?? {}).length).toBe(1); | ||
expect(manifest.dockerImages?.[asset.assetHash]?.source.cacheFrom).toBeUndefined(); | ||
expect(manifest.dockerImages?.[asset.assetHash]?.source.cacheTo).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
function isAssetManifest(x: CloudArtifact): x is AssetManifestArtifact { | ||
return x instanceof AssetManifestArtifact; | ||
} | ||
|
||
function getAssetManifest(asm: CloudAssembly): AssetManifestArtifact { | ||
const manifestArtifact = asm.artifacts.filter(isAssetManifest)[0]; | ||
if (!manifestArtifact) { | ||
throw new Error('no asset manifest in assembly'); | ||
} | ||
return manifestArtifact; | ||
} | ||
|
||
function readAssetManifest(manifestArtifact: AssetManifestArtifact): AssetManifest { | ||
return JSON.parse(fs.readFileSync(manifestArtifact.file, { encoding: 'utf-8' })); | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MrArnoldPalmer followed the pattern in tar assets, lmk no if test naming and tests lgty!