Compare commits
2 Commits
365f110f9c
...
afc0024b37
| Author | SHA1 | Date | |
|---|---|---|---|
| afc0024b37 | |||
| ffd2678c91 |
@@ -0,0 +1,54 @@
|
|||||||
|
name: CI/CD Awesome Pipeline
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY_URL: ${{ vars.REGISTRY_URL || 'gitea.iswearihadsomethingforthis.net' }}
|
||||||
|
REGISTRY_USER: ${{ vars.REGISTRY_USER || 'francwa' }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build and run tests
|
||||||
|
run: make _ci-run-tests
|
||||||
|
|
||||||
|
build-and-push:
|
||||||
|
name: Build & Push to Registry
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Load config from Makefile
|
||||||
|
id: config
|
||||||
|
run: |
|
||||||
|
eval "$(make _ci-image-name)"
|
||||||
|
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Extract version from tag
|
||||||
|
id: version
|
||||||
|
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build production image
|
||||||
|
run: make build
|
||||||
|
|
||||||
|
- name: Tag and push to registry
|
||||||
|
run: |
|
||||||
|
docker tag ${{ steps.config.outputs.image_name }}:latest ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.config.outputs.image_name }}:${{ steps.version.outputs.version }}
|
||||||
|
docker tag ${{ steps.config.outputs.image_name }}:latest ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.config.outputs.image_name }}:latest
|
||||||
|
echo "${{ secrets.GITEA_TOKEN }}" | docker login ${{ env.REGISTRY_URL }} -u ${{ env.REGISTRY_USER }} --password-stdin
|
||||||
|
docker push ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.config.outputs.image_name }}:${{ steps.version.outputs.version }}
|
||||||
|
docker push ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.config.outputs.image_name }}:latest
|
||||||
@@ -18,18 +18,18 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: ruff-check
|
- id: ruff-check
|
||||||
name: Ruff Linter
|
name: Ruff Linter
|
||||||
entry: bash -c 'cd brain && poetry run ruff check --fix'
|
entry: bash -c 'make lint'
|
||||||
language: system
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
|
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
name: Ruff Formatter
|
name: Ruff Formatter
|
||||||
entry: bash -c 'cd brain && poetry run ruff format'
|
entry: bash -c 'make format'
|
||||||
language: system
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
|
|
||||||
- id: system-pytest
|
- id: system-pytest
|
||||||
name: Pytest
|
name: Pytest
|
||||||
entry: bash -c 'cd brain && poetry run pytest -n auto --dist=loadscope'
|
entry: bash -c 'make test'
|
||||||
language: system
|
language: system
|
||||||
always_run: true
|
always_run: true
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
# --- SETTINGS ---
|
# --- SETTINGS ---
|
||||||
# Change to 'uv' when ready.
|
# Change to 'uv' when ready.
|
||||||
RUNNER = poetry
|
RUNNER ?= poetry
|
||||||
|
export RUNNER
|
||||||
|
|
||||||
# --- VARIABLES ---
|
# --- VARIABLES ---
|
||||||
CORE_DIR = brain
|
CORE_DIR = brain
|
||||||
@@ -19,7 +20,7 @@ INSTALL_CMD = $(if $(filter uv,$(RUNNER)),sync,install)
|
|||||||
ARGS = $(filter-out $@,$(MAKECMDGOALS))
|
ARGS = $(filter-out $@,$(MAKECMDGOALS))
|
||||||
BUMP_CMD = cd $(CORE_DIR) && $(RUNNER) run bump-my-version bump
|
BUMP_CMD = cd $(CORE_DIR) && $(RUNNER) run bump-my-version bump
|
||||||
COMPOSE_CMD = docker-compose
|
COMPOSE_CMD = docker-compose
|
||||||
DOCKER_CMD = cd $(CORE_DIR) && docker build -t $(IMAGE_NAME):latest .
|
DOCKER_CMD = cd $(CORE_DIR) && docker build --build-arg RUNNER=$(RUNNER) -t $(IMAGE_NAME):latest .
|
||||||
|
|
||||||
RUNNER_ADD = cd $(CORE_DIR) && $(RUNNER) add
|
RUNNER_ADD = cd $(CORE_DIR) && $(RUNNER) add
|
||||||
RUNNER_HOOKS = cd $(CORE_DIR) && $(RUNNER) run pre-commit install -c ../.pre-commit-config.yaml
|
RUNNER_HOOKS = cd $(CORE_DIR) && $(RUNNER) run pre-commit install -c ../.pre-commit-config.yaml
|
||||||
@@ -195,7 +196,7 @@ shell: check-docker
|
|||||||
|
|
||||||
test: check-runner
|
test: check-runner
|
||||||
@echo "$(T)🧪 Running tests...$(R)"
|
@echo "$(T)🧪 Running tests...$(R)"
|
||||||
$(RUNNER_RUN) pytest $(ARGS)
|
$(RUNNER_RUN) pytest -n auto --dist=loadscope $(ARGS)
|
||||||
|
|
||||||
up: check-docker
|
up: check-docker
|
||||||
@echo "$(T)🚀 Starting Agent Media...$(R)"
|
@echo "$(T)🚀 Starting Agent Media...$(R)"
|
||||||
|
|||||||
+55
-32
@@ -1,47 +1,77 @@
|
|||||||
# Dockerfile for Agent Media
|
# Dockerfile for Agent Media
|
||||||
# Multi-stage build for smaller image size
|
# Multi-stage build for smaller image size
|
||||||
|
ARG PYTHON_VERSION
|
||||||
|
ARG PYTHON_VERSION_SHORT
|
||||||
|
ARG RUNNER
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# Stage 1: Builder
|
# Stage 1: Builder
|
||||||
# ===========================================
|
# ===========================================
|
||||||
FROM python:3.12.7-slim as builder
|
FROM python:${PYTHON_VERSION}-slim-bookworm as builder
|
||||||
|
|
||||||
# STFU (please)
|
# STFU - No need - Write logs asap
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
|
PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
# Install build dependencies (needs root)
|
# Install build dependencies (needs root)
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
build-essential \
|
build-essential \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install Poetry globally (needs root)
|
# Install runner globally (needs root) - Save cache for future
|
||||||
RUN pip install --no-cache-dir poetry
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip install $RUNNER
|
||||||
|
|
||||||
# Copy dependency files (as root for now)
|
# Set working directory for dependency installation
|
||||||
COPY pyproject.toml poetry.lock* /tmp/
|
WORKDIR /tmp
|
||||||
|
|
||||||
|
# Copy dependency files
|
||||||
|
COPY pyproject.toml poetry.lock* uv.lock* Makefile ./
|
||||||
|
|
||||||
# Install dependencies as root (to avoid permission issues with system packages)
|
# Install dependencies as root (to avoid permission issues with system packages)
|
||||||
WORKDIR /tmp
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
RUN poetry config virtualenvs.create false \
|
--mount=type=cache,target=/root/.cache/pypoetry \
|
||||||
&& poetry install --only main --no-root --no-cache
|
--mount=type=cache,target=/root/.cache/uv \
|
||||||
|
if [ "$RUNNER" = "poetry" ]; then \
|
||||||
# Create non-root user
|
poetry config virtualenvs.create false && \
|
||||||
RUN useradd -m -u 1000 -s /bin/bash appuser
|
poetry install --only main --no-root; \
|
||||||
|
elif [ "$RUNNER" = "uv" ]; then \
|
||||||
# Switch to non-root user
|
uv pip install --system -r pyproject.toml; \
|
||||||
USER appuser
|
fi
|
||||||
|
|
||||||
# Set working directory (owned by appuser)
|
|
||||||
WORKDIR /home/appuser/app
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# Stage 2: Runtime
|
# Stage 2: Testing
|
||||||
# ===========================================
|
# ===========================================
|
||||||
FROM python:3.12.7-slim as runtime
|
FROM builder as test
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
--mount=type=cache,target=/root/.cache/pypoetry \
|
||||||
|
--mount=type=cache,target=/root/.cache/uv \
|
||||||
|
if [ "$RUNNER" = "poetry" ]; then \
|
||||||
|
poetry install --no-root; \
|
||||||
|
elif [ "$RUNNER" = "uv" ]; then \
|
||||||
|
uv pip install --system -e .[dev]; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
COPY agent/ ./agent/
|
||||||
|
COPY application/ ./application/
|
||||||
|
COPY domain/ ./domain/
|
||||||
|
COPY infrastructure/ ./infrastructure/
|
||||||
|
COPY tests/ ./tests/
|
||||||
|
COPY app.py .
|
||||||
|
|
||||||
|
# ===========================================
|
||||||
|
# Stage 3: Runtime
|
||||||
|
# ===========================================
|
||||||
|
FROM python:${PYTHON_VERSION}-slim-bookworm as runtime
|
||||||
|
|
||||||
|
ENV LLM_PROVIDER=deepseek \
|
||||||
|
MEMORY_STORAGE_DIR=/data/memory \
|
||||||
|
PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONPATH=/home/appuser/app \
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
# Install runtime dependencies (needs root)
|
# Install runtime dependencies (needs root)
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
curl \
|
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& apt-get clean
|
&& apt-get clean
|
||||||
@@ -60,7 +90,7 @@ USER appuser
|
|||||||
WORKDIR /home/appuser/app
|
WORKDIR /home/appuser/app
|
||||||
|
|
||||||
# Copy Python packages from builder stage
|
# Copy Python packages from builder stage
|
||||||
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
COPY --from=builder /usr/local/lib/${PYTHON_VERSION_SHORT}/site-packages /usr/local/lib/${PYTHON_VERSION_SHORT}/site-packages
|
||||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||||
|
|
||||||
# Copy application code (already owned by appuser)
|
# Copy application code (already owned by appuser)
|
||||||
@@ -78,14 +108,7 @@ EXPOSE 8000
|
|||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
CMD curl -f http://localhost:8000/health || exit 1
|
CMD python -c "import requests; requests.get('http://localhost:8000/health', timeout=5).raise_for_status()" || exit 1
|
||||||
|
|
||||||
# Environment variables (can be overridden)
|
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
|
||||||
PYTHONDONTWRITEBYTECODE=1 \
|
|
||||||
PYTHONPATH=/home/appuser/app \
|
|
||||||
LLM_PROVIDER=deepseek \
|
|
||||||
MEMORY_STORAGE_DIR=/data/memory
|
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ addopts = [
|
|||||||
#"--cov-report=xml", # Génère un rapport XML (pour CI/CD)
|
#"--cov-report=xml", # Génère un rapport XML (pour CI/CD)
|
||||||
#"--cov-fail-under=80", # Échoue si coverage < 80%
|
#"--cov-fail-under=80", # Échoue si coverage < 80%
|
||||||
"-n=auto", # --numprocesses=auto : parallélise les tests (pytest-xdist)
|
"-n=auto", # --numprocesses=auto : parallélise les tests (pytest-xdist)
|
||||||
|
"--dist=loadscope", # Distribution strategy: group tests by module
|
||||||
"--strict-markers", # Erreur si un marker non déclaré est utilisé
|
"--strict-markers", # Erreur si un marker non déclaré est utilisé
|
||||||
"--disable-warnings", # Désactive l'affichage des warnings (sauf erreurs)
|
"--disable-warnings", # Désactive l'affichage des warnings (sauf erreurs)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./brain
|
context: ./brain
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
RUNNER: ${RUNNER} # Get it from Makefile
|
||||||
container_name: agent-brain
|
container_name: agent-brain
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
|||||||
Reference in New Issue
Block a user