Skip to content

Commit

Permalink
support docker
Browse files Browse the repository at this point in the history
  • Loading branch information
boy-hack committed Aug 8, 2018
1 parent 406186f commit 5d95518
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM alpine:latest
MAINTAINER w8ay.w8ay@qq.com
# install requirements
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

RUN set -x \
&& apk update \
&& apk add bash \
&& apk add python3 \
&& apk add redis \
&& apk add mongodb \
&& apk add mongodb-tools

# install w11scan
RUN mkdir -p /opt/w11scan
COPY . /opt/w11scan

RUN set -x \
&& pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r /opt/w11scan/requirements.txt

RUN set -x \
&& chmod a+x /opt/w11scan/dockerconf/start.sh

WORKDIR /opt/w11scan

ENTRYPOINT ["/opt/w11scan/dockerconf/start.sh"]

EXPOSE 8000

CMD ["/usr/bin/tail", "-f", "/dev/null"]
33 changes: 6 additions & 27 deletions app/Conn.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@

from pymongo import MongoClient
from config import mongodb_host,mongodb_password,mongodb_port,mongodb_username
import json

# db connect
class MongDB(object):
def __init__(self,host = 'localhost',port = 27017,database = 'w11scan',username = '',password = ''):
self.host = host
self.port = port
def __init__(self,database = 'w11scan'):
self.host = mongodb_host
self.port = mongodb_port
self.database = database
self.conn = MongoClient(self.host,self.port)
self.coll = self.conn[self.database]
# self.coll.authenticate(username,password)

# with open("cms.json") as f:
# data = json.load(f)
#
# db = MongDB()
# db.coll["cmsdna"].insert_many(data)
#
# # print(db.coll.collection_names())
#
# collections = db.coll.collection_names()
# for k,v in data.items():
# # db.coll[k].insert_many(v)
# for i in v:
# i["hit"] = 0
# if i["option"] == "regx":
# i["option"] = "keyword"
# db.coll[k].insert_many(v)
# print(v)

# for i in collections:
# cursor = db.coll[i].find()
# for f in cursor:
# print(f)
if mongodb_username != "" and mongodb_password != "":
self.coll.authenticate(mongodb_username,mongodb_password)
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config(object):
redis_password = ""

mongodb_host = 'localhost'
mongodb_port = 27017
mongodb_port = 65521
mongodb_username = ''
mongodb_password = ''

Expand All @@ -23,7 +23,7 @@ class Config(object):
else:
BROKER_URL = "redis://{}@{}:{}/1".format(redis_password,redis_host,redis_port)

CELERY_RESULT_BACKEND = "mongodb://localhost:27017/w11scan_celery"
CELERY_RESULT_BACKEND = "mongodb://localhost:65521/w11scan_celery"
# mongodb://user:password@localhost:27017/w11scan_celery

if mongodb_username == "" and mongodb_password == "":
Expand Down
3 changes: 3 additions & 0 deletions dockerconf/mongoauth
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use w11scan_config
db.result.createIndex({"$**":"text"})
exit
20 changes: 20 additions & 0 deletions dockerconf/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

XUNFENG_BASE=/opt/w11scan
cd $XUNFENG_BASE
XUNFENG_LOG=/var/log/xunfeng
MONGODB_PATH=/data/db

[ ! -d $XUNFENG_LOG ] && mkdir -p ${XUNFENG_LOG}
[ ! -d $MONGODB_PATH ] && mkdir -p ${MONGODB_PATH}

nohup redis-server > ${XUNFENG_LOG}/redis.log &
nohup mongod --bind_ip 127.0.0.1 --port 65521 --dbpath=${MONGODB_PATH}> ${XUNFENG_LOG}/db.log &
sleep 3s
mongorestore -h 127.0.0.1 --port 65521 -d w11scan ${XUNFENG_BASE}/backup/w11scan
mongo 127.0.0.1:65521 < ${XUNFENG_BASE}/dockerconf/mongoauth
python3 ${XUNFENG_BASE}/manage.py migrate
nohup python3 ${XUNFENG_BASE}/manage.py runserver 0.0.0.0:8000 > ${XUNFENG_LOG}/web.log &
nohup celery -A whatcms worker -l info > ${XUNFENG_LOG}/celery.log &
nohup celery -A whatcms worker -l info > ${XUNFENG_LOG}/celery2.log &
/usr/bin/tail -f /dev/null

0 comments on commit 5d95518

Please sign in to comment.