Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zhubx007 committed Jul 5, 2022
1 parent dd0314d commit 1117a5a
Show file tree
Hide file tree
Showing 173 changed files with 19,599 additions and 1 deletion.
136 changes: 136 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Dandelion
.git
etc/dandelion/dandelion.conf
mypy-report/
AUTHORS
ChangeLog
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ dmypy.json

# Pyre type checker
.pyre/

# Dandelion
etc/dandelion/dandelion.conf
mypy-report/
AUTHORS
ChangeLog
9 changes: 9 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[settings]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
ensure_newline_before_comments = True
line_length = 99
reverse_relative = true
combine_as_imports = true
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM ubuntu:20.04

ARG GIT_BRANCH
ARG GIT_COMMIT
ARG RELEASE_VERSION
ARG REPO_URL

LABEL dandelion.build_branch=${GIT_BRANCH} \
dandelion.build_commit=${GIT_COMMIT} \
dandelion.release_version=${RELEASE_VERSION} \
dandelion.repo_url=${REPO_URL}

COPY ./ /dandelion/
COPY ./etc/dandelion/gunicorn.py /etc/dandelion/gunicorn.py
COPY ./etc/dandelion/dandelion.conf.sample /etc/dandelion/dandelion.conf
COPY ./tools/run_service.sh /usr/local/bin/run_service.sh

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

RUN export LANG=C.UTF-8 \
&& apt-get update -y && apt-get install -y --no-install-recommends apt-utils \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
traceroute lsof iputils-ping vim git wget curl locales-all ssl-cert \
python3 python3-pip python3-dev python3-venv gcc make \
&& rm -rf /usr/bin/python /usr/bin/pip \
&& ln -s /usr/bin/python3 /usr/bin/python \
&& ln -s /usr/bin/pip3 /usr/bin/pip \
&& cd /dandelion/ \
&& git init \
&& git config --global user.name build \
&& git config --global user.email [email protected] \
&& git add . \
&& git commit -a -m "Build ${GIT_BRANCH} ${GIT_COMMIT}" \
&& cd / \
&& pip install dandelion/ \
&& apt-get clean \
&& rm -rf ~/.cache/pip

EXPOSE 28100

CMD ["run_service.sh"]
110 changes: 110 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
SHELL := /bin/bash

PYTHON ?= python3
SOURCES := dandelion
TOOLS := tools
ROOT_DIR ?= $(shell git rev-parse --show-toplevel)

# Color
no_color = \033[0m
black = \033[0;30m
red = \033[0;31m
green = \033[0;32m
yellow = \033[0;33m
blue = \033[0;34m
purple = \033[0;35m
cyan = \033[0;36m
white = \033[0;37m

# Version
RELEASE_VERSION ?= $(shell git rev-parse --short HEAD)_$(shell date -u +%Y-%m-%dT%H:%M:%S%z)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT ?= $(shell git rev-parse --verify HEAD)

# Database manage
REV_MEG ?=

.PHONY: all help venv install fmt lint server clean db_revision db_sync swagger config build future_check

all:
make venv
make fmt
make lint
make swagger
make config
make future_check

help:
@echo "Dandelion development makefile"
@echo
@echo "Usage: make <TARGET>"
@echo
@echo "Target:"
@echo " venv Create virtualenvs."
@echo " install Installs the project dependencies."
@echo " fmt Code format."
@echo " lint Code lint."
@echo " server Run Server."
@echo " clean Clean tmp resources."
@echo " db_revision Generate database alembic version revision with model."
@echo " db_sync Sync database from alembic version revision."
@echo " swagger Generate swagger json file."
@echo " config Generate sample config file."
@echo " build Build docker image."
@echo " future_check Find python files without 'type annotations'.(Alpha)"
@echo

venv:
tox -e venv

install:
tox -e install
source .tox/install/bin/activate && python setup.py install && deactivate

fmt:
tox -e pep8-format

lint:
tox -e pep8

server: install
source .tox/install/bin/activate && uvicorn --reload --reload-dir dandelion --port 28300 --log-level debug dandelion.main:app --host 0.0.0.0

clean:
rm -rf $(ROOT_DIR)/build
rm -rf $(ROOT_DIR)/dist
rm -rf $(ROOT_DIR)/.venv
rm -rf $(ROOT_DIR)/test_report.html
rm -rf $(ROOT_DIR)/.tox

db_revision:
$(shell [ -z "$(REV_MEG)" ] && printf '$(red)Missing required message, use "make db_revision REV_MEG=<some message>"$(no_color)')
source .tox/venv/bin/activate && alembic revision --autogenerate -m '$(REV_MEG)' && deactivate

db_sync:
source .tox/venv/bin/activate && alembic upgrade head && deactivate

swagger:
tox -e genswagger

config:
tox -e genconfig

BUILD_ENGINE ?= docker
BUILD_CONTEXT ?= .
DOCKER_FILE ?= Dockerfile
IMAGE ?= dandelion
IMAGE_TAG ?= latest
ifeq ($(BUILD_ENGINE), docker)
build_cmd = docker build
else ifeq ($(BUILD_ENGINE), buildah)
build_cmd = buildah bud
else
$(error Unsupported build engine $(BUILD_ENGINE))
endif
build:
$(build_cmd) --no-cache --pull --force-rm --build-arg RELEASE_VERSION=$(RELEASE_VERSION) --build-arg GIT_BRANCH=$(GIT_BRANCH) --build-arg GIT_COMMIT=$(GIT_COMMIT) $(BUILD_ARGS) -f $(DOCKER_FILE) -t $(IMAGE):$(IMAGE_TAG) $(BUILD_CONTEXT)

# Find python files without "type annotations"
future_check:
@find dandelion ! -size 0 -type f -name '*.py' -exec grep -L 'from __future__ import annotations' {} \;
Loading

0 comments on commit 1117a5a

Please sign in to comment.