- Add Gitea Actions workflow with 4 stages: lint, test, build, push - Configure ruff linting and formatting checks - Set up Django tests with PostgreSQL and Redis services - Implement Docker image building for web and celery services - Add requirements.txt and requirements-dev.txt generation - Fix ipdb compatibility issues in test runner - Update ruff configuration for Django compatibility - Add comprehensive CI/CD documentation
248 lines
6.7 KiB
YAML
248 lines
6.7 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
pull_request:
|
|
branches: [ main, develop ]
|
|
|
|
jobs:
|
|
lint:
|
|
name: Code Quality Checks
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Install uv
|
|
run: |
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
|
|
- name: Create virtual environment
|
|
run: uv venv
|
|
|
|
- name: Activate virtual environment and install dependencies
|
|
run: |
|
|
source .venv/bin/activate
|
|
uv sync --dev
|
|
|
|
- name: Run Ruff linting
|
|
run: |
|
|
source .venv/bin/activate
|
|
ruff check .
|
|
|
|
- name: Run Ruff formatting check
|
|
run: |
|
|
source .venv/bin/activate
|
|
ruff format . --check
|
|
|
|
test:
|
|
name: Run Tests
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres:15.10
|
|
env:
|
|
POSTGRES_DB: test_db
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 5432:5432
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
options: >-
|
|
--health-cmd "redis-cli ping"
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 6379:6379
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Install uv
|
|
run: |
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
|
|
- name: Create virtual environment
|
|
run: uv venv
|
|
|
|
- name: Activate virtual environment and install dependencies
|
|
run: |
|
|
source .venv/bin/activate
|
|
uv sync --dev
|
|
|
|
- name: Wait for services to be ready
|
|
run: |
|
|
# Wait for PostgreSQL
|
|
until pg_isready -h localhost -p 5432 -U postgres; do
|
|
echo "Waiting for PostgreSQL..."
|
|
sleep 2
|
|
done
|
|
|
|
# Wait for Redis
|
|
until redis-cli -h localhost -p 6379 ping; do
|
|
echo "Waiting for Redis..."
|
|
sleep 2
|
|
done
|
|
|
|
- name: Run Django tests
|
|
run: |
|
|
source .venv/bin/activate
|
|
cd src
|
|
python manage.py test --verbosity=2
|
|
env:
|
|
DJANGO_SETTINGS_MODULE: config.settings.development
|
|
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db
|
|
REDIS_URL: redis://localhost:6379/0
|
|
CELERY_BROKER_URL: redis://localhost:6379/0
|
|
SECRET_KEY: test-secret-key-for-ci
|
|
|
|
build:
|
|
name: Build Docker Images
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Extract metadata for web image
|
|
id: meta-web
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ github.repository_owner }}/mostovik-web
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=sha,prefix={{branch}}-
|
|
|
|
- name: Extract metadata for celery image
|
|
id: meta-celery
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ github.repository_owner }}/mostovik-celery
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=sha,prefix={{branch}}-
|
|
|
|
- name: Build web image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./docker/Dockerfile.web
|
|
push: false
|
|
load: true
|
|
tags: ${{ steps.meta-web.outputs.tags }}
|
|
labels: ${{ steps.meta-web.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Build celery image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./docker/Dockerfile.celery
|
|
push: false
|
|
load: true
|
|
tags: ${{ steps.meta-celery.outputs.tags }}
|
|
labels: ${{ steps.meta-celery.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
push:
|
|
name: Push to Gitea Registry
|
|
runs-on: ubuntu-latest
|
|
needs: [build]
|
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Login to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ vars.GITEA_REGISTRY_URL }}
|
|
username: ${{ secrets.GITEA_USERNAME }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Extract metadata for web image
|
|
id: meta-web
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository_owner }}/mostovik-web
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=sha,prefix={{branch}}-
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
- name: Extract metadata for celery image
|
|
id: meta-celery
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository_owner }}/mostovik-celery
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=sha,prefix={{branch}}-
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
- name: Build and push web image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./docker/Dockerfile.web
|
|
push: true
|
|
tags: ${{ steps.meta-web.outputs.tags }}
|
|
labels: ${{ steps.meta-web.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Build and push celery image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./docker/Dockerfile.celery
|
|
push: true
|
|
tags: ${{ steps.meta-celery.outputs.tags }}
|
|
labels: ${{ steps.meta-celery.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Image digest
|
|
run: |
|
|
echo "Web image digest: ${{ steps.docker_build_web.outputs.digest }}"
|
|
echo "Celery image digest: ${{ steps.docker_build_celery.outputs.digest }}"
|