diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..93d7954 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +coverage +data +logs +test +tmp +.npmignore +.travis.yml diff --git a/.gitignore b/.gitignore index 2ae598b..c17af8e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ lib test .coveralls.yml coverage +logs tmp *.siege strongloop.json diff --git a/.npmignore b/.npmignore index b592138..0695018 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,7 @@ node_modules *.log src test +logs data coverage .travis.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8a41b29 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM node:0.12 + +MAINTAINER SPHERE.IO Support + +WORKDIR /app + +VOLUME /app/tmp + +ENV APP_ENV=docker NODE_ENV=production + +RUN \ + npm config set registry http://registry.npmjs.org/ && \ + npm i -g phantomjs-prebuilt + +COPY ./container/files / +COPY . /app + +RUN ./container/compile + +EXPOSE 8888 + +CMD ["npm", "start"] diff --git a/README.md b/README.md index 3251a13..7afbe4d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ Run a Restlet webserver to generate PDFs from HTML, using phantom.js ```bash $ brew install phantom + +# or + +$ npm i -g phantomjs-prebuilt +$ npm rebuild ``` Start the webserver @@ -43,31 +48,6 @@ $ npm start | bunyan -o short ... ``` -### StrongOps support -If you would like to monitor your application there is a default support for [StrongOps](http://strongloop.com/node-js-performance/strongops/) monitoring. - -Install the `slc` command-line tool (optional, but strongly recommended) - -```bash -$ npm install -g strong-cli -``` - -You can enable profiling by either: -- use a `strongloop.json` configuration file -- set `ENV` variables before running the app - -```bash -SL_KEY= SL_APP_NAME=sphere-express-pdf slc run |bunyan -o short - -strong-agent profiling app 'sphere-express-pdf' pid '38855' -strong-agent dashboard is at https://strongops.strongloop.com -12:07:01.297Z INFO sphere-express-pdf: Starting express application on port 3999 (development) -12:07:01.428Z INFO sphere-express-pdf: Listening for HTTP on http://localhost:3999 -``` - -> If you don't setup monitoring, the app still works - - ## Documentation The webserver started by express.js offers some JSON endpoints to work with PDFs. There are 2 basic principles regarding the endpoints: diff --git a/container/compile b/container/compile new file mode 100755 index 0000000..6f6133a --- /dev/null +++ b/container/compile @@ -0,0 +1,11 @@ +#!/bin/bash + +mkdir /var/log/sphere-express-pdf + +npm config set registry http://registry.npmjs.org/ +npm i --unsafe-perm --no-optional +npm run build + +# This is necessary in order to ensure the correct +# native binaries of phantomjs +npm rebuild diff --git a/container/files/.gitkeep b/container/files/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 25d4acc..996d641 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "scripts": { "start": "node ./lib/app.js", + "build": "grunt build", "test": "grunt coverage" }, "dependencies": { @@ -45,9 +46,11 @@ "useragent": "2.1.x" }, "devDependencies": { + "coffee-script": "~1.10.0", "coveralls": "~2.11.2", "grunt": "~0.4.2", "grunt-bump": "~0.0.13", + "grunt-cli": "~1.2.0", "grunt-coffeelint": "~0.0.8", "grunt-contrib-clean": "~0.6.0", "grunt-contrib-coffee": "~0.13.0", diff --git a/src/coffee/app.coffee b/src/coffee/app.coffee index 62cca86..989a41b 100644 --- a/src/coffee/app.coffee +++ b/src/coffee/app.coffee @@ -16,7 +16,9 @@ env = app.get 'env' port: 8888 baseUrl: 'https://pdf.sphere.io' logStream: [ - {level: 'info', path: "/var/log/#{pkg.name}/log"} + if process.env.APP_ENV is 'docker' + then {level: 'info', stream: process.stdout} + else {level: 'info', path: "/var/log/#{pkg.name}/log"} ] else port: 3999