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

feat(core): improved docker bundling performance on mac os #8766

Merged
merged 13 commits into from Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 38 additions & 7 deletions packages/@aws-cdk/core/lib/bundling.ts
@@ -1,4 +1,4 @@
import { spawnSync } from 'child_process';
import {spawnSync} from 'child_process';
Dzhuneyt marked this conversation as resolved.
Show resolved Hide resolved

/**
* Bundling options
Expand Down Expand Up @@ -95,7 +95,8 @@ export class BundlingDockerImage {
}

/** @param image The Docker image */
private constructor(public readonly image: string) {}
private constructor(public readonly image: string) {
}

/**
* Runs a Docker image
Expand All @@ -110,13 +111,13 @@ export class BundlingDockerImage {
const dockerArgs: string[] = [
'run', '--rm',
...options.user
? ['-u', options.user]
: [],
...flatten(volumes.map(v => ['-v', `${v.hostPath}:${v.containerPath}`])),
? ['-u', options.user]
: [],
...flatten(volumes.map(v => ['-v', `${v.hostPath}:${v.containerPath}:${v.consistency ?? DockerConsistency.DEFAULT}`])),
...flatten(Object.entries(environment).map(([k, v]) => ['--env', `${k}=${v}`])),
...options.workingDirectory
? ['-w', options.workingDirectory]
: [],
? ['-w', options.workingDirectory]
: [],
this.image,
...command,
];
Expand All @@ -138,6 +139,36 @@ export interface DockerVolume {
* The path where the file or directory is mounted in the container
*/
readonly containerPath: string;

/**
* Mount consistency. Only applicable for macOS
*
* @default delegated
Dzhuneyt marked this conversation as resolved.
Show resolved Hide resolved
* @see https://docs.docker.com/storage/bind-mounts/#configure-mount-consistency-for-macos
*/
readonly consistency?: DockerConsistency;
}

/**
* Supported Docker volume consistency types. Only valid on macOS due to the way file storage works on Mac
*/
export enum DockerConsistency {
/**
* @see DockerConsistency.DELEGATED
*/
DEFAULT = 'consistent',
Dzhuneyt marked this conversation as resolved.
Show resolved Hide resolved
/**
* Read/write operations inside the Docker container are applied immediately on the mounted host machine volumes
*/
CONSISTENT = 'consistent',
/**
* Read/write operations on mounted Docker volumes are first written inside the container and then synchronized to the host machine
*/
DELEGATED = 'delegated',
/**
* Read/write operations on mounted Docker volumes are first applied on the host machine and then synchronized to the container
*/
CACHED = 'cached',
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/core/test/test.bundling.ts
Expand Up @@ -34,7 +34,7 @@ export = {
test.ok(spawnSyncStub.calledWith('docker', [
'run', '--rm',
'-u', 'user:group',
'-v', '/host-path:/container-path',
'-v', '/host-path:/container-path:delegated',
'--env', 'VAR1=value1',
'--env', 'VAR2=value2',
'-w', '/working-directory',
Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/core/test/test.staging.ts
Expand Up @@ -122,7 +122,7 @@ export = {
const assembly = app.synth();
test.deepEqual(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS`,
`run --rm ${USER_ARG} -v /input:/asset-input:delegated -v /output:/asset-output:delegated -w /asset-input alpine DOCKER_STUB_SUCCESS`,
eladb marked this conversation as resolved.
Show resolved Hide resolved
);
test.deepEqual(fs.readdirSync(assembly.directory), [
'asset.2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00',
Expand Down Expand Up @@ -158,7 +158,7 @@ export = {

test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS_NO_OUTPUT`,
`run --rm ${USER_ARG} -v /input:/asset-input:delegated -v /output:/asset-output:delegated -w /asset-input alpine DOCKER_STUB_SUCCESS_NO_OUTPUT`,
);
test.done();
},
Expand All @@ -182,7 +182,7 @@ export = {
// THEN
test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS`,
`run --rm ${USER_ARG} -v /input:/asset-input:delegated -v /output:/asset-output:delegated -w /asset-input alpine DOCKER_STUB_SUCCESS`,
);
test.equal(asset.assetHash, '33cbf2cae5432438e0f046bc45ba8c3cef7b6afcf47b59d1c183775c1918fb1f');

Expand Down Expand Up @@ -226,7 +226,7 @@ export = {
}), /Cannot specify `bundle` for `assetHashType`/);
test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS`,
`run --rm ${USER_ARG} -v /input:/asset-input:delegated -v /output:/asset-output:delegated -w /asset-input alpine DOCKER_STUB_SUCCESS`,
);

test.done();
Expand Down Expand Up @@ -280,7 +280,7 @@ export = {
}), /Failed to run bundling Docker image for asset stack\/Asset/);
test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input this-is-an-invalid-docker-image DOCKER_STUB_FAIL`,
`run --rm ${USER_ARG} -v /input:/asset-input:delegated -v /output:/asset-output:delegated -w /asset-input this-is-an-invalid-docker-image DOCKER_STUB_FAIL`,
);

test.done();
Expand Down