Skip to content
Snippets Groups Projects
Unverified Commit 3f77d676 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix: docker multi-stage duplicate replace (#1662)

Closes #1656
parent 1b2a3196
No related merge requests found
......@@ -10,11 +10,9 @@ function setNewValue(currentFileContent, upgrade) {
upgrade.fromSuffix
}\\n`
);
let newLine = `$1${upgrade.fromPrefix}$2${upgrade.newFrom}$3`;
if (upgrade.fromSuffix.length) {
newLine += `${upgrade.fromSuffix}`;
}
newLine += '\n';
const newLine = `$1${upgrade.fromPrefix}$2${upgrade.newFrom}$3${
upgrade.fromSuffix
}\n`;
const newFileContent = currentFileContent.replace(oldLine, newLine);
return newFileContent;
} catch (err) {
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`workers/branch/dockerfile setNewValue handles similar FROM 1`] = `
"FROM debian:wheezy@sha256:abcdefghijklmnop as stage-1
RUN something
FROM debian:wheezy@sha256:abcdefghijklmnop
RUN something else"
`;
exports[`workers/branch/dockerfile setNewValue handles strange whitespace 1`] = `
"# comment FROM node:8
FROM node:8@sha256:abcdefghijklmnop as base
......
......@@ -53,5 +53,27 @@ describe('workers/branch/dockerfile', () => {
const res = dockerfile.setNewValue(currentFileContent, upgrade);
expect(res).toBe(null);
});
it('handles similar FROM', () => {
const currentFileContent =
'FROM debian:wheezy as stage-1\nRUN something\nFROM debian:wheezy\nRUN something else';
const upgrade1 = {
depName: 'debian',
currentVersion: 'debian:wheezy',
fromPrefix: 'FROM',
fromSuffix: 'as stage-1',
newFrom: 'debian:wheezy@sha256:abcdefghijklmnop',
};
const upgrade2 = {
depName: 'debian',
currentVersion: 'debian:wheezy',
fromPrefix: 'FROM',
fromSuffix: '',
newFrom: 'debian:wheezy@sha256:abcdefghijklmnop',
};
let res = dockerfile.setNewValue(currentFileContent, upgrade1);
res = dockerfile.setNewValue(res, upgrade2);
expect(res).toMatchSnapshot();
expect(res.includes('as stage-1')).toBe(true);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment