Skip to content

Commit

Permalink
fix(ecr-assets): exclude option (#4354)
Browse files Browse the repository at this point in the history
* fix(@aws-cdk/aws-ecr-assets): `exclude` option (#4353)

fixed #4353

* .dockerignore itself should be included
* fixed test path with image.sourceHash

* modified excluded path to be tested
  • Loading branch information
kuwabarahiroshi authored and mergify[bot] committed Oct 3, 2019
1 parent f9898ec commit f96b2fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class DockerImageAsset extends Construct implements assets.IAsset {
throw new Error(`No 'Dockerfile' found in ${dir}`);
}

let exclude: string[] = ['.dockerignore'];
let exclude: string[] = props.exclude || [];

const ignore = path.join(dir, '.dockerignore');

Expand Down
Empty file.
39 changes: 32 additions & 7 deletions packages/@aws-cdk/aws-ecr-assets/test/test.image-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,30 +197,55 @@ export = {
const app = new App();
const stack = new Stack(app, 'stack');

new DockerImageAsset(stack, 'MyAsset', {
const image = new DockerImageAsset(stack, 'MyAsset', {
directory: path.join(__dirname, 'demo-image')
});

const session = app.synth();

test.ok(fs.existsSync(path.join(session.directory, 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/Dockerfile')));
test.ok(fs.existsSync(path.join(session.directory, 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/index.py')));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'Dockerfile')));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'index.py')));
test.done();
},

'docker directory is staged without files specified in .dockerignore'(test: Test) {
const app = new App();
const stack = new Stack(app, 'stack');

new DockerImageAsset(stack, 'MyAsset', {
const image = new DockerImageAsset(stack, 'MyAsset', {
directory: path.join(__dirname, 'dockerignore-image')
});

const session = app.synth();

test.ok(fs.existsSync(path.join(session.directory, `asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/Dockerfile`)));
test.ok(fs.existsSync(path.join(session.directory, 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/index.py')));
test.ok(!fs.existsSync(path.join(session.directory, 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/foobar.txt')));
// .dockerignore itself should be included in output to be processed during docker build
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, '.dockerignore')));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, `Dockerfile`)));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'index.py')));
test.ok(!fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'foobar.txt')));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'subdirectory')));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'subdirectory', 'baz.txt')));

test.done();
},

'docker directory is staged without files specified in exclude option'(test: Test) {
const app = new App();
const stack = new Stack(app, 'stack');

const image = new DockerImageAsset(stack, 'MyAsset', {
directory: path.join(__dirname, 'dockerignore-image'),
exclude: ['subdirectory']
});

const session = app.synth();

test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, '.dockerignore')));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, `Dockerfile`)));
test.ok(fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'index.py')));
test.ok(!fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'foobar.txt')));
test.ok(!fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'subdirectory')));
test.ok(!fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'subdirectory', 'baz.txt')));

test.done();
},
Expand Down

0 comments on commit f96b2fb

Please sign in to comment.