Skip to content

Commit

Permalink
feat: interpret multiple FROM commands as multi-stage builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed Sep 12, 2017
1 parent 7abc92d commit 9970cce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 13 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ module.exports.run = function(configPath, content) {
});

var state = {
instructionsProcessed: 0,
cmdFound: false,
stages: [{
instructionsProcessed: 0,
cmdFound: false // this doesn't seem to be used anywhere
}],
items: [],
rules: loadRules(configPath)
}
Expand All @@ -62,11 +64,17 @@ module.exports.run = function(configPath, content) {

// We care about only having 1 cmd instruction
if (result.command === 'cmd') {
state.cmdFound = true;
state.stages[state.stages.length - 1].cmdFound = true;
} else if (result.command === 'from' && state.stages[state.stages.length - 1].instructionsProcessed !== 0) {
// Each FROM command constitutes a new stage in a multistage build
state.stages.push({
instructionsProcessed: 0,
cmdFound: false
});
}

// And we also care about knowing if this is the first command or not
state.instructionsProcessed = state.instructionsProcessed + 1;
state.stages[state.stages.length - 1].instructionsProcessed++;
};

return state.items;
Expand Down Expand Up @@ -116,7 +124,7 @@ function runLine(state, instructions, idx) {

// check that the first command is a FROM, this might get reported twice, if the FROM command does exist,
// but is not the time (non blank, non commented) line
if ((state.instructionsProcessed === 0 && cmd !== 'from') || (state.instructionsProcessed !== 0 && cmd === 'from')) {
if (state.stages[state.stages.length - 1].instructionsProcessed === 0 && cmd !== 'from') {
items.push(messages.build(state.rules, 'from_first', line));
}

Expand Down
6 changes: 0 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,9 @@ describe("index", function(){
{ title: 'First Command Must Be FROM',
rule: 'from_first',
line: 4 },
{ title: 'First Command Must Be FROM',
rule: 'from_first',
line: 5 },
{ title: 'Base Image Missing Tag',
rule: 'missing_tag',
line: 5 },
{ title: 'First Command Must Be FROM',
rule: 'from_first',
line: 6 },
{ title: 'Base Image Latest Tag',
rule: 'latest_tag',
line: 6 },
Expand Down

0 comments on commit 9970cce

Please sign in to comment.