Dockerize FilePizza.

pull/50/head
Alex Kern 10 years ago
parent 31dd446625
commit 532c996b57

@ -0,0 +1,52 @@
# Logs
log
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
# OSX
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
.AppleDouble
.LSOverride
Icon
# Java
*.class
# Git
.git
# FilePizza
src
resources
log

@ -0,0 +1,14 @@
FROM node:latest
MAINTAINER Alex Kern <alex@pavlovml.com>
# install
RUN mkdir -p /filepizza
WORKDIR /filepizza
COPY package.json Makefile ./
RUN make install
COPY . ./
# run
ENV NODE_ENV production
EXPOSE 80
CMD ./dist/index.js

@ -0,0 +1,40 @@
# ==============================================================================
# config
.PHONY: all build clean install push run
all: run
WATCH ?= false
TAG ?= latest
# ==============================================================================
# phony targets
build:
./node_modules/.bin/babel src --ignore __tests__,__mocks__ --out-dir dist
./node_modules/.bin/webpack --optimize-minimize ./src/client
docker build -t kern/filepizza:$(TAG) .
clean:
@ rm -rf node_modules
@ rm -rf dist
install:
npm install
push: build
docker push kern/filepizza:$(TAG)
run: | node_modules
@ if [ "$(WATCH)" = false ]; then \
./node_modules/.bin/babel-node src; \
else \
./node_modules/.bin/nodemon ./node_modules/.bin/babel-node -i dist src; \
fi
# ==============================================================================
# file targets
node_modules:
npm install

@ -1,10 +0,0 @@
#! /usr/bin/env node
try {
require('./newrelic')
require('newrelic')
} catch (ex) {
// Don't load New Relic if the configuration file doesn't exist.
}
module.exports = require('./dist/server')

@ -1,7 +0,0 @@
var path = require('path')
var CLIENT_MODULE_PATH = path.resolve(__dirname, '../client.js')
module.exports = function (req, res) {
res.sendFile(CLIENT_MODULE_PATH)
}

@ -2,30 +2,43 @@
"name": "filepizza", "name": "filepizza",
"version": "0.2.4", "version": "0.2.4",
"description": "Free peer-to-peer file transfers in your browser.", "description": "Free peer-to-peer file transfers in your browser.",
"preferGlobal": "true",
"bin": "./dist/index.js",
"author": "Alex Kern <alex@kern.io> (http://kern.io)",
"license": "BSD-3-Clause",
"homepage": "https://github.com/kern/filepizza",
"scripts": { "scripts": {
"clean": "rm -rf dist && mkdir -p dist", "start": "make run"
"prepublish": "npm run build:prod",
"build:prod": "npm run build:prod:server && npm run build:prod:client",
"build:prod:server": "./node_modules/.bin/babel lib -d dist",
"build:prod:client": "./node_modules/.bin/browserify lib/client.js -t babelify -t uglifyify | ./node_modules/.bin/uglifyjs -cm > dist/client.js",
"build:dev": "npm run build:dev:server && npm run build:dev:client",
"build:dev:server": "./node_modules/.bin/babel lib -d dist -s inline",
"build:dev:client": "./node_modules/.bin/browserify lib/client.js -t babelify -o dist/client.js -d",
"watch": "./node_modules/.bin/nodemon -w lib --exec 'npm run build:dev && npm run start'",
"start": "node index.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git@github.com:kern/filepizza.git" "url": "git@github.com:kern/filepizza.git"
}, },
"author": "Alex Kern <alex@kern.io> (http://kern.io)",
"license": "BSD-3-Clause",
"bugs": { "bugs": {
"url": "https://github.com/kern/filepizza/issues" "url": "https://github.com/kern/filepizza/issues"
}, },
"homepage": "https://github.com/kern/filepizza", "engines": {
"node": ">= 5.0.0",
"npm": ">= 3.3.0"
},
"babel": {
"presets": [
"es2015",
"stage-0"
],
"plugins": [
"add-module-exports",
"transform-react-jsx"
]
},
"dependencies": { "dependencies": {
"alt": "^0.14.4", "alt": "^0.14.4",
"babel-cli": "^6.6.5",
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-transform-react-jsx": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"classnames": "^1.2.0", "classnames": "^1.2.0",
"express": "^4.12.0", "express": "^4.12.0",
"express-force-ssl": "^0.3.0", "express-force-ssl": "^0.3.0",
@ -42,21 +55,15 @@
"socket.io-client": "^1.3.5", "socket.io-client": "^1.3.5",
"stylus": "^0.50.0", "stylus": "^0.50.0",
"twilio": "^2.3.0", "twilio": "^2.3.0",
"webpack": "^1.12.14",
"webrtcsupport": "^2.1.2", "webrtcsupport": "^2.1.2",
"webtorrent": "^0.90.3",
"winston": "^1.0.1", "winston": "^1.0.1",
"xkcd-password": "^1.2.0" "xkcd-password": "^1.2.0"
}, },
"engines": {
"node": "0.12.x"
},
"preferGlobal": "true",
"bin": "./index.js",
"devDependencies": { "devDependencies": {
"babel": "^5.8.23", "json-loader": "^0.5.4",
"babelify": "^6.3.0",
"browserify": "^11.0.1",
"nodemon": "^1.4.1", "nodemon": "^1.4.1",
"uglify-js": "^2.4.24", "webpack-dev-middleware": "^1.6.1"
"uglifyify": "^3.0.1"
} }
} }

