File tree Expand file tree Collapse file tree 11 files changed +256
-5
lines changed
{{ cookiecutter.project_slug }} Expand file tree Collapse file tree 11 files changed +256
-5
lines changed Original file line number Diff line number Diff line change 2626 - name : Install dependencies
2727 run : |
2828 python -m pip install --upgrade pip
29- pip install cookiecutter flake8 pytest mypy pytest-cov
29+ pip install cookiecutter flake8 pytest mypy pytest-cov kamidana
3030 make create-project-no-input PROJECT_NAME=dummy
3131 cd dummy && pip install .
3232 - name : CI
Original file line number Diff line number Diff line change 1+ # Python project template for Web API with cookiecutter
2+
3+ ## Requirements
4+
5+ - cookiecutter
6+ - kamidana
Original file line number Diff line number Diff line change 11{
22 "project_slug" : " python_api_template" ,
3- "description" : " hoge"
3+ "description" : " hoge" ,
4+ "_extensions" : [" kamidana.extensions.NamingModuleExtension" ]
45}
Original file line number Diff line number Diff line change 1+ .github /
2+ k8s /
3+
4+ # Byte-compiled / optimized / DLL files
5+ __pycache__ /
6+ * .py [cod ]
7+ * $py.class
8+
9+ # C extensions
10+ * .so
11+
12+ # Distribution / packaging
13+ .Python
14+ build /
15+ develop-eggs /
16+ dist /
17+ downloads /
18+ eggs /
19+ .eggs /
20+ lib /
21+ lib64 /
22+ parts /
23+ sdist /
24+ var /
25+ wheels /
26+ pip-wheel-metadata /
27+ share /python-wheels /
28+ * .egg-info /
29+ .installed.cfg
30+ * .egg
31+ MANIFEST
32+
33+ # PyInstaller
34+ # Usually these files are written by a python script from a template
35+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36+ * .manifest
37+ * .spec
38+
39+ # Installer logs
40+ pip-log.txt
41+ pip-delete-this-directory.txt
42+
43+ # Unit test / coverage reports
44+ htmlcov /
45+ .tox /
46+ .nox /
47+ .coverage
48+ .coverage. *
49+ .cache
50+ nosetests.xml
51+ coverage.xml
52+ * .cover
53+ * .py,cover
54+ .hypothesis /
55+ .pytest_cache /
56+
57+ # Translations
58+ * .mo
59+ * .pot
60+
61+ # Django stuff:
62+ * .log
63+ local_settings.py
64+ db.sqlite3
65+ db.sqlite3-journal
66+
67+ # Flask stuff:
68+ instance /
69+ .webassets-cache
70+
71+ # Scrapy stuff:
72+ .scrapy
73+
74+ # Sphinx documentation
75+ docs /_build /
76+
77+ # PyBuilder
78+ target /
79+
80+ # Jupyter Notebook
81+ .ipynb_checkpoints
82+
83+ # IPython
84+ profile_default /
85+ ipython_config.py
86+
87+ # pyenv
88+ .python-version
89+
90+ # pipenv
91+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94+ # install all needed dependencies.
95+ # Pipfile.lock
96+
97+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+ __pypackages__ /
99+
100+ # Celery stuff
101+ celerybeat-schedule
102+ celerybeat.pid
103+
104+ # SageMath parsed files
105+ * .sage.py
106+
107+ # Environments
108+ .env
109+ .venv
110+ env /
111+ venv /
112+ ENV /
113+ env.bak /
114+ venv.bak /
115+
116+ # Spyder project settings
117+ .spyderproject
118+ .spyproject
119+
120+ # Rope project settings
121+ .ropeproject
122+
123+ # mkdocs documentation
124+ /site
125+
126+ # mypy
127+ .mypy_cache /
128+ .dmypy.json
129+ dmypy.json
130+
131+ # Pyre type checker
132+ .pyre /
Original file line number Diff line number Diff line change 1+ SRC_PORT := 4600
2+ DST_PORT := 8000
3+
14# #### docker
25IMAGE_NAME := {{ cookiecutter.project_slug }}
36CONTAINER_NAME := ${IMAGE_NAME}-container
4- SRC_PORT := 4600
5- DST_PORT := 8000
67
78build-image :
89docker build -t ${IMAGE_NAME} ./
@@ -13,6 +14,7 @@ run-container:
1314-p ${SRC_PORT} :${DST_PORT} \
1415${IMAGE_NAME}
1516
17+
1618# #### ci
1719ci : typecheck test lint
1820
2931pytest -rf --cov=./{{ cookiecutter.project_slug }}
3032
3133
34+ # #### k8s
35+ MANIFEST_PATH = $(shell pwd) /k8s
36+ ENVIRONMENT := local
37+
38+ deploy :
39+ kubectl apply -k ${MANIFEST_PATH} /overlays/${ENVIRONMENT} /
40+
41+ # TODO: prevent operation mistaken
42+ destory :
43+ kubectl delete -k ${MANIFEST_PATH} /overlays/${ENVIRONMENT} /
44+
45+ port-forward :
46+ kubectl port-forward service/{{ cookiecutter.project_slug | kebabcase }}-service ${SRC_PORT} :${DST_PORT}
47+
3248# #### application
3349launch :
3450uvicorn app:app --host 0.0.0.0 --port ${DST_PORT}
Original file line number Diff line number Diff line change 1- # python-api-template
1+ # {{ cookiecutter.project_slug }}
2+
3+ ## Requirements
4+
5+ - make
6+ - docker for mac
7+ - Please turn on ` Enable Kubernetes ` configulation if you want to deploy on local k8s
8+ - flake8, pytest, mypy
9+
10+ ## quick start
11+
12+ 1 . build docker image
13+ ``` bash
14+ make build-image
15+ ```
16+
17+ 2 . deploy on your local k8s cluster
18+ ``` bash
19+ make deploy
20+ ```
21+
22+ 3 . port-forward to k8s service resource
23+ ``` bash
24+ make port-forward
25+ ```
26+
27+ 4 . invoke health check endpoint
28+ ``` bash
29+ curl localhost:4600/health
30+ {" msg" :" I'm healthy" }
31+ ```
32+
33+ ## test/lint/typecheck
34+
35+ ``` bash
36+ make ci
37+ ```
Original file line number Diff line number Diff line change 1+ apiVersion : v1
2+ kind : ConfigMap
3+ metadata :
4+ name : configmap
5+ data :
6+ APP_ENV : nonProduction
Original file line number Diff line number Diff line change 1+ apiVersion : apps/v1
2+ kind : Deployment
3+ metadata :
4+ name : deployment
5+ spec :
6+ selector :
7+ matchLabels :
8+ app : {{ cookiecutter.project_slug | kebabcase }}
9+ replicas : 2
10+ template :
11+ spec :
12+ containers :
13+ - name : {{ cookiecutter.project_slug | kebabcase }}
14+ image : {{ cookiecutter.project_slug }}
15+ imagePullPolicy : Never
16+ livenessProbe :
17+ httpGet :
18+ port : 8000
19+ path : /health
20+ readinessProbe :
21+ httpGet :
22+ port : 8000
23+ path : /health
24+ ports :
25+ - containerPort : 8000
26+ envFrom :
27+ - configMapRef :
28+ name : configmap
Original file line number Diff line number Diff line change 1+ namespace : default
2+ namePrefix : " {{ cookiecutter.project_slug | kebabcase }}-"
3+ commonLabels :
4+ app : {{ cookiecutter.project_slug | kebabcase }}
5+ resources :
6+ - configmap.yaml
7+ - deployment.yaml
8+ - service.yaml
Original file line number Diff line number Diff line change 1+ apiVersion : v1
2+ kind : Service
3+ metadata :
4+ name : service
5+ spec :
6+ type : NodePort
7+ ports :
8+ - protocol : TCP
9+ port : 8000
10+ targetPort : 8000
11+ selector :
12+ app : {{ cookiecutter.project_slug | kebabcase }}
You can’t perform that action at this time.
0 commit comments