docker-compose is ok

This commit is contained in:
pycook 2023-07-11 18:12:22 +08:00
parent 109d4f1a2e
commit 6c56757a9d
11 changed files with 94 additions and 13741 deletions

View File

@ -1,5 +1,5 @@
# ================================= UI ================================
FROM node:alpine AS builder
FROM node:16.0.0-alpine AS builder
LABEL description="cmdb-ui"
@ -18,20 +18,20 @@ COPY --from=builder /data/apps/cmdb-ui/dist /etc/nginx/html/
# ================================= API ================================
FROM python:3.7-alpine AS cmdb-api
FROM python:3.8-alpine AS cmdb-api
LABEL description="Python3.7,cmdb"
LABEL description="Python3.8,cmdb"
COPY cmdb-api /data/apps/cmdb
WORKDIR /data/apps/cmdb
RUN apk add --no-cache tzdata gcc musl-dev libffi-dev openldap-dev
RUN apk add --no-cache tzdata gcc musl-dev libffi-dev openldap-dev python3-dev jpeg-dev zlib-dev build-base
ENV TZ=Asia/Shanghai
RUN pip install --no-cache-dir -r requirements.txt \
&& cp ./settings.py.example settings.py \
&& cp ./settings.example.py settings.py \
&& sed -i "s#{user}:{password}@127.0.0.1:3306/{db}#cmdb:123456@mysql:3306/cmdb#g" settings.py \
&& sed -i "s#redis://127.0.0.1#redis://redis#g" settings.py \
&& sed -i 's#CACHE_REDIS_HOST = "127.0.0.1"#CACHE_REDIS_HOST = "redis"#g' settings.py

View File

@ -17,7 +17,7 @@
系统介绍
-------------
### 整体架构
<img src=docs/view.png width=700 height=450 />
<img src=docs/view.png />
### 相关文档
- <a href="https://zhuanlan.zhihu.com/p/98453732" target="_blank">设计文档</a>

View File

@ -41,6 +41,15 @@ from api.models.cmdb import PreferenceRelationView
def cmdb_init_cache():
db.session.remove()
ci_relations = CIRelation.get_by(to_dict=False)
relations = dict()
for cr in ci_relations:
relations.setdefault(cr.first_ci_id, {}).update({cr.second_ci_id: cr.second_ci.type_id})
for i in relations:
relations[i] = json.dumps(relations[i])
if relations:
rd.create_or_update(relations, REDIS_PREFIX_CI_RELATION)
if current_app.config.get("USE_ES"):
from api.extensions import es
from api.models.cmdb import Attribute
@ -83,15 +92,6 @@ def cmdb_init_cache():
else:
rd.create_or_update({ci.id: json.dumps(ci_dict)}, REDIS_PREFIX_CI)
ci_relations = CIRelation.get_by(to_dict=False)
relations = dict()
for cr in ci_relations:
relations.setdefault(cr.first_ci_id, {}).update({cr.second_ci_id: cr.second_ci.type_id})
for i in relations:
relations[i] = json.dumps(relations[i])
if relations:
rd.create_or_update(relations, REDIS_PREFIX_CI_RELATION)
db.session.remove()

View File

@ -95,7 +95,7 @@ class Search(object):
for _v in new_v:
ci_type = CITypeCache.get(_v)
if len(new_v) == 1 and not self.sort and ci_type.default_order_attr:
if len(new_v) == 1 and not self.sort and ci_type and ci_type.default_order_attr:
self.sort = ci_type.default_order_attr
if ci_type is not None:

View File

@ -41,7 +41,7 @@ class ACLManager(object):
def get_all_roles(self):
numfound, roles = RoleCRUD.search(
None, self.app_name, 1, 999999, True, True, False)
return roles
return [i.to_dict() for i in roles]
def remove_user_from_role(self, user_rid, payload):
app_id = self.app_name

View File

@ -444,7 +444,7 @@ class AutoDiscoveryCIType(Model):
__tablename__ = "c_ad_ci_types"
type_id = db.Column(db.Integer, db.ForeignKey('c_ci_types.id'))
adr_id = db.Column(db.Integer, db.ForeignKey('c_ad_ci_types.id'))
adr_id = db.Column(db.Integer, db.ForeignKey('c_ad_rules.id'))
attributes = db.Column(db.JSON) # {ad_key: cmdb_key}

