infra!: added CI/CD pipeline and made various improvements
This commit is contained in:
54
.gitea/workflows/ci.yml
Normal file
54
.gitea/workflows/ci.yml
Normal file
@@ -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
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
# 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=3.14.2
|
ARG PYTHON_VERSION
|
||||||
|
ARG PYTHON_VERSION_SHORT
|
||||||
ARG RUNNER
|
ARG RUNNER
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# Stage 1: Builder
|
# Stage 1: Builder
|
||||||
@@ -39,7 +40,27 @@ RUN --mount=type=cache,target=/root/.cache/pip \
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# Stage 2: Runtime
|
# Stage 2: Testing
|
||||||
|
# ===========================================
|
||||||
|
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
|
FROM python:${PYTHON_VERSION}-slim-bookworm as runtime
|
||||||
|
|
||||||
@@ -69,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)
|
||||||
|
|||||||
@@ -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)
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user