mirror of
https://github.com/nethunterzist/trendyol-analiz
synced 2026-07-01 09:27:03 +00:00
Coolify remaps volume mounts to its own managed directories, so ./categories was mapped to an empty dir instead of the repo data. Changes: - Backend build context changed to repo root (.) so categories/ is accessible - Dockerfile copies categories into /data/initial-categories/ - startup.sh seeds /data/categories from bundled data if empty - Removed categories volume mount (reports still persisted via volume) - Added root .dockerignore (categories NOT excluded) - Updated CI workflow to match new build context Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
218 lines
6.2 KiB
YAML
218 lines
6.2 KiB
YAML
name: Trendyol Analiz CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches: [main, master, develop]
|
|
pull_request:
|
|
branches: [main, master]
|
|
|
|
env:
|
|
PYTHON_VERSION: '3.13'
|
|
NODE_VERSION: '20'
|
|
|
|
jobs:
|
|
# Backend Build & Test (FastAPI)
|
|
backend:
|
|
name: Backend (FastAPI)
|
|
runs-on: ubuntu-latest
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:15-alpine
|
|
env:
|
|
POSTGRES_DB: trendyol_db
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: testpassword
|
|
ports:
|
|
- 5432:5432
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: backend
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: ${{ env.PYTHON_VERSION }}
|
|
cache: 'pip'
|
|
cache-dependency-path: backend/requirements.txt
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r requirements.txt
|
|
pip install -r requirements-test.txt || true
|
|
|
|
- name: Lint with flake8 (optional)
|
|
run: |
|
|
pip install flake8 || true
|
|
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics || true
|
|
|
|
- name: Run tests
|
|
run: |
|
|
pip install pytest pytest-asyncio httpx || true
|
|
pytest || echo "No tests found or tests skipped"
|
|
env:
|
|
DATABASE_URL: postgresql://postgres:testpassword@localhost:5432/trendyol_db
|
|
|
|
# Frontend Build & Test (React + Vite)
|
|
frontend:
|
|
name: Frontend (React + Vite)
|
|
runs-on: ubuntu-latest
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: admin-panel
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Node.js ${{ env.NODE_VERSION }}
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
cache: 'npm'
|
|
cache-dependency-path: admin-panel/package-lock.json
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Lint check
|
|
run: npm run lint || true
|
|
|
|
- name: Build
|
|
run: npm run build
|
|
env:
|
|
VITE_API_URL: http://localhost:8001
|
|
|
|
- name: Upload frontend artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: frontend-dist
|
|
path: admin-panel/dist
|
|
retention-days: 1
|
|
|
|
# Docker Build Test
|
|
docker-build:
|
|
name: Docker Build Test
|
|
runs-on: ubuntu-latest
|
|
needs: [backend, frontend]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build Backend Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: backend/Dockerfile
|
|
push: false
|
|
tags: trendyol-backend:test
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Build Frontend Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./admin-panel
|
|
push: false
|
|
tags: trendyol-frontend:test
|
|
build-args: |
|
|
VITE_API_URL=http://localhost:8010
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# Full Integration Test (Docker Compose)
|
|
integration:
|
|
name: Integration Test
|
|
runs-on: ubuntu-latest
|
|
needs: [backend, frontend]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Create test docker-compose
|
|
run: |
|
|
cat > docker-compose.test.yml << 'EOF'
|
|
name: trendyol-test
|
|
services:
|
|
postgres:
|
|
image: postgres:15-alpine
|
|
environment:
|
|
POSTGRES_DB: trendyol_db
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: testpassword
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
|
|
backend:
|
|
build:
|
|
context: .
|
|
dockerfile: backend/Dockerfile
|
|
environment:
|
|
PYTHONUNBUFFERED: 1
|
|
DATABASE_URL: postgresql://postgres:testpassword@postgres:5432/trendyol_db
|
|
CATEGORIES_DIR: /data/categories
|
|
REPORTS_DIR: /data/reports
|
|
FRONTEND_URL: http://localhost:3010
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:8001/health"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 30s
|
|
EOF
|
|
|
|
- name: Start services
|
|
run: docker compose -f docker-compose.test.yml up -d --build
|
|
|
|
- name: Wait for backend
|
|
run: |
|
|
echo "Waiting for backend to be healthy..."
|
|
timeout 120 bash -c 'until docker compose -f docker-compose.test.yml ps backend | grep -q "healthy"; do sleep 5; done' || \
|
|
(docker compose -f docker-compose.test.yml logs && exit 1)
|
|
|
|
- name: Test backend health
|
|
run: |
|
|
docker compose -f docker-compose.test.yml exec -T backend curl -f http://localhost:8001/health || \
|
|
(docker compose -f docker-compose.test.yml logs backend && exit 1)
|
|
|
|
- name: Cleanup
|
|
if: always()
|
|
run: docker compose -f docker-compose.test.yml down -v
|
|
|
|
# Deploy to Coolify (only on main push)
|
|
deploy:
|
|
name: Deploy to Coolify
|
|
runs-on: ubuntu-latest
|
|
needs: [docker-build, integration]
|
|
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
|
|
steps:
|
|
- name: Trigger Coolify Deployment
|
|
run: |
|
|
curl -X POST "${{ secrets.COOLIFY_WEBHOOK }}" \
|
|
-H "Authorization: Bearer ${{ secrets.COOLIFY_TOKEN }}" \
|
|
--fail --max-time 30
|