forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecr-assets): Support cache-from and cache-to flags (aws#24024)
This adds the `--cache-from` and `--cache-to` flag options. --- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md?rgh-link-date=2022-12-09T23%3A48%3A14Z) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/?rgh-link-date=2022-12-09T23%3A48%3A14Z#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md?rgh-link-date=2022-12-09T23%3A48%3A14Z)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
- Loading branch information
1 parent
5035698
commit bc86384
Showing
17 changed files
with
366 additions
and
5 deletions.
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.