Skip to content

Commit

Permalink
fix(ecr-mirror): allow using the same directory twice as MirrorSource (
Browse files Browse the repository at this point in the history
…#1045)

As long as the build arguments are different.


-----

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
rix0rrr authored Oct 14, 2021
1 parent 5de32d8 commit 9031548
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/__tests__/registry-sync/mirror-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,24 @@ describe('RegistryImageSource', () => {
const expected = 'docker build --pull -t myregistry/myrepository:latest --build-arg arg1=val1 --build-arg arg2=val2 myrepository';
expect(result.commands[2]).toEqual(expected);
});

test('can bind the same directory twice if they have different build args', () => {
// GIVEN
const stack = new Stack();
const ecrRegistry = 'myregistry';
const source1 = MirrorSource.fromDir(path.join(__dirname, 'docker-asset'), 'myrepository');
const source2 = MirrorSource.fromDir(path.join(__dirname, 'docker-asset'), 'myrepository', {
buildArgs: {
arg1: 'val1',
arg2: 'val2',
},
});

// WHEN
source1.bind({ scope: stack, ecrRegistry });
source2.bind({ scope: stack, ecrRegistry });

// THEN -- didn't throw
});
});
});
2 changes: 1 addition & 1 deletion lib/registry-sync/mirror-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export abstract class MirrorSource {
}

public bind(options: MirrorSourceBindOptions) {
const asset = new s3Assets.Asset(options.scope, `BuildContext${this.directory}`, { path: this.directory! });
const asset = new s3Assets.Asset(options.scope, `BuildContext${this.directory}${JSON.stringify(opts.buildArgs ?? {})}`, { path: this.directory! });
if (options.syncJob) {
asset.grantRead(options.syncJob);
}
Expand Down

0 comments on commit 9031548

Please sign in to comment.