Skip to content

Commit eaca957

Browse files
authored
Merge pull request #139 from marccampbell/from-with-as
Detect FROM with as and ports
2 parents e4dd297 + 605eb2b commit eaca957

File tree

6 files changed

+1919
-1389
lines changed

6 files changed

+1919
-1389
lines changed

lib/checks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ var commands = module.exports = {
3838
if (args.includes('@')) {
3939
baseImage = args.split('@');
4040
} else {
41-
baseImage = args.split(':');
41+
baseImage = args.split(' ')[0].split(":");
4242
}
4343
var result = [];
4444
if (baseImage.length === 1) {
4545
result.push('missing_tag');
46-
} else if (baseImage[1] === 'latest') {
46+
} else if (baseImage[baseImage.length - 1] === 'latest') {
4747
result.push('latest_tag');
4848
}
4949

test/examples/Dockerfile.from-as

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM repo/image:latest as example
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM some.registry:1234/repo/image:latest
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM some.registry:1234/repo/image:abcde

test/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,47 @@ describe("index", function(){
8181
});
8282
});
8383

84+
describe("#from-with-as", function () {
85+
it("validates the Dockerfile detects latest when using as", function () {
86+
var expected = [
87+
{ title: 'Base Image Latest Tag',
88+
line: 1,
89+
rule: 'latest_tag'}
90+
];
91+
const lintResult = dockerfilelint.run('./test/examples', fs.readFileSync('./test/examples/Dockerfile.from-as', 'UTF-8'));
92+
_.forEach(lintResult, function(r) {
93+
delete r['description'];
94+
delete r['category'];
95+
});
96+
expect(lintResult).to.have.length(expected.length);
97+
expect(lintResult).to.deep.equal(expected);
98+
});
99+
});
100+
101+
describe("#from-with-port", function () {
102+
it("validates the Dockerfile detects latest when it has a port", function () {
103+
var expected = [
104+
{ title: 'Base Image Latest Tag',
105+
line: 1,
106+
rule: 'latest_tag'}
107+
];
108+
const lintResult = dockerfilelint.run('./test/examples', fs.readFileSync('./test/examples/Dockerfile.from-with-port', 'UTF-8'));
109+
_.forEach(lintResult, function(r) {
110+
delete r['description'];
111+
delete r['category'];
112+
});
113+
expect(lintResult).to.have.length(expected.length);
114+
expect(lintResult).to.deep.equal(expected);
115+
});
116+
});
117+
118+
describe("#from-with-port-no-latest", function () {
119+
it("validates the Dockerfile detects not latest when it has a port", function () {
120+
const lintResult = dockerfilelint.run('./test/examples', fs.readFileSync('./test/examples/Dockerfile.from-with-port-no-latest', 'UTF-8'));
121+
expect(lintResult).to.have.length(0);
122+
});
123+
});
124+
84125
describe("#shell", function() {
85126
it("validates the shell command is accepted when entered correctly", function() {
86127
expect(dockerfilelint.run('./test/examples', fs.readFileSync('./test/examples/Dockerfile.shell.pass', 'UTF-8'))).to.be.empty;

0 commit comments

Comments
 (0)