Skip to content

Commit

Permalink
Merge pull request ampproject#2015 from jkingyens/dockerize-validator
Browse files Browse the repository at this point in the history
Dockerize validate & support validation from stdin
  • Loading branch information
powdercloud committed Feb 17, 2016
2 parents 784990f + 4c62900 commit 157ef75
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
1 change: 1 addition & 0 deletions validator/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions validator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:5.5.0
MAINTAINER [email protected]
RUN apt-get -y update
RUN apt-get -y install openjdk-7-jre protobuf-compiler python-protobuf python2.7
WORKDIR /root
ADD package.json /root/
RUN npm install
ADD . /root
RUN python build.py
ENTRYPOINT [ "/usr/local/bin/node", "/root/dist/validate", "-" ]
15 changes: 15 additions & 0 deletions validator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ empty.html:1:0 MANDATORY_TAG_MISSING noscript enclosure for mandatory style (see
empty.html:1:0 MANDATORY_TAG_MISSING body (see https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#crps)
empty.html:1:0 MANDATORY_TAG_MISSING amphtml engine v0.js script (see https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#scrpt)
```

###Docker

Build a docker image that contains the amp validator:

```
docker build -t=amp-validator .
```

Validate an amp html file by piping a file through a container:

```
cat examples\facebook.amp.html | docker run -i amp-validator
PASS
```
50 changes: 30 additions & 20 deletions validator/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,37 +252,47 @@ def GenerateValidateBin(out_dir, nodejs_cmd):
function main() {
if (process.argv.length < 3) {
console.error('usage: validate <file.html or url>');
console.error('usage: validate <file.html>|<url>|-');
process.exit(1)
}
var args = process.argv.slice(2);
var full_path = args[0];
if (full_path.indexOf('http://') === 0 ||
full_path.indexOf('https://') === 0) {
var callback = function(response) {
var chunks = [];
var callback = function(response) {
var chunks = [];
response.on('data', function (chunk) {
chunks.push(chunk);
});
response.on('data', function (chunk) {
chunks.push(chunk);
});
response.on('end', function () {
validateFile(chunks.join(''), full_path);
});
};
response.on('end', function () {
validateFile(chunks.join(''), full_path);
});
var clientModule = http;
if (full_path.indexOf('https://') === 0) {
clientModule = https;
}
};
clientModule.request(url.parse(full_path), callback).end();
if (full_path === '-') {
callback(process.stdin);
process.stdin.resume();
} else {
var filename = path.basename(full_path);
var contents = fs.readFileSync(full_path, 'utf8');
validateFile(contents, filename);
if (full_path.indexOf('http://') === 0 ||
full_path.indexOf('https://') === 0) {
var clientModule = http;
if (full_path.indexOf('https://') === 0) {
clientModule = https;
}
clientModule.request(url.parse(full_path), callback).end();
} else {
var filename = path.basename(full_path);
var contents = fs.readFileSync(full_path, 'utf8');
validateFile(contents, filename);
}
}
}
if (require.main === module) {
Expand Down

0 comments on commit 157ef75

Please sign in to comment.