Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加Dockerfile,使用docker-compose部署;使用configparser统一管理配置项;修正部分数据库models错误 #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.6-slim-stretch

WORKDIR /app

COPY sources.list /etc/apt/sources.list
COPY requirements.txt ./
RUN apt update \
&& apt install -y default-libmysqlclient-dev gcc python-dev libsasl2-dev git sshpass mariadb-client \
&& pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple \
&& rm -rf /var/lib/apt/lists/*

COPY . .
RUN cp conf/celeryd.conf /etc/default/celeryd \
&& cp conf/celeryd.server /etc/init.d/celeryd \
&& cp conf/celerybeat.server /etc/init.d/celerybeat \
&& cp conf/get_mem.py /usr/local/lib/python3.6/site-packages/ansible \
&& chmod +x /etc/init.d/celeryd /etc/init.d/celerybeat /usr/local/lib/python3.6/site-packages/ansible/get_mem.py /app/docker-entrypoint.sh

EXPOSE 8000

ENTRYPOINT [ "/app/docker-entrypoint.sh" ]
Binary file removed Ops/__pycache__/__init__.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/index.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/routing.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/settings.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/urls.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/views.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/wsgi.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed Ops/__pycache__/wsgi.cpython-36.pyc
Binary file not shown.
9 changes: 8 additions & 1 deletion Ops/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
import os
from celery import Celery
from kombu import Queue, Exchange
try:
import ConfigParser as conf
except ImportError as e:
import configparser as conf

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Ops.settings')
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
config = conf.ConfigParser()
config.read(os.path.join(BASE_DIR, 'conf/ops.ini'))

app = Celery('Ops', broker='redis://127.0.0.1:6379/0')
app = Celery('Ops', broker='redis://{host}:{port}/{db}'.format(host=config.get('redis', 'host'), port=config.get('redis', 'port'), db=config.get('redis', 'celery_db')))

app.conf.task_queues = (
Queue('default', Exchange('default', type='direct'), routing_key='default'),
Expand Down
71 changes: 41 additions & 30 deletions Ops/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@

import os
import sys
try:
import ConfigParser as conf
except ImportError as e:
import configparser as conf

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
config = conf.ConfigParser()
config.read(os.path.join(BASE_DIR, 'conf/ops.ini'))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
Expand All @@ -23,7 +29,7 @@
SECRET_KEY = 'e02$n$tpsi&rvjj7=5y!pi7b2$ku-+@5+6%#va7=oypuglxkn#'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = config.get('global', 'debug')

ALLOWED_HOSTS = ['*']

Expand All @@ -35,7 +41,7 @@
# This example app uses the Redis channel layer implementation channels_redis
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [('127.0.0.1', 6379)],
"hosts": [(config.get('redis', 'host'), config.get('redis', 'port'))],
},
},
}
Expand All @@ -57,18 +63,18 @@
}

# 执行ansible命令使用的redis信息
REDIS_HOST = '127.0.0.1'
REDIS_PORT = 6379
REDIS_DB = 2
REDIS_PASSWORD = None
REDIS_HOST = config.get('redis', 'host')
REDIS_PORT = config.get('redis', 'port')
REDIS_DB = config.get('redis', 'ansible_db')
REDIS_PASSWORD = config.get('redis', 'password')

# mongodb配置信息
MONGODB_HOST = '10.1.7.198'
MONGODB_PORT = 27017
MONGODB_USER = 'admin'
MONGODB_PASS = '123456'
RECORD_DB = 'records'
RECORD_COLL = 'ops'
MONGODB_HOST = config.get('mongodb', 'host')
MONGODB_PORT = config.getint('mongodb', 'port')
MONGODB_USER = config.get('mongodb', 'user')
MONGODB_PASS = config.get('mongodb', 'password')
RECORD_DB = config.get('mongodb', 'record_db')
RECORD_COLL = config.get('mongodb', 'record_coll')

# Application definition
INSTALLED_APPS = [
Expand Down Expand Up @@ -169,10 +175,15 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ops',
'USER': 'ops',
'PASSWORD': '123456',
'HOST': '127.0.0.1'
'NAME': config.get('db', 'name'),
'USER': config.get('db', 'user'),
'PASSWORD': config.get('db', 'password'),
'HOST': config.get('db', 'host'),
'PORT': config.get('db', 'port'),
'OPTIONS':{
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
'charset': 'utf8mb4',
},
}
}

Expand Down Expand Up @@ -226,26 +237,26 @@

# zabbix配置
ZABBIX_INFO = {
'api_url': 'http://127.0.0.1/zabbix/api_jsonrpc.php',
'graph_url': 'http://127.0.0.1/zabbix/chart2.php',
'login_url': 'http://127.0.0.1/zabbix/index.php',
'username': 'admin',
'password': '123456'
'api_url': 'http://{host}:{port}/{api_url}'.format(host=config.get('zabbix', 'host'), port=config.get('zabbix', 'port'), api_url=config.get('zabbix', 'api_url')),
'graph_url': 'http://{host}:{port}/{graph_url}'.format(host=config.get('zabbix', 'host'), port=config.get('zabbix', 'port'), graph_url=config.get('zabbix', 'graph_url')),
'login_url': 'http://{host}:{port}/{login_url}'.format(host=config.get('zabbix', 'host'), port=config.get('zabbix', 'port'), login_url=config.get('zabbix', 'login_url')),
'username': '{username}'.format(username=config.get('zabbix', 'username')),
'password': '{password}'.format(password=config.get('zabbix', 'password'))
}

# ANSIBLE_ROLE_PATH = os.path.join(MEDIA_ROOT, 'roles')
ANSIBLE_ROLE_PATH = '/usr/share/ansible/roles'
ANSIBLE_ROLE_PATH = config.get('ansible', 'ansible_role_path')

GUACD_HOST = '127.0.0.1'
GUACD_PORT = 4822
GUACD_HOST = config.get('cuacd', 'host')
GUACD_PORT = config.get('cuacd', 'port')

# email配置
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'XXXXXXXXXXXX'
EMAIL_HOST_PASSWORD = 'XXXXXXXXXXX'
EMAIL_HOST = config.get('email', 'smtp_host')
EMAIL_PORT = config.get('email', 'smtp_port')
EMAIL_HOST_USER = config.get('email', 'smtp_user')
EMAIL_HOST_PASSWORD = config.get('email', 'smtp_passwd')
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

# 数据库管理用户,该用户需要有grant option权限,并且只能赋予该用户所拥有的权限
MYSQL_USER = 'cc'
MYSQL_PASS = '123456'
MYSQL_USER = config.get('db', 'admin_user')
MYSQL_PASS = config.get('db', 'admin_password')
Binary file removed api/__pycache__/__init__.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed api/__pycache__/admin.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed api/__pycache__/apps.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed api/__pycache__/models.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed api/__pycache__/serializers.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed api/__pycache__/urls.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed api/__pycache__/views.cpython-36.opt-1.pyc
Binary file not shown.
Empty file removed api/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file removed assets/__pycache__/__init__.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed assets/__pycache__/admin.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed assets/__pycache__/apps.cpython-36.opt-1.pyc
Binary file not shown.
Binary file removed assets/__pycache__/models.cpython-36.opt-1.pyc
Binary file not shown.
Loading