View File

@ -1,3 +1,5 @@
# -*- coding:utf-8 -*-
from api.extensions import db
from api.lib.database import Model, TimestampMixin, SoftDeleteMixin, CRUDMixin

View File

@ -58,7 +58,12 @@ DEFAULT_MAIL_SENDER = ''
CELERY_RESULT_BACKEND = "redis://127.0.0.1:6379/2"
BROKER_URL = 'redis://127.0.0.1:6379/2'
BROKER_VHOST = '/'
ONCE = {
'backend': 'celery_once.backends.Redis',
'settings': {
'url': BROKER_URL,
}
}
# # SSO
CAS_SERVER = "http://sso.xxx.com"

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ version: '3.5'
services:
cmdb-db:
image: registry.cn-qingdao.aliyuncs.com/pycook/cmdb-db:1.0
image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-db:3.0
container_name: cmdb-db
environment:
TZ: Asia/Shanghai
@ -12,81 +12,55 @@ services:
MYSQL_PASSWORD: '123456'
volumes:
- db-data:/var/lib/mysql
- ./docs/cmdb_en.sql:/docker-entrypoint-initdb.d/cmdb.sql
- ./docs/mysqld.cnf:/etc/mysql/conf.d/mysqld.cnf
- ./docs/cmdb.sql:/docker-entrypoint-initdb.d/cmdb.sql
networks:
new:
aliases:
- mysql
ports:
- '23306:3306'
cmdb-cache:
image: registry.cn-qingdao.aliyuncs.com/pycook/cmdb-cache:1.0
image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-cache:3.0
container_name: cmdb-cache
networks:
new:
aliases:
- redis
cmdb-search:
image: registry.cn-qingdao.aliyuncs.com/pycook/cmdb-search:1.2
# build:
# context: .
# target: cmdb-search
container_name: cmdb-search
environment:
- discovery.type=single-node
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
new:
aliases:
- cmdb-search
cmdb-api:
image: registry.cn-qingdao.aliyuncs.com/pycook/cmdb-api:2.2
image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-api:3.0
# build:
# context: .
# target: cmdb-api
container_name: cmdb-api
environment:
TZ: Asia/Shanghai
WAIT_HOSTS: cmdb-db:3306, cmdb-cache:6379, cmdb-search:9200
WAIT_HOSTS: cmdb-db:3306, cmdb-cache:6379
command:
- /bin/sh
- -c
- |
sed -i "s#USE_ES = False#USE_ES = True#g" settings.py
sed -i "s#USE_ACL = False#USE_ACL = True#g" settings.py
sed -i "s#ES_HOST = '127.0.0.1'#ES_HOST = 'cmdb-search'#g" settings.py
/wait
sleep 5
gunicorn --workers=3 autoapp:app -b 0.0.0.0:5000 -D
flask init-cache
flask init-acl
flask cmdb-init-cache
flask cmdb-init-acl
celery worker -A celery_worker.celery -E -Q cmdb_async --concurrency=1
celery worker -A celery_worker.celery -E -Q one_cmdb_async --concurrency=2 -D
celery worker -A celery_worker.celery -E -Q acl_async --concurrency=2
depends_on:
- cmdb-db
- cmdb-cache
- cmdb-search
networks:
new:
aliases:
- cmdb-api
cmdb-ui:
image: registry.cn-qingdao.aliyuncs.com/pycook/cmdb-ui:2.2
image: registry.cn-hangzhou.aliyuncs.com/veops/cmdb-ui:3.0
# build:
# context: .
# target: cmdb-ui
@ -112,7 +86,6 @@ services:
volumes:
db-data:
esdata:
networks:
new:

55
docs/mysqld.cnf Normal file
View File

@ -0,0 +1,55 @@
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
character-set-server = utf8
collation-server = utf8_unicode_ci
skip-character-set-client-handshake
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
default-storage-engine=INNODB
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-external-locking
key_buffer_size=16M
max_allowed_packet=4M
table_open_cache=64
sort_buffer_size=512K
net_buffer_length=8K
read_buffer_size=256K
read_rnd_buffer_size=512K
skip-name-resolve
max_connections=1000
slow_query_log = ON
slow_query_log_file = /var/log/mysql_slow.log
long_query_time = 1
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks