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

Feat: init project #1

Merged
merged 5 commits into from
Mar 29, 2024
Merged
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
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
68 changes: 35 additions & 33 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,45 @@
name: CI-Build

on:
push:
branches:
- main
- release-*
pull_request:
branches:
- main
- release-*
release:
types:
- published

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@v5
with:
python-version: "3.10"
cache: 'pip' # caching pip 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: Docker Login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
username: ${{ secrets.REG_USER }}
password: ${{ secrets.REG_PASSWD }}

- name: Get Version
id: pversion
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 }}


if [[ "${{ github.ref_name }}" =~ ^[.\|v][0-9]{1,}.[0-9]{1,}[.\|-][0-9]{1,} ]];then
VERSION=${{ github.ref_name }}
else
VERSION="latest"
fi
echo "git_revision=$VERSION" >> $GITHUB_OUTPUT

- name: Build Images
id: build
run: make docker-build IMG_REGISTRY=${{ secrets.CONTAINER_REGISTRY }} VERSION=${{ steps.pversion.outputs.git_revision }}

- name: Push Images
run: make docker-push IMG_REGISTRY=${{ secrets.CONTAINER_REGISTRY }} VERSION=${{ steps.pversion.outputs.git_revision }}
44 changes: 17 additions & 27 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Unit-Test
on:
push:
branches:
- main
- release-*
- "*"
workflow_dispatch: {}
pull_request:
branches:
Expand All @@ -14,15 +13,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 +31,22 @@ 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
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code into the Go module directory
uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017
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: |
export Test=true
pytest --cov --cov-report term --cov-report xml:coverage.xml
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM python:3.10.13-bullseye AS builder

WORKDIR /workspace

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv ${VIRTUAL_ENV}
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"

# Install Python dependencies
COPY docker/python/requirements.txt .
COPY docker/bin/entrypoint.sh .
#COPY version.py .
COPY kdp_catalog_manager kdp_catalog_manager/
RUN ${VIRTUAL_ENV}/bin/pip3 install --no-cache-dir --upgrade pip setuptools Cython==3.0.8 \
&& ${VIRTUAL_ENV}/bin/pip3 install --no-cache-dir --upgrade --force-reinstall -r requirements.txt \
&& rm -f requirements.txt \
&& cd kdp_catalog_manager && python setup.py build_ext --inplace \
&& ${VIRTUAL_ENV}/bin/python setup.py build_ext clean -a && rm -f setup.py && rm -rf build


FROM python:3.10.13-bullseye

ENV TZ=${TZ:-Asia/Shanghai}
ARG RUNTIME_HOME
ENV RUNTIME_HOME=${RUNTIME_HOME:-/opt/bdos/kdp/bdos-core}
ENV BDOS_USER=${BDOS_USER:-bdos}
ENV BDOS_USER_HOME=${BDOS_USER_HOME:-/home/${BDOS_USER}}


WORKDIR ${RUNTIME_HOME}

RUN apt-get update \
&& apt-get -y install sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& cp /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo ${TZ} > /etc/timezone \
&& adduser -q --disabled-password --shell /bin/bash ${BDOS_USER} \
&& echo "${BDOS_USER} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${BDOS_USER} \
&& chmod 0440 /etc/sudoers.d/${BDOS_USER} \
&& chown -R ${BDOS_USER}:${BDOS_USER} ${BDOS_USER_HOME} \
&& mkdir ${RUNTIME_HOME}/logs \
&& chown -R ${BDOS_USER}:${BDOS_USER} ${RUNTIME_HOME}

ENV PYTHONPATH=${RUNTIME_HOME}
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"
COPY --chown=${BDOS_USER}:${BDOS_USER} --from=builder /workspace .
COPY --chown=${BDOS_USER}:${BDOS_USER} --from=builder /opt/venv /opt/venv

USER ${BDOS_USER}
CMD ["/bin/sh", "-c", "${RUNTIME_HOME}/entrypoint.sh"]
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
97 changes: 95 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,95 @@
# template-project
This is the template project for initializing other LTC projects.
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
![Tests](https://github.com/linktimecloud/kdp-catalog-manager/actions/workflows/unit-test.yml/badge.svg)
![Build](https://github.com/linktimecloud/kdp-catalog-manager/actions/workflows/ci-build.yml/badge.svg)
![](https://img.shields.io/badge/python-3.10.13-green)
![](https://img.shields.io/badge/fastapi-0.110.0-green)
![image version](https://img.shields.io/docker/v/linktimecloud/kdp-catalog-manager)
![image size](https://img.shields.io/docker/image-size/linktimecloud/kdp-catalog-manager)


# 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 查看提供的接口列表
25 changes: 25 additions & 0 deletions docker/bin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

declare RUNTIME_HOME=${RUNTIME_HOME:-"/opt/bdos/kdp/bdos-core"}
declare BDOS_USER=${BDOS_USER:-bdos}
declare CHOWN_HOST_PATH=${CHOWN_HOST_PATH:-"False"}
declare LOG_LEVEL=${LOG_LEVEL:-"info"}
declare WORKER_NUM=${WORKER_NUM:-4}
declare PARAMS_LIMIT=${PARAMS_LIMIT:-0}
declare MAX_REQUESTS=${MAX_REQUESTS:-100}
declare MAX_REQUESTS_JITTER=${MAX_REQUESTS:-100}


sudo chown ${BDOS_USER}:${BDOS_USER} ${RUNTIME_HOME} >/dev/null 2>&1

if [[ "${CHOWN_HOST_PATH}" == "True" ]];then
echo -e "### Change owner of $RUNTIME_HOME ###"
sudo chown -R ${BDOS_USER}:${BDOS_USER} ${RUNTIME_HOME}/kdp_catalog_manager ${RUNTIME_HOME}/logs ${RUNTIME_HOME} >/dev/null 2>&1
echo -e "### Change owner return code: $? ###"
fi


echo -e "### Starting Server... ###"
cd ${RUNTIME_HOME}

gunicorn -c kdp_catalog_manager/config/gunicorn.py kdp_catalog_manager.main:app --workers ${WORKER_NUM} --log-level ${LOG_LEVEL} --limit-request-line=${PARAMS_LIMIT} --max-requests ${MAX_REQUESTS} --max-requests-jitter ${MAX_REQUESTS_JITTER} --preload
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 -*-
Loading
Loading