Skip to content

Commit

Permalink
fix(ecr): apply user excludes after .dockerignore
Browse files Browse the repository at this point in the history
  • Loading branch information
blaenk committed Oct 7, 2020
1 parent 55cf1cc commit 475604b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts
Expand Up @@ -102,7 +102,7 @@ export class DockerImageAsset extends CoreConstruct implements assets.IAsset {
const ignore = path.join(dir, '.dockerignore');

if (fs.existsSync(ignore)) {
exclude = [...exclude, ...fs.readFileSync(ignore).toString().split('\n').filter(e => !!e)];
exclude = [...fs.readFileSync(ignore).toString().split('\n').filter(e => !!e), ...exclude];
}

// make sure the docker file and the dockerignore file end up in the staging area
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-ecr-assets/test/test.image-asset.ts
Expand Up @@ -235,6 +235,7 @@ export = {

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

const session = app.synth();
Expand All @@ -244,6 +245,8 @@ export = {
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.ok(!fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'node_modules')));
test.ok(!fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'node_modules', 'one')));
test.ok(!fs.existsSync(path.join(session.directory, `asset.${image.sourceHash}`, 'node_modules', 'some_dep')));
Expand Down
Expand Up @@ -3,4 +3,4 @@
!.dockerignore
!foobar.txt
!index.py
!subdirectory/
!subdirectory

0 comments on commit 475604b

Please sign in to comment.