@ -43,7 +43,6 @@ export default class App extends React.Component {
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Quicksand:300,400,700|Lobster+Two" /> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Quicksand:300,400,700|Lobster+Two" />
<link rel="stylesheet" href="/css" /> <link rel="stylesheet" href="/css" />
<script src="//cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js" />
<Bootstrap data={this.props.data} /> <Bootstrap data={this.props.data} />
<script src="/js" /> <script src="/js" />

@ -0,0 +1,24 @@
#! /usr/bin/env node
try {
require('../newrelic')
require('newrelic')
} catch (ex) {
// Don't load New Relic if the configuration file doesn't exist.
}
process.on('unhandledRejection', (reason, p) => {
p.catch(err => {
console.error('Exiting due to unhandled rejection!')
console.error(err)
process.exit(1)
})
})
process.on('uncaughtException', err => {
console.error('Exiting due to uncaught exception!')
console.error(err.stack)
process.exit(1)
})
module.exports = require('./server')

@ -4,8 +4,6 @@ module.exports = function (err, req, res, next) {
var message = err.message || '' var message = err.message || ''
var stack = process.env.NODE_ENV === 'production' ? null : err.stack || null var stack = process.env.NODE_ENV === 'production' ? null : err.stack || null
console.log(err)
req.url = '/error' req.url = '/error'
res.status(status) res.status(status)
res.locals.data = { res.locals.data = {

@ -0,0 +1,16 @@
const path = require('path')
const BUNDLE_PATH = path.resolve(__dirname, '../../dist/bundle.js')
if (process.env.NODE_ENV === 'production') {
module.exports = function (req, res) {
res.sendFile(BUNDLE_PATH)
}
} else {
const webpackMiddleware = require('webpack-dev-middleware')
const webpack = require('webpack')
const config = require('../../webpack.config.js')
config.output.filename = '/js'
config.output.path = '/'
module.exports = webpackMiddleware(webpack(config))
}

@ -46,6 +46,20 @@ server.on('error', function (err) {
process.exit(1) process.exit(1)
}) })
process.on('unhandledRejection', (reason, p) => {
p.catch(err => {
log.error('Exiting due to unhandled rejection!')
log.error(err)
process.exit(1)
})
})
process.on('uncaughtException', err => {
log.error('Exiting due to uncaught exception!')
log.error(err)
process.exit(1)
})
server.listen(port, function (err) { server.listen(port, function (err) {
var host = server.address().address var host = server.address().address
var port = server.address().port var port = server.address().port
@ -57,9 +71,9 @@ app.use(expressWinston.logger({
expressFormat: true expressFormat: true
})) }))
if (process.env.NODE_ENV === 'production') { // if (process.env.NODE_ENV === 'production') {
app.use(forceSSL) // app.use(forceSSL)
} // }
app.get('/js', require('./middleware/javascript')) app.get('/js', require('./middleware/javascript'))
app.get('/css', require('./middleware/css')) app.get('/css', require('./middleware/css'))

@ -35,7 +35,7 @@ export default alt.createStore(class DownloadStore {
this.status = 'requesting' this.status = 'requesting'
getClient().then((client) => { getClient().then((client) => {
client.download(this.infoHash, (torrent) => { client.add(this.infoHash, (torrent) => {
this.setState({ status: 'downloading' }) this.setState({ status: 'downloading' })
const updateSpeed = () => { const updateSpeed = () => {

@ -42,7 +42,7 @@ export default alt.createStore(class UploadStore {
fileName: file.name, fileName: file.name,
fileSize: file.size, fileSize: file.size,
fileType: file.type, fileType: file.type,
infoHash: torrent.infoHash infoHash: torrent.magnetURI
}, (token) => { }, (token) => {
this.setState({ this.setState({
status: 'uploading', status: 'uploading',
@ -50,7 +50,7 @@ export default alt.createStore(class UploadStore {
fileName: file.name, fileName: file.name,
fileSize: file.size, fileSize: file.size,
fileType: file.type, fileType: file.type,
infoHash: torrent.infoHash infoHash: torrent.magnetURI
}) })
}) })

@ -1,3 +1,4 @@
import WebTorrent from 'webtorrent'
import socket from 'filepizza-socket' import socket from 'filepizza-socket'
export function getClient() { export function getClient() {

@ -0,0 +1,26 @@
module.exports = {
entry: './src/client',
target: 'web',
output: {
filename: 'dist/bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.json$/,
loader: 'json'
}
]
},
node: {
fs: 'empty'
}
}
Loading…
Cancel
Save