Skip to content

Commit

Permalink
Merge branch 'release/3.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Oct 3, 2021
2 parents a44bc52 + 6de86b6 commit 3ce4d53
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Release python package

on:
push:
branches:
- master
tags:
- "*"

jobs:
deploy:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches-ignore:
- master
tags-ignore:
- "*"

jobs:
pytest:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ repos:
hooks:
- id: add-trailing-comma

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.0.11 # or specific tag
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.1.0
hooks:
- id: yamlfmt
- id: pretty-format-yaml
args:
- --autofix
- --preserve-quotes
- --indent=2

- repo: local
hooks:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
FROM python:3.9.6-slim-buster

RUN apt-get update && apt-get install -y \
wait-for-it \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN pip install poetry==1.1.8

# Installing requirements
# Configuring poetry
RUN poetry config virtualenvs.create false

# Copying requirements of a project
COPY pyproject.toml poetry.lock /app/src/
WORKDIR /app/src

# Installing requirements
RUN poetry install

# Copying actuall application
COPY . /app/src/
RUN pip install --use-feature=in-tree-build .
RUN poetry install

CMD python -m {{cookiecutter.project_name}}
CMD ["/usr/local/bin/python", "-m", "{{cookiecutter.project_name}}"]
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ services:
{{cookiecutter.project_name | upper}}_DB_BASE: {{cookiecutter.project_name}}
{%- endif %}
{%- endif %}

