Skip to content

Commit a6fa5b8

Browse files
authored
chore: support contributing to the AWS CDK using alternative container clients (#23855)
The AWS CDK uses `docker` for a feature subset related to building assets. For users, we already support the `CDK_DOCKER` env variable to change the container client at runtime. However contributing to the AWS CDK currently still requires a contributor to have `docker` installed. This PR extends the support for the `CDK_DOCKER` env variable to contributor tooling. For example one can now run: ```console CDK_DOCKER=finch ./scripts/foreach.sh "yarn build" CDK_DOCKER=finch ./scripts/foreach.sh "yarn test" ``` When using `finch`, the following packages do still fail tests, due to known feature gaps: ```csv @aws-cdk/aws-ec2 @aws-cdk/aws-lambda @aws-cdk/aws-lambda-go @aws-cdk/aws-lambda-python @aws-cdk/aws-lambda-nodejs @aws-cdk/aws-s3-deployment ``` --- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### 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/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] 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*
1 parent d9ce580 commit a6fa5b8

File tree

7 files changed

+74
-29
lines changed

7 files changed

+74
-29
lines changed

packages/@aws-cdk/aws-s3/test/notifications-resource-handler/test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ cp ${script_dir}/test_index.py $PWD
1717
cp ${script_dir}/Dockerfile $PWD
1818

1919
NOTIFICATIONS_RESOURCE_TEST_NO_DOCKER=${NOTIFICATIONS_RESOURCE_TEST_NO_DOCKER:-""}
20+
DOCKER_CMD=${CDK_DOCKER:-docker}
2021

2122
if [ -z ${NOTIFICATIONS_RESOURCE_TEST_NO_DOCKER} ]; then
2223
# this will run our tests inside the right environment
23-
docker build .
24+
$DOCKER_CMD build .
2425
else
2526
python test_index.py
2627
fi

packages/@aws-cdk/core/test/bundling.test.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as path from 'path';
44
import * as sinon from 'sinon';
55
import { DockerImage, FileSystem } from '../lib';
66

7+
const dockerCmd = process.env.CDK_DOCKER ?? 'docker';
8+
79
describe('bundling', () => {
810
afterEach(() => {
911
sinon.restore();
@@ -33,7 +35,7 @@ describe('bundling', () => {
3335
user: 'user:group',
3436
});
3537

36-
expect(spawnSyncStub.calledWith('docker', [
38+
expect(spawnSyncStub.calledWith(dockerCmd, [
3739
'run', '--rm',
3840
'-u', 'user:group',
3941
'-v', '/host-path:/container-path:delegated',
@@ -74,13 +76,13 @@ describe('bundling', () => {
7476
})).digest('hex');
7577
const tag = `cdk-${tagHash}`;
7678

77-
expect(spawnSyncStub.firstCall.calledWith('docker', [
79+
expect(spawnSyncStub.firstCall.calledWith(dockerCmd, [
7880
'build', '-t', tag,
7981
'--build-arg', 'TEST_ARG=cdk-test',
8082
'docker-path',
8183
])).toEqual(true);
8284

83-
expect(spawnSyncStub.secondCall.calledWith('docker', [
85+
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
8486
'run', '--rm',
8587
tag,
8688
])).toEqual(true);
@@ -110,13 +112,13 @@ describe('bundling', () => {
110112
})).digest('hex');
111113
const tag = `cdk-${tagHash}`;
112114

113-
expect(spawnSyncStub.firstCall.calledWith('docker', [
115+
expect(spawnSyncStub.firstCall.calledWith(dockerCmd, [
114116
'build', '-t', tag,
115117
'--platform', platform,
116118
'docker-path',
117119
])).toEqual(true);
118120

119-
expect(spawnSyncStub.secondCall.calledWith('docker', [
121+
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
120122
'run', '--rm',
121123
tag,
122124
])).toEqual(true);
@@ -146,13 +148,13 @@ describe('bundling', () => {
146148
})).digest('hex');
147149
const tag = `cdk-${tagHash}`;
148150

149-
expect(spawnSyncStub.firstCall.calledWith('docker', [
151+
expect(spawnSyncStub.firstCall.calledWith(dockerCmd, [
150152
'build', '-t', tag,
151153
'--target', targetStage,
152154
'docker-path',
153155
])).toEqual(true);
154156

155-
expect(spawnSyncStub.secondCall.calledWith('docker', [
157+
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
156158
'run', '--rm',
157159
tag,
158160
])).toEqual(true);
@@ -281,7 +283,7 @@ describe('bundling', () => {
281283
user: 'user:group',
282284
});
283285

284-
expect(spawnSyncStub.calledWith('docker', [
286+
expect(spawnSyncStub.calledWith(dockerCmd, [
285287
'run', '--rm',
286288
'-u', 'user:group',
287289
'-v', '/host-path:/container-path:delegated',
@@ -392,7 +394,7 @@ describe('bundling', () => {
392394
user: 'user:group',
393395
});
394396

395-
expect(spawnSyncStub.calledWith('docker', [
397+
expect(spawnSyncStub.calledWith(dockerCmd, [
396398
'run', '--rm',
397399
'--security-opt', 'no-new-privileges',
398400
'-u', 'user:group',
@@ -427,7 +429,7 @@ describe('bundling', () => {
427429
user: 'user:group',
428430
});
429431

430-
expect(spawnSyncStub.calledWith('docker', [
432+
expect(spawnSyncStub.calledWith(dockerCmd, [
431433
'run', '--rm',
432434
'--network', 'host',
433435
'-u', 'user:group',
@@ -464,7 +466,7 @@ describe('bundling', () => {
464466
// nevertheless what we want to check here is that the command was built correctly and triggered
465467
};
466468

467-
expect(spawnSyncStub.calledWith('docker', [
469+
expect(spawnSyncStub.calledWith(dockerCmd, [
468470
'run', '--rm',
469471
'-u', 'user:group',
470472
'--volumes-from', 'foo',
@@ -507,7 +509,7 @@ describe('bundling', () => {
507509
});
508510

509511
// THEN
510-
expect(spawnSyncStub.secondCall.calledWith('docker', [
512+
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
511513
'run', '--rm',
512514
'-u', 'user:group',
513515
'-v', '/host-path:/container-path:z,delegated',
@@ -548,7 +550,7 @@ describe('bundling', () => {
548550
});
549551

550552
// THEN
551-
expect(spawnSyncStub.secondCall.calledWith('docker', [
553+
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
552554
'run', '--rm',
553555
'-u', 'user:group',
554556
'-v', '/host-path:/container-path:delegated',
@@ -589,7 +591,7 @@ describe('bundling', () => {
589591
});
590592

591593
// THEN
592-
expect(spawnSyncStub.secondCall.calledWith('docker', [
594+
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
593595
'run', '--rm',
594596
'-u', 'user:group',
595597
'-v', '/host-path:/container-path:delegated',

packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface IntegRunnerOptions {
3333
*
3434
* @default - no additional environment variables
3535
*/
36-
readonly env?: { [name: string]: string },
36+
readonly env?: { [name: string]: string | undefined },
3737

3838
/**
3939
* tmp cdk.out directory

packages/@aws-cdk/integ-runner/lib/workers/extract/extract_worker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function integTestWorker(request: IntegTestBatchRequest): IntegTestWorker
2626
profile: request.profile,
2727
env: {
2828
AWS_REGION: request.region,
29+
CDK_DOCKER: process.env.CDK_DOCKER,
2930
},
3031
showOutput: verbosity >= 2,
3132
}, testInfo.destructiveChanges);

packages/cdk-cli-wrapper/lib/cdk-wrapper.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ export interface SynthFastOptions {
6969
readonly env?: { [name: string]: string }
7070
}
7171

72+
/**
73+
* Additional environment variables to set
74+
* in the execution environment that will be running
75+
* the cdk commands
76+
*/
77+
export interface Environment {
78+
[key: string]: string | undefined
79+
}
80+
7281
/**
7382
* AWS CDK client that provides an API to programatically execute the CDK CLI
7483
* by wrapping calls to exec the CLI
@@ -86,7 +95,7 @@ export interface CdkCliWrapperOptions {
8695
*
8796
* @default - no additional env vars
8897
*/
89-
readonly env?: { [key: string]: string },
98+
readonly env?: Environment,
9099

91100
/**
92101
* The path to the cdk executable
@@ -109,7 +118,7 @@ export interface CdkCliWrapperOptions {
109118
*/
110119
export class CdkCliWrapper implements ICdk {
111120
private readonly directory: string;
112-
private readonly env?: { [key: string]: string };
121+
private readonly env?: Environment;
113122
private readonly cdk: string;
114123
private readonly showOutput: boolean;
115124

scripts/check-build-prerequisites.sh

+42-10
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,51 @@ else
7474
wrong_version
7575
fi
7676

77+
# Container Client
78+
container_client=${CDK_DOCKER:-docker}
79+
docker_min="19.03.0"
80+
finch_min="0.3.0"
81+
7782
# [Docker >= 19.03]
78-
app="docker"
79-
app_min="19.03.0"
80-
check_which $app $app_min
83+
if [ "$container_client" == "docker" ]; then
84+
check_which $container_client $docker_min
8185

82-
# Make sure docker is running
83-
echo -e "Checking if docker is running... \c"
84-
docker_running=$(docker ps)
85-
if [ $? -eq 0 ]
86-
then
87-
echo "Ok"
86+
# Make sure docker is running
87+
echo -e "Checking if Docker is running... \c"
88+
docker_running=$(docker ps)
89+
if [ $? -eq 0 ]
90+
then
91+
echo "Ok"
92+
else
93+
die "Docker is not running"
94+
fi
95+
96+
# [finch >= 0.3.0]
97+
elif [ "$container_client" == "finch" ]; then
98+
check_which $container_client $finch_min
99+
100+
# Make sure docker is running
101+
echo -e "Checking if finch is running... \c"
102+
finch_running=$($container_client ps)
103+
if [ $? -eq 0 ]
104+
then
105+
echo "Ok"
106+
else
107+
die "Finch is not running"
108+
fi
88109
else
89-
die "Docker is not running"
110+
echo "⚠️ Dependency warning: Unknown container client detected. You have set \"CDK_DOCKER=$CDK_DOCKER\"."
111+
check_which $container_client "(unknown version requirement)"
112+
echo "While any docker compatible client can be used as a drop-in replacement, support for \"$CDK_DOCKER\" is unknown."
113+
echo "Proceed with caution."
114+
echo -e "Checking if $container_client is running... \c"
115+
client_running=$($container_client ps)
116+
if [ $? -eq 0 ]
117+
then
118+
echo "Ok"
119+
else
120+
die "$CDK_DOCKER is not running"
121+
fi
90122
fi
91123

92124
# [.NET == 3.1.x, == 5.x]

tools/@aws-cdk/node-bundle/src/api/bundle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export interface BundleProps {
7979
*
8080
* @default "inline"
8181
*/
82-
readonly sourcemap?: 'linked' | 'inline' | 'external' | 'both';
82+
readonly sourcemap?: 'linked' | 'inline' | 'external' | 'both';
8383

8484
/**
8585
* Minifies the bundled code.

0 commit comments

Comments
 (0)