Skip to content

Commit

Permalink
fix(ecr-mirror): fromDir() fails when building multiple tags for one …
Browse files Browse the repository at this point in the history
…repo (#1048)

The `unzip` command used will throw up an `overwrite? [y]es/[n]o` dialog
when using `fromDir()` to build multiple tags into the same repository.

This fails. Prevent it by cleaning similarly named files and directories
before we begin.
  • Loading branch information
rix0rrr authored Oct 15, 2021
1 parent 1fcd663 commit c26288f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 15 additions & 6 deletions lib/__tests__/registry-sync/mirror-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ describe('RegistryImageSource', () => {
// THEN
expect(result.repositoryName).toEqual('myrepository');
expect(result.tag).toEqual('latest');
const cmds = result.commands;
expect(cmds.shift()).toMatch(/aws s3 cp s3:.* myrepository.zip/);
expect(cmds).toEqual([
expect(result.commands).toEqual([
'rm -rf myrepository.zip myrepository',
expect.stringMatching(/aws s3 cp s3:.* myrepository.zip/),
'unzip myrepository.zip -d myrepository',
'docker build --pull -t myregistry/myrepository:latest myrepository',
]);
Expand All @@ -115,7 +115,12 @@ describe('RegistryImageSource', () => {
// THEN
expect(result.repositoryName).toEqual('myrepository');
expect(result.tag).toEqual('mytag');
expect(result.commands[2]).toEqual('docker build --pull -t myregistry/myrepository:mytag myrepository');
expect(result.commands).toEqual([
'rm -rf myrepository.zip myrepository',
expect.stringMatching(/aws s3 cp s3:.* myrepository.zip/),
'unzip myrepository.zip -d myrepository',
'docker build --pull -t myregistry/myrepository:mytag myrepository',
]);
});

test('syncJob is given permission to s3 asset', () => {
Expand Down Expand Up @@ -196,8 +201,12 @@ describe('RegistryImageSource', () => {
});

// THEN
const expected = 'docker build --pull -t myregistry/myrepository:latest --build-arg arg1=val1 --build-arg arg2=val2 myrepository';
expect(result.commands[2]).toEqual(expected);
expect(result.commands).toEqual([
'rm -rf myrepository.zip myrepository',
expect.stringMatching(/aws s3 cp s3:.* myrepository.zip/),
'unzip myrepository.zip -d myrepository',
'docker build --pull -t myregistry/myrepository:latest --build-arg arg1=val1 --build-arg arg2=val2 myrepository',
]);
});

test('can bind the same directory twice if they have different build args', () => {
Expand Down
10 changes: 7 additions & 3 deletions lib/registry-sync/mirror-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ export abstract class MirrorSource {
Object.entries(opts.buildArgs).forEach(([k, v]) => cmdFlags.push('--build-arg', `${k}=${v}`));
}

const zipFile = `${this.repositoryName}.zip`;
const tmpDir = this.repositoryName;

return {
commands: [
`aws s3 cp ${asset.s3ObjectUrl} ${this.repositoryName}.zip`,
`unzip ${this.repositoryName}.zip -d ${this.repositoryName}`,
`docker build ${cmdFlags.join(' ')} ${this.repositoryName}`,
`rm -rf ${zipFile} ${tmpDir}`,
`aws s3 cp ${asset.s3ObjectUrl} ${zipFile}`,
`unzip ${zipFile} -d ${tmpDir}`,
`docker build ${cmdFlags.join(' ')} ${tmpDir}`,
],
repositoryName: this.repositoryName,
tag: this.tag,
Expand Down

0 comments on commit c26288f

Please sign in to comment.