{%- if cookiecutter.db_info.name == "sqlite" %}
volumes:
- {{cookiecutter.project_name}}-db-data:/db_data/
Expand All @@ -47,14 +46,18 @@ services:
image: {{cookiecutter.db_info.image}}
hostname: {{cookiecutter.project_name}}-db
environment:
- "POSTGRES_PASSWORD={{cookiecutter.project_name}}"
- "POSTGRES_USER={{cookiecutter.project_name}}"
- "POSTGRES_DB={{cookiecutter.project_name}}"
POSTGRES_PASSWORD: "{{cookiecutter.project_name}}"
POSTGRES_USER: "{{cookiecutter.project_name}}"
POSTGRES_DB: "{{cookiecutter.project_name}}"
volumes:
- {{cookiecutter.project_name}}-db-data:/var/lib/postgresql/data
restart: always
healthcheck:
test: pg_isready -U {{cookiecutter.project_name}}
test:
- CMD
- pg_isready
- -U
- {{cookiecutter.project_name}}
interval: 2s
timeout: 3s
retries: 40
Expand All @@ -66,19 +69,19 @@ services:
hostname: {{cookiecutter.project_name}}-db
restart: always
environment:
- "ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_ROOT_PASSWORD={{cookiecutter.project_name}}"
- "MYSQL_ROOT_USER={{cookiecutter.project_name}}"
- "MYSQL_DATABASE={{cookiecutter.project_name}}"
ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_ROOT_PASSWORD: "{{cookiecutter.project_name}}"
MYSQL_ROOT_USER: "{{cookiecutter.project_name}}"
MYSQL_DATABASE: "{{cookiecutter.project_name}}"
healthcheck:
test:
- "CMD"
- "mysql"
- "-u"
- "{{cookiecutter.project_name}}"
- "-p{{cookiecutter.project_name}}"
- "-e"
- "SELECT 1"
- CMD
- mysql
- -u
- {{cookiecutter.project_name}}
- -p{{cookiecutter.project_name}}
- -e
- SELECT 1
interval: 3s
timeout: 3s
retries: 40
Expand All @@ -89,6 +92,7 @@ services:
{% if cookiecutter.enable_migrations == 'True' -%}
migrator:
image: {{cookiecutter.project_name}}:{{"${" }}{{cookiecutter.project_name | upper }}_VERSION:-latest{{"}"}}
restart: "no"
{%- if cookiecutter.orm == 'sqlalchemy' %}
command: alembic upgrade head
{%- elif cookiecutter.orm == 'tortoise' %}
Expand Down Expand Up @@ -120,9 +124,12 @@ services:
hostname: {{cookiecutter.project_name}}-redis
restart: always
environment:
- "ALLOW_EMPTY_PASSWORD=yes"
ALLOW_EMPTY_PASSWORD: "yes"
healthcheck:
test: redis-cli ping
test:
- CMD
- redis-cli
- ping
interval: 1s
timeout: 3s
retries: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: {{cookiecutter.kube_name}}
name: {{cookiecutter.kube_name}}-app
spec:
replicas: 2
selector:
matchLabels:
app: {{cookiecutter.kube_name}}-app
Expand All @@ -15,49 +17,67 @@ spec:
containers:
- name: app
image: {{cookiecutter.project_name}}:latest
readinessProbe:
httpGet:
path: /api/health
port: api-port
initialDelaySeconds: 5
periodSeconds: 10
{%- if cookiecutter.db_info.name == "sqlite" %}
command: ["/bin/sh"]
args:
- -c
- >-
{%- if cookiecutter.orm == 'sqlalchemy' %}
alembic upgrade head &&
{%- elif cookiecutter.orm == 'tortoise' %}
aerich upgrade &&
{%- endif %}
python -m {{cookiecutter.project_name }}
{%- endif %}
env:
- name: {{cookiecutter.project_name | upper }}_HOST
value: 0.0.0.0
value: "0.0.0.0"
- name: {{cookiecutter.project_name | upper }}_WORKERS_COUNT
value: "10"
{%- if cookiecutter.db_info.name != "none" %}
{%- if cookiecutter.db_info.name != "sqlite" %}
- name: {{cookiecutter.project_name | upper }}_DB_HOST
value: {{cookiecutter.kube_name}}-db-service
value: "{{cookiecutter.kube_name}}-db-service"
{%- endif %}
{%- endif %}
{%- if cookiecutter.enable_redis == 'True' %}
- name: {{cookiecutter.project_name | upper }}_REDIS_HOST
value: {{cookiecutter.kube_name}}-redis-service
value: "{{cookiecutter.kube_name}}-redis-service"
{%- endif %}
resources:
limits:
memory: "300Mi"
cpu: "200m"
ports:
- containerPort: 8000
name: api-port
---
apiVersion: v1
kind: Service
metadata:
namespace: {{cookiecutter.kube_name}}
name: {{cookiecutter.kube_name}}-app-service
spec:
selector:
app: {{cookiecutter.kube_name}}-app
ports:
- port: 80
targetPort: 8000
- protocol: TCP
port: 80
targetPort: api-port
name: api-port

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{cookiecutter.kube_name}}-app
namespace: {{cookiecutter.kube_name}}
labels:
name: {{cookiecutter.kube_name}}-app
spec:
Expand All @@ -71,4 +91,6 @@ spec:
service:
name: {{cookiecutter.kube_name}}-app-service
port:
number: 80
name: api-port

