This commit is contained in:
Joseph Schorr 2014-05-19 16:04:41 -04:00
commit faa46a12f2
36 changed files with 77 additions and 168 deletions

View file

@ -38,9 +38,11 @@ ADD test test
ADD conf conf
RUN rm -rf /conf/stack
ADD conf/init/tutumdocker.sh /etc/service/tutumdocker/run
ADD conf/init/dockerfilebuild.sh /etc/service/dockerfilebuild/run
ADD conf/init/svlogd_config /svlogd_config
ADD conf/init/preplogsdir.sh /etc/my_init.d/
ADD conf/init/tutumdocker /etc/service/tutumdocker
ADD conf/init/dockerfilebuild /etc/service/dockerfilebuild
VOLUME ["/var/lib/docker", "/var/lib/lxc", "/conf/stack"]
VOLUME ["/var/lib/docker", "/var/lib/lxc", "/conf/stack", "/var/log"]
CMD ["/sbin/my_init"]

View file

@ -45,11 +45,12 @@ ADD application.py application.py
ADD config.py config.py
ADD initdb.py initdb.py
ADD conf/init/mklogsdir.sh /etc/my_init.d/
ADD conf/init/gunicorn.sh /etc/service/gunicorn/run
ADD conf/init/nginx.sh /etc/service/nginx/run
ADD conf/init/diffsworker.sh /etc/service/diffsworker/run
ADD conf/init/webhookworker.sh /etc/service/webhookworker/run
ADD conf/init/svlogd_config /svlogd_config
ADD conf/init/preplogsdir.sh /etc/my_init.d/
ADD conf/init/gunicorn /etc/service/gunicorn
ADD conf/init/nginx /etc/service/nginx
ADD conf/init/diffsworker /etc/service/diffsworker
ADD conf/init/webhookworker /etc/service/webhookworker
RUN cd grunt && npm install
RUN cd grunt && grunt
@ -59,7 +60,7 @@ ADD test test
RUN TEST=true venv/bin/python -m unittest discover
RUN rm -rf /conf/stack
VOLUME ["/conf/stack", "/mnt/logs"]
VOLUME ["/conf/stack", "/var/log"]
EXPOSE 443 80

View file

@ -67,5 +67,5 @@ application.teardown_request(close_db)
application.request_class = RequestWithId
if __name__ == '__main__':
logging.config.fileConfig('conf/logging_local.conf', disable_existing_loggers=False)
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
application.run(port=5000, debug=True, threaded=True, host='0.0.0.0')

Binary file not shown.

View file

@ -2,6 +2,5 @@ bind = 'unix:/tmp/gunicorn.sock'
workers = 8
worker_class = 'gevent'
timeout = 2000
pidfile = '/tmp/gunicorn.pid'
logconfig = 'conf/logging.conf'
pythonpath = '.'

View file

@ -3,5 +3,5 @@ workers = 2
worker_class = 'gevent'
timeout = 2000
daemon = False
logconfig = 'conf/logging_local.conf'
logconfig = 'conf/logging.conf'
pythonpath = '.'

View file

@ -1,20 +1,8 @@
log_format logstash_json '{ "@timestamp": "$time_iso8601", '
'"@fields": { '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"body_bytes_sent": "$body_bytes_sent", '
'"request_time": "$request_time", '
'"status": "$status", '
'"request": "$request", '
'"request_method": "$request_method", '
'"http_referrer": "$http_referer", '
'"http_user_agent": "$http_user_agent" } }';
types_hash_max_size 2048;
include /usr/local/nginx/conf/mime.types.default;
default_type application/octet-stream;
access_log /mnt/logs/nginx.access.log logstash_json;
access_log /var/log/nginx/nginx.access.log;
sendfile on;
gzip on;

2
conf/init/diffsworker/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/diffsworker/

View file

@ -3,6 +3,6 @@
echo 'Starting diffs worker'
cd /
venv/bin/python -m workers.diffsworker --log=/mnt/logs/diffsworker.log
venv/bin/python -m workers.diffsworker
echo 'Diffs worker exited'

View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/dockerfilebuild/

2
conf/init/gunicorn/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/gunicorn/

View file

