mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
add simple hs pattern
This commit is contained in:
4
.env
4
.env
@@ -2,14 +2,14 @@ PYTHONDONTWRITEBYTECODE=1
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
# Postgres
|
||||
POSTGRES_HOST=localhost
|
||||
POSTGRES_HOST=postgres
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_DB=devdb
|
||||
POSTGRES_USER=devdb
|
||||
POSTGRES_PASSWORD=secret
|
||||
|
||||
# Redis
|
||||
REDIS_HOST=localhost
|
||||
REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
REDIS_DB=2
|
||||
|
||||
|
||||
94
compose-ha.yml
Normal file
94
compose-ha.yml
Normal file
@@ -0,0 +1,94 @@
|
||||
services:
|
||||
api1:
|
||||
container_name: panettone_api1
|
||||
build: .
|
||||
environment:
|
||||
- PYTHONPATH=/panettone
|
||||
env_file:
|
||||
- .env
|
||||
- .secrets
|
||||
command: bash -c "
|
||||
uvicorn app.main:app
|
||||
--host 0.0.0.0 --port 8080
|
||||
--lifespan=on --use-colors --loop uvloop --http httptools
|
||||
"
|
||||
volumes:
|
||||
- ./app:/panettone/app
|
||||
- ./tests:/panettone/tests
|
||||
- ./templates:/panettone/templates
|
||||
- ./alembic:/panettone/alembic
|
||||
ports:
|
||||
- "8081:8080"
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
|
||||
api2:
|
||||
container_name: panettone_api2
|
||||
build: .
|
||||
environment:
|
||||
- PYTHONPATH=/panettone
|
||||
env_file:
|
||||
- .env
|
||||
- .secrets
|
||||
command: bash -c "
|
||||
uvicorn app.main:app
|
||||
--host 0.0.0.0 --port 8080
|
||||
--lifespan=on --use-colors --loop uvloop --http httptools
|
||||
"
|
||||
volumes:
|
||||
- ./app:/panettone/app
|
||||
- ./tests:/panettone/tests
|
||||
- ./templates:/panettone/templates
|
||||
- ./alembic:/panettone/alembic
|
||||
ports:
|
||||
- "8082:8080"
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
|
||||
|
||||
postgres:
|
||||
container_name: panettone_postgres
|
||||
build:
|
||||
context: ./db
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- panettone_postgres_data:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
- 5432:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
|
||||
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
|
||||
- POSTGRES_DB=${POSTGRES_DB?Variable not set}
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD-SHELL", "pg_isready -d $POSTGRES_DB -U $POSTGRES_USER"
|
||||
]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
container_name: panettone_redis
|
||||
ports:
|
||||
- "6379:6379"
|
||||
env_file:
|
||||
- .env
|
||||
entrypoint: redis-server --appendonly yes
|
||||
|
||||
loadbalancer:
|
||||
container_name: panettone_loadbalancer
|
||||
build: ./nginx
|
||||
ports:
|
||||
- "8080:80"
|
||||
depends_on:
|
||||
- api1
|
||||
- api2
|
||||
|
||||
volumes:
|
||||
panettone_postgres_data: {}
|
||||
3
nginx/Dockerfile
Normal file
3
nginx/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM nginx
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
12
nginx/nginx.conf
Normal file
12
nginx/nginx.conf
Normal file
@@ -0,0 +1,12 @@
|
||||
upstream loadbalancer {
|
||||
server api1:8080 weight=1;
|
||||
server api2:8080 weight=1;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
location / {
|
||||
proxy_pass http://loadbalancer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user