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

Develop #2

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7dad391
Backend upgrade;
KingSkyLi Nov 21, 2024
caeae38
run black .;
KingSkyLi Nov 21, 2024
6b34e49
run isort;
KingSkyLi Nov 21, 2024
aaf2cec
fixed;
KingSkyLi Nov 21, 2024
acfe5a6
fixed;
KingSkyLi Nov 21, 2024
ab47b73
fixed;
KingSkyLi Nov 21, 2024
093c146
fixed;
KingSkyLi Nov 21, 2024
f190008
add render graph
KingSkyLi Nov 22, 2024
0ee4138
push
KingSkyLi Nov 22, 2024
b64caa9
add ut;
KingSkyLi Nov 25, 2024
350831d
fixed;
KingSkyLi Nov 25, 2024
cf20ba3
update render graph
KingSkyLi Nov 26, 2024
4383457
add web container;
KingSkyLi Nov 26, 2024
c364fbc
change port
KingSkyLi Nov 26, 2024
588e737
update config
KingSkyLi Nov 27, 2024
5d2a2c4
add UT;
KingSkyLi Nov 27, 2024
01423e3
add system db config;
KingSkyLi Nov 28, 2024
4eddff8
update web
KingSkyLi Nov 28, 2024
f73b63a
update
KingSkyLi Nov 30, 2024
1b30959
fixed;
KingSkyLi Dec 2, 2024
5221eaf
fixed;
KingSkyLi Dec 2, 2024
daaaf5f
update;
KingSkyLi Dec 2, 2024
8140ce2
update;
KingSkyLi Dec 3, 2024
35dc87a
chage web dir
KingSkyLi Dec 3, 2024
1380828
Merge branch 'master' into develop
KingSkyLi Dec 3, 2024
7f845f6
add homePage_new.ts
KingSkyLi Dec 3, 2024
f657bdd
change homepage
KingSkyLi Dec 3, 2024
dd69e63
update web
KingSkyLi Dec 3, 2024
e5e4ade
fixed;
KingSkyLi Dec 3, 2024
bed4d0a
fixed;
KingSkyLi Dec 10, 2024
c4b48e5
fixed
KingSkyLi Dec 10, 2024
5823559
Merge branch 'master' into develop
KingSkyLi Dec 11, 2024
307cc15
Update webpack.yml
KingSkyLi Dec 11, 2024
3f7741b
'useTranslation' is declared but its value is never read.
KingSkyLi Dec 11, 2024
79361be
Merge branch 'develop' of github.com:KingSkyLi/OSGraph into develop
KingSkyLi Dec 11, 2024
d5c1083
update webpack.yml
KingSkyLi Dec 11, 2024
3d3bcfa
update webpack
KingSkyLi Dec 11, 2024
df05896
upadte;
KingSkyLi Dec 11, 2024
8b0f475
update;
KingSkyLi Dec 11, 2024
e099fe8
fixed;
KingSkyLi Dec 11, 2024
42cd344
update
KingSkyLi Dec 12, 2024
f64f81e
update webpack.yml
KingSkyLi Dec 12, 2024
a1db116
fixed;
KingSkyLi Dec 12, 2024
1cb5b93
update
KingSkyLi Dec 12, 2024
ea7ee90
fixed
KingSkyLi Dec 12, 2024
4f5f3b9
fixed;
KingSkyLi Dec 12, 2024
0c21043
uodate
KingSkyLi Dec 12, 2024
839548e
fixed;
KingSkyLi Dec 12, 2024
fd0663b
set timeout
KingSkyLi Dec 12, 2024
ef0ed9f
reset webpack.yml
KingSkyLi Dec 12, 2024
caaf560
add timeout 300
KingSkyLi Dec 12, 2024
c2fff92
add test ssh
KingSkyLi Dec 12, 2024
875a481
test ssh
KingSkyLi Dec 12, 2024
c598b0b
Merge branch 'master' into develop
KingSkyLi Dec 12, 2024
249f99e
test ssh
KingSkyLi Dec 12, 2024
97b88c5
Merge branch 'develop' of github.com:KingSkyLi/OSGraph into develop
KingSkyLi Dec 12, 2024
380272a
test ssh
KingSkyLi Dec 12, 2024
edc04d9
test
KingSkyLi Dec 12, 2024
098543a
test
KingSkyLi Dec 12, 2024
bd7d869
test scp and ssh
KingSkyLi Dec 12, 2024
3c828e3
add source env
KingSkyLi Dec 12, 2024
592e818
set web build env;
KingSkyLi Dec 13, 2024
89d357e
set web build env;
KingSkyLi Dec 13, 2024
e4e2620
set web build env;
KingSkyLi Dec 13, 2024
ab35c8d
add oneclip
KingSkyLi Dec 16, 2024
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
32 changes: 28 additions & 4 deletions .github/workflows/webpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,40 @@ jobs:

# Step 3: 构建前端代码
- name: Build frontend
working-directory: ./osgraph-web # 假设前端代码在项目的 frontend 目录
working-directory: ./osgraph-web
run: |
pnpm install
pnpm run build
pnpm run build:stage

# Step 4: 上传前端构建产物到服务器
# Step 4: 配置 SSH 密钥
- name: Configure SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

# Step 5: 上传前端构建产物到服务器
- name: Deploy frontend
env:
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH_FRONTEND: ${{ secrets.DEPLOY_PATH_FRONTEND }}
run: |
scp -o StrictHostKeyChecking=no -r ./osgraph-web/build/* $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH_FRONTEND
timeout 300 scp -o StrictHostKeyChecking=no -r ./osgraph-web/dist/* $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH_FRONTEND

# Step 6: 更新后端代码并重启服务
- name: Deploy backend
env:
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH_BACKEND: ${{ secrets.DEPLOY_PATH_BACKEND }}
run: |
timeout 300 scp -o StrictHostKeyChecking=no -r ./osgraph-service-py/* $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH_BACKEND
ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_SERVER << EOF
set -e
source ~/.bashrc
source /root/osgraph/myenv/bin/activate
cd $DEPLOY_PATH_BACKEND
poetry install
lsof -ti:8000 | xargs kill -9 || true
nohup poetry run gunicorn -w 4 -b 0.0.0.0:8000 run:app > gunicorn.log 2>&1 &
EOF
34 changes: 34 additions & 0 deletions osgraph-service-py/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# es config
ES_HOST=127.0.0.1
ES_PORT=9200
ES_USERNAME=elastic
ES_PASSWORD=es

# tugraph config
TUGRAPHDB_HOST=127.0.0.1
TUGRAPHDB_PORT=7687
TUGRAPHDB_USER=admin
TUGRAPHDB_PASSWORD=73@TuGraph
TUGRAPHDB_OSGRAPH_GITHUB_GRAPH_NAME=default

# system config
TUGRAPHDB_SYSTEM_HOST=127.0.0.1
TUGRAPHDB_SYSTEM_PORT=7687
TUGRAPHDB_SYSTEM_USER=admin
TUGRAPHDB_SYSTEM_PASSWORD=73@TuGraph
TUGRAPHDB_OSGRAPH_SYSTEM_GRAPH_NAME=system

# flask config
FLASK_ENV=production
FLASK_PORT=8000


# OpenAI key
SUMMARY_GRAPH=off # on | off
OPENAI_KEY=
BASEURL=
MODEL=




3 changes: 3 additions & 0 deletions osgraph-service-py/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
exclude = .venv,__pycache__,build,dist,static
4 changes: 3 additions & 1 deletion osgraph-service-py/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ __pycache__/
# IDE files
.vscode/
.idea/
.DS_Store
.DS_Store
.certs/

Empty file added osgraph-service-py/README.md
Empty file.
123 changes: 123 additions & 0 deletions osgraph-service-py/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# app/__init__.py
import importlib
import os
from typing import Type, Union

from dotenv import load_dotenv
from flask import Flask, jsonify, send_from_directory

from app.dal.graph.tugraph import GraphClient, GraphLabel, LabelProps
from app.models.system_graph import GraphService
from app.services import register_all_services

from .utils.custom_exceptions import InvalidUsage
from .utils.logger import setup_logger

load_dotenv()


def create_app(
config_class: Union[str, Type[object]] = "config.ProductionConfig"
) -> Flask:
static_folder_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../web")
app = Flask(__name__,static_folder=static_folder_path)
@app.route('/')
def serve_index():
return send_from_directory(app.static_folder, 'index.html')
@app.route('/<path:filename>')
def serve_static(filename):
try:
return send_from_directory(app.static_folder, filename)
except:
return send_from_directory(app.static_folder, 'index.html')

app.config.from_object(config_class)
setup_logger(app)
register_blueprints(app)
with app.app_context():
initialize_system_graph(app)
register_all_services()
register_error_handlers(app)
return app


def register_blueprints(app: Flask, blueprint_folder: str = "routes") -> None:
current_dir = os.path.dirname(os.path.abspath(__file__))
blueprints_path = os.path.join(current_dir, blueprint_folder)
for filename in os.listdir(blueprints_path):
if filename.endswith(".py") and filename != "__init__.py":
module_name = filename[:-3]
module_path = f"app.{blueprint_folder}.{module_name}"
module = importlib.import_module(module_path)
for attr_name in dir(module):
if attr_name.endswith("_bp"):
blueprint = getattr(module, attr_name)
if hasattr(blueprint, "name") and hasattr(blueprint, "url_prefix"):
app.register_blueprint(blueprint)


def register_error_handlers(app: Flask) -> None:
@app.errorhandler(InvalidUsage)
def handle_invalid_usage(error):
response = jsonify(error.to_dict())
response.status_code = error.status_code
app.logger.error(f"InvalidUsage: {error.message}")
return response

@app.errorhandler(404)
def not_found(error):
app.logger.warning("404 Not Found")
return jsonify({"message": "Resource not found"}), 404

@app.errorhandler(500)
def internal_error(error):
app.logger.error("Internal Server Error")
return jsonify({"message": "Internal server error"}), 500


def initialize_system_graph(app: Flask):
TUGRAPHDB_OSGRAPH_SYSTEM_GRAPH_NAME = os.getenv("TUGRAPHDB_OSGRAPH_SYSTEM_GRAPH_NAME")
TUGRAPHDB_SYSTEM_HOST = os.getenv("TUGRAPHDB_SYSTEM_HOST")
TUGRAPHDB_SYSTEM_PORT = os.getenv("TUGRAPHDB_SYSTEM_PORT")
TUGRAPHDB_SYSTEM_USER = os.getenv("TUGRAPHDB_SYSTEM_USER")
TUGRAPHDB_SYSTEM_PASSWORD = os.getenv("TUGRAPHDB_SYSTEM_PASSWORD")

client = GraphClient(
host=TUGRAPHDB_SYSTEM_HOST,
port=TUGRAPHDB_SYSTEM_PORT,
user=TUGRAPHDB_SYSTEM_USER,
password=TUGRAPHDB_SYSTEM_PASSWORD,
graph_name=TUGRAPHDB_OSGRAPH_SYSTEM_GRAPH_NAME
)

try:
system_graph = client.get_graph()
if system_graph:
app.logger.info("system_graph 图已存在")
else:
client.create_graph()
app.logger.info("system_graph 图已创建")
graph_service = client.get_label("vertex", "graph_service")
if graph_service:
app.logger.info("graph_service Label 已存在")
else:
label = GraphLabel(
label=GraphService.label,
primary=GraphService.primary,
type=GraphService.type,
properties=[
LabelProps(name=key, type="string", optional=True)
for key in (
GraphService.props.keys()
if isinstance(GraphService.props, dict)
else dir(GraphService.props)
)
if not key.startswith("_")
],
)
client.create_label(label)
app.logger.info("graph_service Label 已创建")
except Exception as e:
app.logger.error(f"初始化 system_graph 失败: {str(e)}")
finally:
client.close()
Empty file.
Empty file.
Loading
Loading