@ -1,4 +0,0 @@
#! /bin/sh
echo 'Creating logs directory'
mkdir -p /mnt/logs

2
conf/init/nginx/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/nginx/

View file

@ -5,10 +5,10 @@ echo 'Starting nginx'
if [ -f /conf/stack/ssl.key ]
then
echo "Using HTTPS"
/usr/local/nginx/sbin/nginx -c /conf/nginx-enterprise.conf
/usr/local/nginx/sbin/nginx -c /conf/nginx.conf
else
echo "No SSL key provided, using HTTP"
/usr/local/nginx/sbin/nginx -c /conf/nginx-enterprise-nossl.conf
/usr/local/nginx/sbin/nginx -c /conf/nginx-nossl.conf
fi
echo 'Nginx exited'

8
conf/init/preplogsdir.sh Executable file
View file

@ -0,0 +1,8 @@
#! /bin/sh
echo 'Linking config files to logs directory'
for svc in `ls /etc/service/`
do
mkdir -p /var/log/$svc
ln -s /svlogd_config /var/log/$svc/config
done

2
conf/init/svlogd_config Normal file
View file

@ -0,0 +1,2 @@
s100000000
t86400

2
conf/init/tutumdocker/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/tutumdocker/

View file

@ -92,6 +92,5 @@ if [ "$PORT" ]
then
exec docker -d -H 0.0.0.0:$PORT
else
docker -d -D -e lxc
docker -d -D -e lxc 2>&1
fi

View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd -t /var/log/webhookworker/

View file

@ -3,6 +3,6 @@
echo 'Starting webhook worker'
cd /
venv/bin/python -m workers.webhookworker --log=/mnt/logs/webhookworker.log
venv/bin/python -m workers.webhookworker
echo 'Webhook worker exited'

View file

@ -1,38 +1,38 @@
[loggers]
keys=root, gunicorn.error, gunicorn.access
keys=root, gunicorn.error, gunicorn.access, application.profiler
[handlers]
keys=error_file
keys=console
[formatters]
keys=generic
[logger_application.profiler]
level=DEBUG
handlers=error_file
handlers=console
propagate=0
qualname=application.profiler
[logger_root]
level=DEBUG
handlers=error_file
handlers=console
[logger_gunicorn.error]
level=INFO
handlers=error_file
handlers=console
propagate=1
qualname=gunicorn.error
[logger_gunicorn.access]
level=INFO
handlers=error_file
handlers=console
propagate=0
qualname=gunicorn.access
[handler_error_file]
class=logging.FileHandler
[handler_console]
class=StreamHandler
formatter=generic
args=('/mnt/logs/application.log',)
args=(sys.stdout, )
[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s

View file

@ -1,39 +0,0 @@
[loggers]
keys=root, gunicorn.error, gunicorn.access, application.profiler
[handlers]
keys=console
[formatters]
keys=generic
[logger_application.profiler]
level=DEBUG
handlers=console
propagate=0
qualname=application.profiler
[logger_root]
level=DEBUG
handlers=console
[logger_gunicorn.error]
level=INFO
handlers=console
propagate=1
qualname=gunicorn.error
[logger_gunicorn.access]
level=INFO
handlers=console
propagate=0
qualname=gunicorn.access
[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )
[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s
class=logging.Formatter

View file

@ -1,41 +0,0 @@
/mnt/logs/nginx.access.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
kill -USR1 `cat /mnt/logs/nginx.pid`
endscript
}
/mnt/logs/nginx.error.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
kill -USR1 `cat /mnt/logs/nginx.pid`
endscript
}
/mnt/logs/application.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 ubuntu ubuntu
postrotate
kill -USR1 `cat /mnt/logs/gunicorn.pid`
endscript
}

View file

