Browse Source

Merge pull request #109 from open-falcon/dockerv021

run falcon dashboard in docker container
laiwei 6 years ago
parent
commit
033092dbeb
4 changed files with 46 additions and 32 deletions
  1. 21 11
      Dockerfile
  2. 1 20
      README.md
  3. 20 0
      control
  4. 4 1
      wsgi.py

+ 21 - 11
Dockerfile

@@ -1,15 +1,25 @@
-FROM centos:7.3.1611
+FROM python:2.7-alpine3.7
+USER root
+ENV prefix=/open-falcon
+ENV workdir=$prefix/dashboard
 
-RUN yum clean all && yum install -y epel-release && yum -y update && \
-yum install -y git python-virtualenv python-devel openldap-devel mysql-devel && \
-yum groupinstall -y "Development tools"
+RUN apk add --no-cache \
+    ca-certificates bash git g++ perl make \
+    py-mysqldb \
+    py-pyldap
 
-RUN export HOME=/home/work/ && mkdir -p $HOME/open-falcon/dashboard && cd $HOME/open-falcon/dashboard
-WORKDIR /home/work/open-falcon/dashboard
-ADD ./ ./
-RUN virtualenv ./env && ./env/bin/pip install -r pip_requirements.txt -i http://pypi.douban.com/simple
+RUN mkdir -p $prefix
 
-ADD ./entrypoint.sh /entrypoint.sh
-RUN chmod +x /entrypoint.sh
+ENV PYTHONPATH "${PYTHONPATH}:/usr/lib/python2.7/site-packages/"
+WORKDIR $workdir
+ADD ./ ./
+RUN pip install \
+    Flask==0.10.1 \
+    Flask-Babel==0.9 \
+    Jinja2==2.7.2 \
+    Werkzeug==0.9.4 \
+    gunicorn==19.9.0 \
+    python-dateutil==2.2 \
+    requests==2.3.0
 
-ENTRYPOINT ["/entrypoint.sh"]
+ENTRYPOINT ["/bin/sh", "-c"]

+ 1 - 20
README.md

@@ -21,26 +21,7 @@ Open-Falcon natively support zh_CN and currently partially support English. Any
 
 
 ## Run in docker
-```
-# make the image,run commands under dir of dashboard:
-docker build -t falcon-dashboard:v1.0 .
-
-# start the container
-docker run -itd --name aaa --net host \
-	-e API_ADDR=http://127.0.0.1:8080/api/v1 \
-	-e PORTAL_DB_HOST=127.0.0.1 \
-	-e PORTAL_DB_PORT=3306 \
-	-e PORTAL_DB_USER=root \
-	-e PORTAL_DB_PASS=123456 \
-	-e PORTAL_DB_NAME=falcon_portal \
-	-e ALARM_DB_PASS=123456 \
-	-e ALARM_DB_HOST=127.0.0.1 \
-	-e ALARM_DB_PORT=3306 \
-	-e ALARM_DB_USER=root \
-	-e ALARM_DB_PASS=123456 \
-	-e ALARM_DB_NAME=alarms \
-	falcon-dashboard:v1.0
-```
+- [run dashboard in docker container](https://github.com/open-falcon/falcon-plus/blob/master/docker/README.md)
 
 ## Clone & Prepare
 ```

+ 20 - 0
control

@@ -39,6 +39,24 @@ function start() {
     cat $pidfile
 }
 
+function startfg() {
+    source env/bin/activate
+    hash gunicorn 2>&- || { echo >&2 "I require gunicorn but it's not installed.  Aborting."; exit 1; }
+
+    check_pid
+    running=$?
+    if [ $running -gt 0 ];then
+        echo -n "$app now is running already, pid="
+        cat $pidfile
+        return 1
+    fi
+
+    gunicorn -c gunicorn.conf wsgi:app -t 6000 --pid $pidfile --error-logfile $logfile --log-level info
+    sleep 1
+    echo -n "$app started..., pid="
+    cat $pidfile
+}
+
 function stop() {
     pid=`cat $pidfile`
     kill $pid
@@ -96,6 +114,8 @@ elif [ "$1" == "kill9" ];then
     kill9
 elif [ "$1" == "start" ];then
     start
+elif [ "$1" == "startfg" ];then
+    startfg
 elif [ "$1" == "restart" ];then
     restart
 elif [ "$1" == "status" ];then

+ 4 - 1
wsgi.py

@@ -17,7 +17,10 @@
 import os
 base_dir = os.path.dirname(os.path.abspath(__file__))
 activate_this = '%s/env/bin/activate_this.py' % base_dir
-execfile(activate_this, dict(__file__=activate_this))
+try:
+    execfile(activate_this, dict(__file__=activate_this))
+except:
+    print "running without local python env"
 
 import sys
 sys.path.insert(0, base_dir)