Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .env.staging.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Staging Environment Configuration
ENVIRONMENT=staging

# Database
DATABASE_URL=postgresql://postgres:staging_password@db_postgres:5432/staging_db
POSTGRES_DB=staging_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=staging_password_change_me

# Application
SECRET_KEY=staging_secret_key_change_me_in_production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

# External Services
REDIS_URL=redis://redis:6379/0

# Monitoring
GRAFANA_PASSWORD=staging_admin_password
PGADMIN_PASSWORD=staging_pgadmin_password

# Notifications (optional)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK

# Logging
LOG_LEVEL=INFO
LOG_FORMAT=json

# CORS (для staging можно быть более либеральным)
CORS_ORIGINS=["http://localhost:3000", "https://staging.yourdomain.com"]

# Rate Limiting
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=60
38 changes: 0 additions & 38 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

28 changes: 0 additions & 28 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

79 changes: 74 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ jobs:
run: |
uv sync --all-extras --dev
uv pip install -r tests/requirements-test.txt
uv add ruff

- name: Create test environment file
run: |
Expand Down Expand Up @@ -192,11 +191,81 @@ jobs:
environment: staging

steps:
- name: Deploy to staging
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy to staging server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USER }}
key: ${{ secrets.STAGING_SSH_KEY }}
port: ${{ secrets.STAGING_PORT || 22 }}
script: |
# Переходим в директорию проекта
cd ${{ secrets.STAGING_PROJECT_PATH || '/opt/app' }}

# Подтягиваем последние изменения
git fetch origin
git checkout develop
git pull origin develop

# Экспортируем переменные окружения
export GITHUB_REPOSITORY=${{ github.repository }}
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
export GITHUB_ACTOR=${{ github.actor }}

# Запускаем деплой
./scripts/deploy-staging.sh

- name: Alternative local deployment (if no staging server)
if: ${{ !secrets.STAGING_HOST }}
run: |
echo "Deploying to staging environment..."
# Здесь будет код для деплоя в staging
# Например, обновление Kubernetes deployment или Docker Compose
echo "No staging server configured, running local deployment simulation..."

# Создаем .env.staging из примера
if [ ! -f ".env.staging" ]; then
cp .env.staging.example .env.staging
fi

# Симулируем деплой
echo "Would deploy image: ghcr.io/${{ github.repository }}:develop"
echo "Staging deployment simulation completed"

- name: Health check
if: ${{ secrets.STAGING_HOST }}
run: |
# Ждем запуска приложения
sleep 30

# Проверяем доступность
curl -f http://${{ secrets.STAGING_HOST }}:8081/health || echo "Health check failed"

- name: Notify deployment status
if: always()
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
channel: '#deployments'
text: |
Staging Deployment ${{ job.status }}
Repository: ${{ github.repository }}
Branch: ${{ github.ref_name }}
Commit: ${{ github.sha }}
Actor: ${{ github.actor }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
continue-on-error: true

deploy-production:
name: Deploy to Production
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
python-version: "3.13"

- name: Install uv
uses: astral-sh/setup-uv@v3
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
python-version: "3.13"

- name: Install tools
run: |
Expand All @@ -80,4 +80,4 @@ jobs:

- name: Check for complex functions
run: |
xenon --max-absolute B --max-modules A --max-average A app/
xenon --max-absolute B --max-modules A --max-average A app/
4 changes: 2 additions & 2 deletions app/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def set_tokens(response: Response, user_id: int):

response.set_cookie(
key="user_access_token",
value=access_token,
value=str(access_token or ""),
httponly=True,
secure=True,
samesite="lax",
)

response.set_cookie(
key="user_refresh_token",
value=refresh_token,
value=str(refresh_token or ""),
httponly=True,
secure=True,
samesite="lax",
Expand Down
4 changes: 2 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Settings(BaseSettings):
)
LOG_ROTATION: str = "10 MB"

SECRET_KEY: str = "test-secret-key"
SECRET_KEY: str = "test-secret-key" # noqa: S105
ALGORITHM: str = "HS256"

POSTGRES_USER: str = "test"
POSTGRES_PASSWORD: str = "test"
POSTGRES_PASSWORD: str = "test" # noqa: S105
POSTGRES_HOST: str = "localhost"
POSTGRES_PORT: int = 5432
POSTGRES_DB: str = "test"
Expand Down
2 changes: 1 addition & 1 deletion app/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class BaseDAO[T: Base]:
model: type[T] = None
model: type[T]

def __init__(self, session: AsyncSession):
self._session = session
Expand Down
1 change: 1 addition & 0 deletions command
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
uvicorn app.main:app --host 0.0.0.0 --port 8080
docker compose up -d --build
docker compose -f docker-compose-prod.yml up -d --build

docker compose down
docker compose down -v
Expand Down
93 changes: 93 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
services:
app:
restart: always
image: ghcr.io/gooodh/fastapi_sqlalchemy_temp:latest
container_name: "app"
command: bash entrypoint.sh
ports:
- "8080:8080"
depends_on:
- db_postgres

watchtower:
image: containrrr/watchtower
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command:
- --cleanup=true # Очистка старых неиспользуемых образов после обновления
- --interval=300 # Проверять обновления каждые 300 секунд (5 минут)


db_postgres:
image: postgres:15
container_name: app_postgres_container
restart: always
env_file:
- .env
volumes:
- app_postgres:/var/lib/postgresql/data
ports:
- 5432:5432

pgadmin:
image: dpage/pgadmin4
container_name: app_pgadmin_container
environment:
PGADMIN_DEFAULT_EMAIL: admin@pgadmin.com
PGADMIN_DEFAULT_PASSWORD: password
PGADMIN_LISTEN_PORT: 80
ports:
- 15432:80
volumes:
- app_pgadmin:/var/lib/pgadmin
depends_on:
- db_postgres

loki:
image: grafana/loki:latest
container_name: "grafana_loki"
ports:
- "3100:3100"
volumes:
- ./loki-config.yml:/etc/loki/local-config.yml:ro

grafana:
image: grafana/grafana:latest
container_name: "grafana"
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana

promtail:
image: grafana/promtail:2.9.0
container_name: promtail
volumes:
- /var/lib/docker/containers:/var/lib/docker/containers:ro
- /var/run/docker.sock:/var/run/docker.sock
- ./promtail-config.yaml:/etc/promtail/config.yml
command: -config.file=/etc/promtail/config.yml
privileged: true
depends_on:
- loki

prometheus:
image: prom/prometheus:v2.52.0
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.enable-lifecycle'
depends_on:
- loki

volumes:
app_postgres:
app_pgadmin:
grafana_data:
Loading