Compare commits
2 commits
8e6b0a39b2
...
71964355b7
Author | SHA1 | Date | |
---|---|---|---|
71964355b7 | |||
2135126235 |
9 changed files with 58 additions and 10 deletions
3
.env
3
.env
|
@ -1,3 +1,6 @@
|
||||||
|
APP_HOST=0.0.0.0
|
||||||
|
APP_PORT=8000
|
||||||
|
|
||||||
DB_HOST=${REPO_NAME_SNAKE}_db
|
DB_HOST=${REPO_NAME_SNAKE}_db
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_USER=${REPO_NAME_SNAKE}
|
DB_USER=${REPO_NAME_SNAKE}
|
||||||
|
|
2
.env_db
2
.env_db
|
@ -1,5 +1,5 @@
|
||||||
MYSQL_HOST=${REPO_NAME_SNAKE}_db
|
|
||||||
MYSQL_PORT=3306
|
MYSQL_PORT=3306
|
||||||
|
MYSQL_RANDOM_ROOT_PASSWORD=true
|
||||||
MYSQL_USER=${REPO_NAME_SNAKE}
|
MYSQL_USER=${REPO_NAME_SNAKE}
|
||||||
MYSQL_PASSWORD=
|
MYSQL_PASSWORD=
|
||||||
MYSQL_DATABASE=${REPO_NAME_SNAKE}
|
MYSQL_DATABASE=${REPO_NAME_SNAKE}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
DEBUG=true
|
DEBUG=true
|
||||||
|
|
||||||
SESSION_KEY=debug
|
SESSION_KEY=debug
|
||||||
CSRF_KEY=debug
|
CSRF_KEY=debug
|
||||||
|
|
||||||
|
APP_HOST=127.0.0.1
|
||||||
|
APP_PORT=8000
|
||||||
|
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_USER=darkcat09
|
DB_USER=darkcat09
|
||||||
|
|
14
Dockerfile
14
Dockerfile
|
@ -1,7 +1,15 @@
|
||||||
FROM python:3-alpine
|
FROM alpine:latest as build
|
||||||
RUN apk update && apk upgrade && apk add py-pip make
|
RUN apk add --no-cache python3 python3-dev py3-pip mariadb-dev build-base
|
||||||
|
RUN pip install --no-cache-dir wheel
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN pip install -r requirements.txt
|
RUN pip wheel --no-cache-dir -w /app/wheels -r requirements.txt
|
||||||
|
|
||||||
|
FROM alpine:latest as run
|
||||||
|
RUN apk add --no-cache python3 py3-pip make mariadb-connector-c-dev
|
||||||
|
COPY --from=build /app /app
|
||||||
|
WORKDIR /app
|
||||||
|
RUN pip install --no-cache-dir --find-links /app/wheels -r requirements.txt
|
||||||
|
RUN apk del py3-pip && rm -rf /app/wheels
|
||||||
CMD make prod
|
CMD make prod
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
21
Makefile
21
Makefile
|
@ -1,9 +1,14 @@
|
||||||
|
APP_HOST ?= 0.0.0.0
|
||||||
|
APP_PORT ?= 8000
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
python3 -m dotenv -f .env_debug run \
|
python3 -m dotenv -f .env_debug run \
|
||||||
python3 -m uvicorn main:app --reload
|
make cmd-dev
|
||||||
|
|
||||||
prod:
|
prod:
|
||||||
python3 -m uvicorn main:app
|
python3 -m gunicorn \
|
||||||
|
-w 4 -k uvicorn.workers.UvicornWorker \
|
||||||
|
-b $${APP_HOST}:$${APP_PORT} main:app
|
||||||
|
|
||||||
format:
|
format:
|
||||||
python3 -m autopep8 -r --in-place app/
|
python3 -m autopep8 -r --in-place app/
|
||||||
|
@ -30,8 +35,16 @@ clean:
|
||||||
rm -rf __pycache__
|
rm -rf __pycache__
|
||||||
rm -rf .mypy_cache
|
rm -rf .mypy_cache
|
||||||
|
|
||||||
|
cmd-dev:
|
||||||
|
python3 -m uvicorn main:app \
|
||||||
|
--reload \
|
||||||
|
--host $${APP_HOST} \
|
||||||
|
--port $${APP_PORT}
|
||||||
|
|
||||||
cmd-docker-build:
|
cmd-docker-build:
|
||||||
docker build -t ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:$${VERSION} .
|
docker build \
|
||||||
|
-t ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:latest \
|
||||||
|
-t ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:$${VERSION} .
|
||||||
|
|
||||||
cmd-docker-push:
|
cmd-docker-push:
|
||||||
docker push ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:$$VERSION
|
docker push -a ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}
|
||||||
|
|
|
@ -20,6 +20,8 @@ class Settings(BaseSettings):
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
session_key: str = secrets.token_hex(32)
|
session_key: str = secrets.token_hex(32)
|
||||||
csrf_key: str = secrets.token_hex(32)
|
csrf_key: str = secrets.token_hex(32)
|
||||||
|
app_host: str = '127.0.0.1'
|
||||||
|
app_port: int = 8000
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
version: "3"
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
${REPO_NAME_SNAKE}:
|
${REPO_NAME_SNAKE}:
|
||||||
image: ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:latest
|
image: ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:latest
|
||||||
container_name: ${REPO_NAME_SNAKE}
|
container_name: ${REPO_NAME_SNAKE}
|
||||||
|
@ -10,10 +11,20 @@ services:
|
||||||
links:
|
links:
|
||||||
- ${REPO_NAME_SNAKE}_db
|
- ${REPO_NAME_SNAKE}_db
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
depends_on:
|
||||||
|
${REPO_NAME_SNAKE}_db:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
${REPO_NAME_SNAKE}_db:
|
${REPO_NAME_SNAKE}_db:
|
||||||
image: mariadb:latest
|
image: mariadb:latest
|
||||||
container_name: ${REPO_NAME_SNAKE}_db
|
container_name: ${REPO_NAME_SNAKE}_db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- "./database:/var/lib/mysql"
|
- "./database:/var/lib/mysql"
|
||||||
env_file: .env
|
env_file: .env_db
|
||||||
|
healthcheck:
|
||||||
|
test: sh -c "mysqladmin ping -u$$$$MYSQL_USER -p$$$$MYSQL_PASSWORD"
|
||||||
|
interval: 1s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 20
|
||||||
|
start_period: 10s
|
||||||
|
|
7
main.py
7
main.py
|
@ -3,7 +3,12 @@
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
from app.main import app
|
from app.main import app
|
||||||
|
from app.common import settings
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
uvicorn.run(app)
|
uvicorn.run(
|
||||||
|
app=app,
|
||||||
|
host=settings.app_host,
|
||||||
|
port=settings.app_port,
|
||||||
|
)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
fastapi==0.92.0
|
fastapi==0.92.0
|
||||||
uvicorn[standard]==0.20.0
|
uvicorn[standard]==0.20.0
|
||||||
|
gunicorn==20.1.0
|
||||||
jinja2==3.1.2
|
jinja2==3.1.2
|
||||||
starlette-wtf==0.4.3
|
starlette-wtf==0.4.3
|
||||||
sqlalchemy==2.0.4
|
sqlalchemy==2.0.4
|
||||||
|
|
Loading…
Add table
Reference in a new issue