@ -1,5 +1,5 @@
pid /tmp/nginx.pid;
error_log /mnt/logs/nginx.error.log;
error_log /var/log/nginx/nginx.error.log;
events {
worker_connections 1024;

View file

@ -1,7 +1,10 @@
client_max_body_size 8G;
client_body_temp_path /mnt/logs/client_body 1 2;
client_body_temp_path /var/log/nginx/client_body 1 2;
server_name _;
set_real_ip_from 172.17.0.0/16;
real_ip_header X-Forwarded-For;
keepalive_timeout 5;
if ($args ~ "_escaped_fragment_") {
@ -20,5 +23,5 @@ location / {
proxy_pass http://app_server;
proxy_read_timeout 2000;
proxy_temp_path /mnt/logs/proxy_temp 1 2;
proxy_temp_path /var/log/nginx/proxy_temp 1 2;
}

View file

@ -1,7 +1,15 @@
from raven.contrib.flask import Sentry as FlaskSentry
class FakeSentryClient(object):
def captureException(self, *args, **kwargs):
pass
def user_context(self, *args, **kwargs):
pass
class FakeSentry(object):
pass
def __init__(self):
self.client = FakeSentryClient()
class Sentry(object):
def __init__(self, app=None):

View file

@ -33,16 +33,7 @@ class DiffsWorker(Worker):
return True
parser = argparse.ArgumentParser(description='Worker daemon to compute diffs')
parser.add_argument('--log', help='Specify the log file for the worker as a daemon.')
args = parser.parse_args()
if args.log is not None:
handler = logging.FileHandler(args.log)
else:
handler = logging.StreamHandler()
handler.setFormatter(formatter)
root_logger.addHandler(handler)
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
worker = DiffsWorker(image_diff_queue)
worker.start()
worker.start()

View file

@ -21,7 +21,7 @@ from collections import defaultdict
from data.queue import dockerfile_build_queue
from data import model
from workers.worker import Worker, WorkerUnhealthyException, JobException
from app import app, userfiles as user_files, build_logs
from app import userfiles as user_files, build_logs, sentry
from util.safetar import safe_extractall
from util.dockerfileparse import parse_dockerfile, ParsedDockerfile, serialize_dockerfile
@ -141,6 +141,7 @@ class DockerfileBuildContext(object):
self.__cleanup_images()
self.__prune_cache()
except APIError:
sentry.client.captureException()
message = 'Docker installation is no longer healthy.'
logger.exception(message)
raise WorkerUnhealthyException(message)
@ -450,6 +451,9 @@ class DockerfileBuildWorker(Worker):
def process_queue_item(self, job_details):
self._timeout.clear()
# Make sure we have more information for debugging problems
sentry.client.user_context(job_details)
repository_build = model.get_repository_build(job_details['namespace'],
job_details['repository'],
job_details['build_uuid'])
@ -540,6 +544,7 @@ class DockerfileBuildWorker(Worker):
raise exc
except Exception as exc:
sentry.client.captureException()
log_appender('error', build_logs.PHASE)
logger.exception('Exception when processing request.')
repository_build.phase = 'error'
@ -550,27 +555,12 @@ class DockerfileBuildWorker(Worker):
desc = 'Worker daemon to monitor dockerfile build'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-D', action='store_true', default=False,
help='Run the worker in daemon mode.')
parser.add_argument('--log', default='dockerfilebuild.log',
help='Specify the log file for the worker as a daemon.')
parser.add_argument('--cachegb', default=20, type=float,
help='Maximum cache size in gigabytes.')
args = parser.parse_args()
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
worker = DockerfileBuildWorker(args.cachegb, dockerfile_build_queue,
reservation_seconds=RESERVATION_TIME)
if args.D:
handler = logging.FileHandler(args.log)
handler.setFormatter(formatter)
root_logger.addHandler(handler)
with daemon.DaemonContext(files_preserve=[handler.stream]):
worker.start()
else:
handler = logging.StreamHandler()
handler.setFormatter(formatter)
root_logger.addHandler(handler)
worker.start(start_status_server_port=8000)
worker.start(start_status_server_port=8000)

View file

@ -34,17 +34,7 @@ class WebhookWorker(Worker):
return True
parser = argparse.ArgumentParser(description='Worker daemon to send webhooks')
parser.add_argument('--log', help='Specify the log file for the worker as a daemon.')
args = parser.parse_args()
if args.log is not None:
handler = logging.FileHandler(args.log)
else:
handler = logging.StreamHandler()
handler.setFormatter(formatter)
root_logger.addHandler(handler)
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
worker = WebhookWorker(webhook_queue, poll_period_seconds=15,
reservation_seconds=3600)