Skip to content

Commit 02b18b9

Browse files
committed
Merge pull request #11 from connyay/enable-http-checking
enable basic http & https checking
2 parents 5747221 + 75eb6e4 commit 02b18b9

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

bin/dockerfile_lint

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ function printEntry(entry, level){
3939

4040
}
4141

42+
function isRedirect(statusCode) {
43+
return (statusCode === 300 || statusCode === 301 || statusCode === 302);
44+
}
45+
46+
function downloadDockerfile(url, cb) {
47+
var proto, dockerfile = '';
48+
if(url.match('^https://')) {
49+
proto = require('https');
50+
} else {
51+
proto = require('http');
52+
}
53+
proto.get(url, function(res) {
54+
res.on('data', function(data) {
55+
dockerfile += data;
56+
}).on('end', function() {
57+
if (isRedirect(res.statusCode) && res.headers.location) {
58+
return downloadDockerfile(res.headers.location, cb);
59+
}
60+
cb(dockerfile);
61+
});
62+
});
63+
}
64+
4265
function printResults(results){
4366
var errors = results.error;
4467
var warn = results.warn;
@@ -80,6 +103,7 @@ var rulefileLocation = null;
80103
var dockerfile = null;
81104
var rulefile = null;
82105
var printJson = false;
106+
var remoteFile = false;
83107

84108

85109

@@ -104,8 +128,12 @@ if (commandline.rulefile){
104128
try {
105129
dockerfile = fs.readFileSync(dockerfileLocation, 'UTF-8');
106130
} catch (e) {
107-
console.error('ERROR: Dockerfile not found -> ' + dockerfileLocation);
108-
process.exit(1);
131+
if (/^http[s]?:\/\//.test(dockerfileLocation)) {
132+
remoteFile = true;
133+
} else {
134+
console.error('ERROR: Dockerfile not found -> ' + dockerfileLocation);
135+
process.exit(1);
136+
}
109137
}
110138
if (rulefileLocation !== null) {
111139
try {
@@ -116,16 +144,27 @@ if (rulefileLocation !== null) {
116144
}
117145
}
118146

119-
var validator = new DockeFileValidator(rulefile);
120-
var results = validator.validate(dockerfile);
121-
if (printJson){
122-
printJsonResults(results);
123-
}else {
124-
printResults(results);
147+
function runValidation(dockerfile, rulefile) {
148+
var validator = new DockeFileValidator(rulefile);
149+
var results = validator.validate(dockerfile);
150+
if (printJson){
151+
printJsonResults(results);
152+
}else {
153+
printResults(results);
154+
}
155+
156+
if (results.error.count > 0) {
157+
process.exit(1);
158+
} else {
159+
process.exit(0);
160+
}
125161
}
126162

127-
if (results.error.count > 0) {
128-
process.exit(1);
163+
if (remoteFile) {
164+
downloadDockerfile(dockerfileLocation, function(dockerfile){
165+
runValidation(dockerfile, rulefile);
166+
});
129167
} else {
130-
process.exit(0);
168+
runValidation(dockerfile, rulefile);
131169
}
170+

0 commit comments

Comments
 (0)