Skip to content

Commit

Permalink
chore: update tooling to support alternative docker commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Jan 26, 2023
1 parent cb54c28 commit 16e6068
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ cp ${script_dir}/test_index.py $PWD
cp ${script_dir}/Dockerfile $PWD

NOTIFICATIONS_RESOURCE_TEST_NO_DOCKER=${NOTIFICATIONS_RESOURCE_TEST_NO_DOCKER:-""}
DOCKER_CMD=${CDK_DOCKER:-docker}

if [ -z ${NOTIFICATIONS_RESOURCE_TEST_NO_DOCKER} ]; then
# this will run our tests inside the right environment
docker build .
$DOCKER_CMD build .
else
python test_index.py
fi
30 changes: 16 additions & 14 deletions packages/@aws-cdk/core/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as path from 'path';
import * as sinon from 'sinon';
import { DockerImage, FileSystem } from '../lib';

const dockerCmd = process.env.CDK_DOCKER ?? 'docker';

describe('bundling', () => {
afterEach(() => {
sinon.restore();
Expand Down Expand Up @@ -33,7 +35,7 @@ describe('bundling', () => {
user: 'user:group',
});

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

expect(spawnSyncStub.firstCall.calledWith('docker', [
expect(spawnSyncStub.firstCall.calledWith(dockerCmd, [
'build', '-t', tag,
'--build-arg', 'TEST_ARG=cdk-test',
'docker-path',
])).toEqual(true);

expect(spawnSyncStub.secondCall.calledWith('docker', [
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
'run', '--rm',
tag,
])).toEqual(true);
Expand Down Expand Up @@ -110,13 +112,13 @@ describe('bundling', () => {
})).digest('hex');
const tag = `cdk-${tagHash}`;

expect(spawnSyncStub.firstCall.calledWith('docker', [
expect(spawnSyncStub.firstCall.calledWith(dockerCmd, [
'build', '-t', tag,
'--platform', platform,
'docker-path',
])).toEqual(true);

expect(spawnSyncStub.secondCall.calledWith('docker', [
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
'run', '--rm',
tag,
])).toEqual(true);
Expand Down Expand Up @@ -146,13 +148,13 @@ describe('bundling', () => {
})).digest('hex');
const tag = `cdk-${tagHash}`;

expect(spawnSyncStub.firstCall.calledWith('docker', [
expect(spawnSyncStub.firstCall.calledWith(dockerCmd, [
'build', '-t', tag,
'--target', targetStage,
'docker-path',
])).toEqual(true);

expect(spawnSyncStub.secondCall.calledWith('docker', [
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
'run', '--rm',
tag,
])).toEqual(true);
Expand Down Expand Up @@ -281,7 +283,7 @@ describe('bundling', () => {
user: 'user:group',
});

expect(spawnSyncStub.calledWith('docker', [
expect(spawnSyncStub.calledWith(dockerCmd, [
'run', '--rm',
'-u', 'user:group',
'-v', '/host-path:/container-path:delegated',
Expand Down Expand Up @@ -392,7 +394,7 @@ describe('bundling', () => {
user: 'user:group',
});

expect(spawnSyncStub.calledWith('docker', [
expect(spawnSyncStub.calledWith(dockerCmd, [
'run', '--rm',
'--security-opt', 'no-new-privileges',
'-u', 'user:group',
Expand Down Expand Up @@ -427,7 +429,7 @@ describe('bundling', () => {
user: 'user:group',
});

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

expect(spawnSyncStub.calledWith('docker', [
expect(spawnSyncStub.calledWith(dockerCmd, [
'run', '--rm',
'-u', 'user:group',
'--volumes-from', 'foo',
Expand Down Expand Up @@ -507,7 +509,7 @@ describe('bundling', () => {
});

// THEN
expect(spawnSyncStub.secondCall.calledWith('docker', [
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
'run', '--rm',
'-u', 'user:group',
'-v', '/host-path:/container-path:z,delegated',
Expand Down Expand Up @@ -548,7 +550,7 @@ describe('bundling', () => {
});

// THEN
expect(spawnSyncStub.secondCall.calledWith('docker', [
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
'run', '--rm',
'-u', 'user:group',
'-v', '/host-path:/container-path:delegated',
Expand Down Expand Up @@ -589,7 +591,7 @@ describe('bundling', () => {
});

// THEN
expect(spawnSyncStub.secondCall.calledWith('docker', [
expect(spawnSyncStub.secondCall.calledWith(dockerCmd, [
'run', '--rm',
'-u', 'user:group',
'-v', '/host-path:/container-path:delegated',
Expand Down
24 changes: 13 additions & 11 deletions packages/@aws-cdk/core/test/private/asset-staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as sinon from 'sinon';
import { AssetStaging, DockerImage } from '../../lib';
import { AssetBundlingBindMount, AssetBundlingVolumeCopy } from '../../lib/private/asset-staging';

const dockerCmd = process.env.CDK_DOCKER ?? 'docker';

describe('bundling', () => {
afterEach(() => {
sinon.restore();
Expand All @@ -29,25 +31,25 @@ describe('bundling', () => {
helper.run();

// volume Creation
expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'volume', 'create', sinon.match(/assetInput.*/g),
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'volume', 'create', sinon.match(/assetOutput.*/g),
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

// volume removal
expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'volume', 'rm', sinon.match(/assetInput.*/g),
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'volume', 'rm', sinon.match(/assetOutput.*/g),
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

// prepare copy container
expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'run',
'--name', sinon.match(/copyContainer.*/g),
'-v', sinon.match(/assetInput.*/g),
Expand All @@ -59,22 +61,22 @@ describe('bundling', () => {
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

// delete copy container
expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'rm', sinon.match(/copyContainer.*/g),
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

// copy files to copy container
expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'cp', `${options.sourcePath}/.`, `${helper.copyContainerName}:${AssetStaging.BUNDLING_INPUT_DIR}`,
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

// copy files from copy container to host
expect(spawnSyncStub.calledWith('docker', sinon.match([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match([
'cp', `${helper.copyContainerName}:${AssetStaging.BUNDLING_OUTPUT_DIR}/.`, options.bundleDir,
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);

// actual docker run
expect(spawnSyncStub.calledWith('docker', sinon.match.array.contains([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match.array.contains([
'run', '--rm',
'--volumes-from', helper.copyContainerName,
'alpine',
Expand Down Expand Up @@ -103,10 +105,10 @@ describe('bundling', () => {
helper.run();

// actual docker run with bind mount is called
expect(spawnSyncStub.calledWith('docker', sinon.match.array.contains([
expect(spawnSyncStub.calledWith(dockerCmd, sinon.match.array.contains([
'run', '--rm',
'-v',
'alpine',
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);
});
});
});
8 changes: 4 additions & 4 deletions scripts/check-build-prerequisites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ else
fi

# [Docker >= 19.03]
app="docker"
app=${CDK_DOCKER:-docker}
app_min="19.03.0"
check_which $app $app_min

# Make sure docker is running
echo -e "Checking if docker is running... \c"
docker_running=$(docker ps)
echo -e "Checking if $app is running... \c"
docker_running=$($app ps)
if [ $? -eq 0 ]
then
echo "Ok"
else
die "Docker is not running"
die "$app is not running"
fi

# [.NET == 3.1.x, == 5.x]
Expand Down

0 comments on commit 16e6068

Please sign in to comment.