Skip to content

Commit

Permalink
Add support for the SHELL Dockerfile command
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Jul 10, 2016
1 parent 8df0a0f commit d9ccb19
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .dockerfilelintrc
@@ -0,0 +1,2 @@
rules:
uppercase_commands: off
9 changes: 9 additions & 0 deletions lib/checks.js
Expand Up @@ -152,5 +152,14 @@ var commands = module.exports = {

return result;
}
},

is_valid_shell: function(args) {
// Dockerfile syntax requires that args be in JSON array format
var parsed = JSON.parse(args);
if (parsed.constructor !== Array) {
return ['invalid_format'];
}
return [];
}
}
5 changes: 5 additions & 0 deletions lib/index.js
Expand Up @@ -257,6 +257,11 @@ function runLine(state, instructions, idx) {
break;
case 'stopsignal':
break;
case 'shell':
checks.is_valid_shell(args).forEach(function(item) {
items.push(messages.build(state.rules, item, line));
});
break;
default:
items.push(messages.build(state.rules, 'invalid_command', line));
break;
Expand Down
6 changes: 3 additions & 3 deletions test/cli_reporter.js
Expand Up @@ -98,7 +98,7 @@ describe('cli_reporter', () => {
expect(Object.keys(reporter.fileReports)).to.have.length(1);
let fileReport = reporter.fileReports[file];
expect(fileReport.uniqueIssues).to.equal(3);
expect(fileReport.contentArray).to.have.length(34);
expect(fileReport.contentArray).to.have.length(35);
expect(fileReport.itemsByLine).to.deep.equal({
'5': [ items[0] ],
'6': items.splice(1)
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('cli_reporter', () => {
expect(Object.keys(reporter.fileReports)).to.have.length(1);
let fileReport = reporter.fileReports[file];
expect(fileReport.uniqueIssues).to.equal(1);
expect(fileReport.contentArray).to.have.length(34);
expect(fileReport.contentArray).to.have.length(35);
expect(fileReport.itemsByLine).to.deep.equal({
'6': [ items[0] ]
});
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('cli_reporter', () => {
});
let file2Report = reporter.fileReports[file2];
expect(file2Report.uniqueIssues).to.equal(2);
expect(file2Report.contentArray).to.have.length(34);
expect(file2Report.contentArray).to.have.length(35);
expect(file2Report.itemsByLine).to.deep.equal({
'5': [ file2Items[0] ],
'6': [ file2Items[1] ]
Expand Down
1 change: 1 addition & 0 deletions test/examples/Dockerfile.misc
Expand Up @@ -30,4 +30,5 @@ ONBUILD RUN echo test
STOPSIGNAL SIGKILL
ADD /test* /test2
CMD ["bash"]
SHELL ["/bin/sh", "-c"]
ENTRYPOINT ["bash"]
5 changes: 5 additions & 0 deletions test/examples/Dockerfile.shell.fail
@@ -0,0 +1,5 @@
FROM alpine:4

SHELL ["/bin/sh"]
SHELL "bin/sh"
SHELL ["/bin/sh", "-c"]
3 changes: 3 additions & 0 deletions test/examples/Dockerfile.shell.pass
@@ -0,0 +1,3 @@
FROM alpine:4

SHELL ["/bin/sh", "-c"]
21 changes: 21 additions & 0 deletions test/index.js
Expand Up @@ -64,6 +64,27 @@ describe("index", function(){
});
});

describe("#shell", function() {
it("validates the shell command is accepted when entered correctly", function() {
expect(dockerfilelint.run('./test/examples', fs.readFileSync('./test/examples/Dockerfile.shell.pass', 'UTF-8'))).to.be.empty;
});

it("validates the shell command detects invalid shell commands", function() {
var expected = [
{ title: 'Invalid Argument Format',
line: 4,
rule: 'invalid_format'}
];
var result = dockerfilelint.run('./test/examples', fs.readFileSync('./test/examples/Dockerfile.shell.fail', 'UTF-8'));
_.forEach(result, function(r) {
delete r['description'];
delete r['category'];
});
expect(result).to.have.length(expected.length);
expect(result).to.deep.equal(expected);
});
});

describe("#misc", function(){
it("validates the misc Dockerfile have the exact right issues reported", function(){
var expected = [
Expand Down

0 comments on commit d9ccb19

Please sign in to comment.