1
2
mirror of https://github.com/vimagick/dockerfiles synced 2024-06-16 03:48:44 +00:00

add webkit

This commit is contained in:
kev 2014-12-25 17:07:50 +08:00
parent eeefab6355
commit 67c21bfe42
10 changed files with 124 additions and 4 deletions

24
webkit/Dockerfile Normal file

@ -0,0 +1,24 @@
#
# Dockerfile for webkit
#
FROM ubuntu:14.04
MAINTAINER kev
RUN apt-get update && apt-get install -y supervisor haproxy libfontconfig1 libfreetype6
RUN mkdir -p /usr/local/lib/webkit/
ADD ./*.js ./includes/ /usr/local/lib/webkit/
ADD ./phantomjs /usr/local/bin/
ADD ./webkit.sh /usr/local/bin/
ADD ./restart.sh /usr/local/bin/
ADD ./haproxy.cfg /etc/haproxy/
ADD ./supervisor/supervisord.conf /etc/supervisor/
ADD ./supervisor/conf.d/haproxy.conf /etc/supervisor/conf.d/
ADD ./supervisor/conf.d/webkit.conf /etc/supervisor/conf.d/
ADD ./supervisor/conf.d/restart.conf /etc/supervisor/conf.d/
EXPOSE 1024 9001
CMD /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf

42
webkit/haproxy.cfg Normal file

@ -0,0 +1,42 @@
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
#daemon
defaults
log global
mode http
option httplog
option dontlognull
contimeout 5000
clitimeout 50000
srvtimeout 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend front
bind 0.0.0.0:1024
default_backend back
stats enable
stats admin if TRUE
backend back
server s0 127.0.0.1:8080 maxconn 10
server s1 127.0.0.1:8081 maxconn 10
server s2 127.0.0.1:8082 maxconn 10
server s3 127.0.0.1:8083 maxconn 10
server s4 127.0.0.1:8084 maxconn 10
server s5 127.0.0.1:8085 maxconn 10
server s6 127.0.0.1:8086 maxconn 10
server s7 127.0.0.1:8087 maxconn 10
server s8 127.0.0.1:8088 maxconn 10
server s9 127.0.0.1:8089 maxconn 10

BIN
webkit/phantomjs Executable file

Binary file not shown.

13
webkit/restart.sh Executable file

@ -0,0 +1,13 @@
#!/bin/bash
#
# restart webkit instances one by one forever
#
while :
do
for ((i=8080; i<8090; i++))
do
sleep 30
/usr/bin/supervisorctl restart webkit:webkit-$i
done
done

11
webkit/server.js Executable file → Normal file

@ -1,6 +1,7 @@
#!/usr/bin/env phantomjs
var system = require('system');
var fs = require('fs');
var sys = require('system');
var server = require('webserver').create();
var parser = require('./parser');
var client = require('./client');
@ -8,15 +9,14 @@ var utils = require('./utils');
var port;
if(system.args.length > 1) {
port = parseInt(system.args[1]);
if(sys.args.length > 1) {
port = parseInt(sys.args[1]);
} else {
port = 1024;
}
var ok = server.listen(port, function(request, response) {
var req;
if(request.method === 'POST') {
try {
var raw = request.postRaw || request.post || '{}',
@ -40,7 +40,10 @@ var ok = server.listen(port, function(request, response) {
if(ok) {
var pidfile = '/tmp/webkit-' + port.toString() + '.pid';
utils.info('service started (listen %d)', port);
utils.info('write pidfile: %s (pid %d)', pidfile, sys.pid);
fs.write(pidfile, sys.pid.toString(), 'w');
} else {
utils.error('service failed to start');
phantom.exit(1);

@ -0,0 +1,2 @@
[program:haproxy]
command = /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

@ -0,0 +1,2 @@
[program:restart]
command = /usr/local/bin/restart.sh

@ -0,0 +1,5 @@
[program:webkit]
command = /usr/local/bin/webkit.sh %(process_num)d
numprocs_start = 8080
numprocs = 10
process_name = %(program_name)s-%(process_num)d

@ -0,0 +1,20 @@
[inet_http_server]
port = 0.0.0.0:9001
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[supervisord]
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=http://127.0.0.1:9001
[include]
files = /etc/supervisor/conf.d/*.conf

9
webkit/webkit.sh Executable file

@ -0,0 +1,9 @@
#!/bin/bash
#
# run webkit instance
#
set -e
cd /usr/local/lib/webkit
phantomjs server.js "$@"