validate-dockerfile
Advanced tools
Comparing version 1.3.0 to 1.4.0
39
index.js
@@ -45,3 +45,3 @@ 'use strict'; | ||
var hasFrom = false; | ||
var fromCheck = false; | ||
var hasCmd = false; | ||
@@ -51,6 +51,3 @@ var currentLine = 0; | ||
var linesArr = dockerfile.split('\n').filter(function (line) { | ||
var tLine = line.trim(); | ||
return tLine && tLine[0] !== '#'; | ||
}); | ||
var linesArr = dockerfile.split('\n'); | ||
@@ -60,3 +57,17 @@ function validateLine(line) { | ||
line = line.trim(); | ||
if (!line || line[0] === '#') { | ||
return; | ||
} | ||
// First instruction must be FROM | ||
if (!fromCheck) { | ||
fromCheck = true; | ||
if (line.toUpperCase().indexOf('FROM') !== 0) { | ||
errors.push({ | ||
message: 'Missing or misplaced FROM', | ||
line: currentLine | ||
}); | ||
} | ||
} | ||
var instruction = instructionsRegex.exec(line); | ||
@@ -86,15 +97,9 @@ if (!instruction) { | ||
return true; | ||
}; | ||
if (!linesArr.length) { | ||
errors.push({ | ||
message: 'Empty dockerfile' | ||
}); | ||
return finish(errors); | ||
} | ||
// First line should be FROM instruction | ||
if (linesArr[0].toUpperCase().indexOf('FROM') !== 0) { | ||
linesArr.forEach(validateLine); | ||
if (!fromCheck) { | ||
errors.push({ | ||
message: 'Missing FROM', | ||
message: 'Missing or misplaced FROM', | ||
line: 1 | ||
@@ -104,4 +109,2 @@ }); | ||
linesArr.forEach(validateLine); | ||
if (!hasCmd) { | ||
@@ -114,4 +117,4 @@ errors.push({ | ||
return finish(errors); | ||
}; | ||
} | ||
module.exports = validate; |
{ | ||
"name": "validate-dockerfile", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Validates a Dockerfile", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -41,3 +41,3 @@ #validate-dockerfile | ||
- i.e. `FROM Incom/Z-95 Headhunter` | ||
- `Missing FROM` | ||
- `Missing or misplaced FROM` | ||
- `FROM` is not the first instruction in the dockerfile. | ||
@@ -48,5 +48,2 @@ - For more: https://docs.docker.com/reference/builder/#from | ||
- For more: https://docs.docker.com/reference/builder/#cmd | ||
- `Empty dockerfile` | ||
- The dockerfile does not contain any instructions | ||
- More than likely, you're passing the wrong parameter | ||
- `Invalid type` | ||
@@ -53,0 +50,0 @@ - You gave us something other than a string |
@@ -35,3 +35,3 @@ 'use strict'; | ||
stderr.should.eql(['VALIDATION FAILED', | ||
'Missing FROM', | ||
'Missing or misplaced FROM', | ||
'at line 1', | ||
@@ -38,0 +38,0 @@ 'Invalid instruction', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20
26349
434
67
2