---
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: {{cookiecutter.kube_name}}
name: {{cookiecutter.kube_name}}-db
spec:
selector:
Expand All @@ -22,18 +23,18 @@ spec:
env:
{%- if cookiecutter.db_info.name == 'postgresql' %}
- name: POSTGRES_PASSWORD
value: {{cookiecutter.project_name}}
value: "{{cookiecutter.project_name}}"
- name: POSTGRES_USER
value: {{cookiecutter.project_name}}
value: "{{cookiecutter.project_name}}"
- name: POSTGRES_DB
value: {{cookiecutter.project_name}}
value: "{{cookiecutter.project_name}}"
{%- elif cookiecutter.db_info.name == 'mysql' %}
- name: MYSQL_PASSWORD
value: {{cookiecutter.project_name}}
value: "{{cookiecutter.project_name}}"
- name: MYSQL_USER
value: {{cookiecutter.project_name}}
value: "{{cookiecutter.project_name}}"
- name: MYSQL_DATABASE
value: {{cookiecutter.project_name}}
value: "{{cookiecutter.project_name}}"
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
{%- endif %}
Expand All @@ -43,6 +44,7 @@ spec:
apiVersion: v1
kind: Service
metadata:
namespace: {{cookiecutter.kube_name}}
name: "{{cookiecutter.kube_name}}-db-service"
spec:
selector:
Expand All @@ -54,6 +56,7 @@ spec:
apiVersion: batch/v1
kind: Job
metadata:
namespace: {{cookiecutter.kube_name}}
name: {{cookiecutter.kube_name}}-migrator
spec:
ttlSecondsAfterFinished: 100
Expand All @@ -63,11 +66,6 @@ spec:
- name: migrator
image: {{cookiecutter.project_name}}:latest
command:
- "wait-for-it"
- "-t"
- "180"
- "{{cookiecutter.kube_name}}-db-service:{{cookiecutter.db_info.port}}"
- "--"
{%- if cookiecutter.orm == 'sqlalchemy' %}
- "alembic"
- "upgrade"
Expand All @@ -76,7 +74,18 @@ spec:
- "aerich"
- "upgrade"
{%- endif %}
resources:
limits:
memory: "200Mi"
cpu: "250m"
env:
- name: {{cookiecutter.project_name | upper }}_DB_HOST
value: {{cookiecutter.kube_name}}-db-service
value: "{{cookiecutter.kube_name}}-db-service"
initContainers:
- name: wait-for-db
image: toschneck/wait-for-it:latest
command: ["./wait-for-it.sh", "-t", "60", "{{cookiecutter.kube_name}}-db-service:{{cookiecutter.db_info.port}}"]
restartPolicy: Never


---
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: "{{cookiecutter.project_name}}"

---
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: {{cookiecutter.kube_name}}
name: {{cookiecutter.kube_name}}-redis
spec:
selector:
Expand All @@ -15,6 +16,11 @@ spec:
containers:
- name: redis
image: bitnami/redis:6.2.5
startupProbe:
exec:
command: ["redis-cli", "ping"]
failureThreshold: 30
periodSeconds: 5
env:
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
Expand All @@ -28,10 +34,13 @@ spec:
apiVersion: v1
kind: Service
metadata:
namespace: {{cookiecutter.kube_name}}
name: "{{cookiecutter.kube_name}}-redis-service"
spec:
selector:
app: {{cookiecutter.kube_name}}-redis
ports:
- port: 6379
targetPort: 6379

---
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fastapi = "^0.68.0"
uvicorn = "^0.15.0"
pydantic = {version = "^1.8.2", extras = ["dotenv"]}
yarl = "^1.6.3"
ujson = "^4.2.0"
{%- if cookiecutter.orm == "sqlalchemy" %}
SQLAlchemy = {version = "^1.4", extras = ["mypy", "asyncio"]}
{%- elif cookiecutter.orm == "tortoise" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
{%- endif %}
{%- if cookiecutter.enable_routers == "True" %}
api_router.include_router(echo.router, prefix="/echo", tags=["echo"])
{%- if cookiecutter.db_info.name != "none" %}
{%- if cookiecutter.add_dummy == 'True' %}
api_router.include_router(dummy.router, prefix="/dummy", tags=["dummy"])
{%- endif %}
{%- endif %}
{%- if cookiecutter.enable_redis == "True" %}
api_router.include_router(redis.router, prefix="/redis", tags=["redis"])
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI
from fastapi.responses import UJSONResponse

from {{cookiecutter.project_name}}.web.api.router import api_router
from {{cookiecutter.project_name}}.web.lifetime import shutdown, startup
Expand Down Expand Up @@ -39,6 +40,7 @@ def get_app() -> FastAPI:
redoc_url="/api/redoc",
{%- endif %}
openapi_url="/api/openapi.json",
default_response_class=UJSONResponse,
)

app.on_event("startup")(startup(app))
Expand Down
Loading

0 comments on commit 3ce4d53

Please sign in to comment.