Skip to content

Commit

Permalink
Feat: init project
Browse files Browse the repository at this point in the history
  • Loading branch information
harlee-x committed Mar 26, 2024
1 parent dd5318f commit 3648957
Show file tree
Hide file tree
Showing 84 changed files with 3,642 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ blank_issues_enabled: true
contact_links:
- name: Questions
about: Please use one of the forums for questions or general discussions
url: https://github.com/linktimecloud/template-project/pulls
url: https://github.com/linktimecloud/kdp-catalog-manager/issues
51 changes: 28 additions & 23 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,39 @@ on:
- main
- release-*

env:
PYTHON_VERSION: "3.10"

jobs:
build-docker-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Get the version
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Get image registry
id: get_image_registry
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: $PYTHON_VERSION
# Optional - x64 or x86 architecture, defaults to x64
architecture: 'x64'
- name: Install dependencies
run: |
echo "IMG_REGISTRY=${{ secrets.NX_ALIYUN_REGISTRY }}" >> $GITHUB_OUTPUT
# - name: Docker Login
# uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
# with:
# registry: ${{ secrets.NX_ALIYUN_REGISTRY }}
# username: ${{ secrets.NX_ALIYUN_USERNAME }}
# password: ${{ secrets.NX_ALIYUN_PASSWORD }}

# - name: Build Images
# run: make docker-build-apiserver IMG_REGISTRY=${{ steps.get_image_registry.outputs.IMG_REGISTRY }} VERSION=${{ steps.get_version.outputs.VERSION }}
#
# - name: Push Images
# run: make docker-push-apiserver IMG_REGISTRY=${{ steps.get_image_registry.outputs.IMG_REGISTRY }} VERSION=${{ steps.get_version.outputs.VERSION }}
python -m pip install --upgrade pip
pip install pytest pytest-cov
if [ -f docker/python/requirements.txt ]; then pip install -r docker/python/requirements.txt; fi
- name: Docker Login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.REG_USER }}
password: ${{ secrets.REG_PASSWD }}

- name: Build Images
run: make docker-build IMG_REGISTRY=${{ secrets.DOCKER_REGISTRY }} VERSION=${{ github.ref_name }}

- name: Push Images
run: make docker-build IMG_REGISTRY=${{ secrets.DOCKER_REGISTRY }} VERSION=${{ github.ref_name }}


40 changes: 15 additions & 25 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ on:
permissions:
contents: read

env:
# Common versions
GO_VERSION: "1.21"

jobs:
detect-noop:
permissions:
actions: write # for fkirc/skip-duplicate-actions to skip or stop workflow runs
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
outputs:
noop: ${{ steps.noop.outputs.should_skip }}
steps:
Expand All @@ -36,27 +32,21 @@ jobs:
continue-on-error: true

unit-tests:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs: detect-noop
if: needs.detect-noop.outputs.noop != 'true'

steps:
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code into the Go module directory
uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
submodules: true

- name: Cache Go Dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
with:
path: .work/pkg
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-

# - name: Run Make test
# run: make test
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
if [ -f docker/python/requirements.txt ]; then pip install -r docker/python/requirements.txt; fi
- name: Test with pytest
run: |
pytest --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include makefiles/const.mk
include makefiles/build-image.mk
88 changes: 86 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,86 @@
# template-project
This is the template project for initializing other LTC projects.
# KDP Catalog Manager

## 项目描述

### 项目概述
KDP Catalog Manager是一套大数据应用管理平台。基于应用功能进行分类查看、管理,降低应用管理的复杂度,从而使大数据管理人员更专注于数据的处理

### 核心技术架构
![kdp-catalog-manager](kdp-catalog-manager.png)



### 功能模块描述

#### api
* view
定义 Restful API 并对用户输入参数执行基本验证及结果输出

#### Domain
* service
业务逻辑
* format
数据转换层,用于缓存数据与业务数据转换
* model
数据模型实体


##### Modules
* cache
数据存储层,静态数据存储于缓存中
* requests
外部数据调用,调用外部服务获取数据


## 目录结构
```shell
├── CODEOWNERS
├── README.md
└── kdp_catalog_manager
   ├── api
   ├── common
   ├── config
   ├── main.py # 服务启动程序
   ├── requirements.txt
   ├── test_main.py
   ├── domain
   ├── modules
   └── utils
```

## 启动方式
### 开发环境搭建
* 使用python3.10+

1. 克隆代码至本地
```shell
git clone xxx && cd kdp-catalog-manager
```

2. 使用虚拟环境
```shell
#安装virtualenv
pip install virtualenv
virtualenv -p /usr/local/bin/python3 venv
# 激活虚拟环境
source ./venv/bin/activate

# 关闭虚拟环境
deactivate
```

3. 安装依赖
```shell
pip install -r docker/python/requirements.txt
```

4. 服务启动
```shell
cd ~/kdp-catalog-manager \
&& export PYTHONPATH=$PYTHONPATH:$(pwd)
python kdp_catalog_manager/main.py

```

### API 手册
* 启动服务后通过 http://127.0.0.1:8000/docs 查看提供的接口列表
2 changes: 2 additions & 0 deletions docker/python/pip-linktime.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[global]
index-url = https://nx.linktimecloud.com/repository/pypi-group/simple/
2 changes: 2 additions & 0 deletions docker/python/pip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[global]
index-url = https://pypi.douban.com/simple/
8 changes: 8 additions & 0 deletions docker/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fastapi[all]==0.110.0
uvicorn[standard]==0.27.1
cachelib==0.12.0
concurrent-log-handler==0.9.25
cachelib==0.12.0
markdown==3.5.2
prometheus-fastapi-instrumentator==6.1.0
gunicorn==21.2.0
Binary file added kdp-catalog-manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions kdp_catalog_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
2 changes: 2 additions & 0 deletions kdp_catalog_manager/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
2 changes: 2 additions & 0 deletions kdp_catalog_manager/api/api_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
18 changes: 18 additions & 0 deletions kdp_catalog_manager/api/api_v1/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from fastapi import APIRouter

from kdp_catalog_manager.api.api_v1.endpoints import catalog
from kdp_catalog_manager.api.api_v1.endpoints import catalog_app_form
from kdp_catalog_manager.api.api_v1.endpoints import catalog_app_runtime

api_router = APIRouter()

# 分组路由
api_router.include_router(catalog.router, tags=["Catalog"])
api_router.include_router(
catalog_app_form.router, tags=["CatalogAppForm"]
)
api_router.include_router(
catalog_app_runtime.router, tags=["CatalogRuntime"]
)
2 changes: 2 additions & 0 deletions kdp_catalog_manager/api/api_v1/endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
100 changes: 100 additions & 0 deletions kdp_catalog_manager/api/api_v1/endpoints/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from typing import Annotated

from fastapi import APIRouter, Path, Response, status, Header
from fastapi.responses import HTMLResponse

from kdp_catalog_manager.common.constants import CATALOG_DESC, \
NOT_FOUND_README_HTML
from kdp_catalog_manager.config.base_config import DEFAULT_LANG, SUPPORT_LANG
from kdp_catalog_manager.domain.model.catalog import CatalogList, \
CatalogDataOut
from kdp_catalog_manager.domain.service.catalog import CatalogController
from kdp_catalog_manager.exceptions.exception import KdpCatalogManagerError, \
FileNotExistsError, LangNotSupport
from kdp_catalog_manager.utils.format_return import FormatReturn

router = APIRouter()


@router.get("/catalogs",
response_model=CatalogList,
summary="获取应用目录列表",
description="获取应用目录列表操作")
async def read_catalogs(
accept_language: Annotated[str, Header(description="请求语言类型")] = DEFAULT_LANG
):
"""获取catalog 列表"""
try:
if accept_language not in SUPPORT_LANG:
raise LangNotSupport(
f"Header Accept-Language is:{accept_language}, "
f"not in {SUPPORT_LANG}")
data = CatalogController(lang=accept_language).get_catalogs()
rtn = FormatReturn().format_return_json(
data, msg="get catalogs data success")
except KdpCatalogManagerError as error:
error_info = FormatReturn().format_error_info(
error.error_name,
error.error_details,
error_msg=error.error_cname
)
rtn = FormatReturn().format_return_json(
[], status=1, msg=error.error_cname, error_info=error_info)
return rtn


@router.get("/catalogs/{catalog}",
response_model=CatalogDataOut,
summary="获取应用目录信息",
description="获取某个应用目录信息操作")
async def read_catalog(
catalog: Annotated[str, Path(description=CATALOG_DESC)],
accept_language: Annotated[str, Header(description="请求语言类型")] = DEFAULT_LANG
):
"""获取catalog 信息"""
try:
if accept_language not in SUPPORT_LANG:
raise LangNotSupport(
f"Header Accept-Language is:{accept_language}, "
f"not in {SUPPORT_LANG}")
data = CatalogController(
catalog=catalog, lang=accept_language).get_catalog()
rtn = FormatReturn().format_return_json(
data, msg="get catalogs data success")
except KdpCatalogManagerError as error:
error_info = FormatReturn().format_error_info(
error.error_name,
error.error_details,
error_msg=error.error_cname
)
rtn = FormatReturn().format_return_json(
{}, status=1, msg=error.error_cname, error_info=error_info)
return rtn


@router.get("/catalogs/{catalog}/readme",
response_class=HTMLResponse,
summary="获取应用目录说明",
description="获取某个应用目录说明操作")
async def read_catalog_readme(
response: Response,
catalog: Annotated[str, Path(description=CATALOG_DESC)],
accept_language: Annotated[str, Header(description="请求语言类型")] = DEFAULT_LANG
):
"""获取catalog 说明"""
try:
if accept_language not in SUPPORT_LANG:
raise LangNotSupport(
f"Header Accept-Language is:{accept_language}, "
f"not in {SUPPORT_LANG}")
rtn = CatalogController(
catalog, lang=accept_language).get_catalog_readme()
except FileNotExistsError:
response.status_code = status.HTTP_404_NOT_FOUND
rtn = NOT_FOUND_README_HTML
except LangNotSupport:
response.status_code = status.HTTP_400_BAD_REQUEST
rtn = "语言不支持:Header Accept-Language is:ens, not in ['zh', 'en']"
return rtn
Loading

0 comments on commit 3648957

Please sign in to comment.