Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #8 from sphereio/dockerize
Browse files Browse the repository at this point in the history
Dockerize application
  • Loading branch information
hajoeichler committed May 30, 2017
2 parents f8763cc + 0a00cad commit 9155fdc
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
@@ -0,0 +1,7 @@
coverage
data
logs
test
tmp
.npmignore
.travis.yml
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ lib
test
.coveralls.yml
coverage
logs
tmp
*.siege
strongloop.json
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -2,6 +2,7 @@ node_modules
*.log
src
test
logs
data
coverage
.travis.yml
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile
@@ -0,0 +1,22 @@
FROM node:0.12

MAINTAINER SPHERE.IO Support <support@sphere.io>

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"]
30 changes: 5 additions & 25 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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=<API_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:
Expand Down
11 changes: 11 additions & 0 deletions 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
Empty file added container/files/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -27,6 +27,7 @@
},
"scripts": {
"start": "node ./lib/app.js",
"build": "grunt build",
"test": "grunt coverage"
},
"dependencies": {
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/coffee/app.coffee
Expand Up @@ -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
Expand Down

0 comments on commit 9155fdc

Please sign in to comment.