Commit adef5c8c authored by Adriana Fernández-Fernández's avatar Adriana Fernández-Fernández
Browse files

Merge branch 'feature-REL0' into 'main'

Includes features for REL0

See merge request !1
parents bf5f3bf4 f562a243
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+91 −0
Original line number Diff line number Diff line
# Git files
.git
.gitignore
.gitlab-ci.yml

# Documentation
README.md
CONTRIBUTING.md
LICENSE

# Docker files
Dockerfile
docker-compose.yaml
.dockerignore

# Python cache and virtual environments
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
env.bak/
venv.bak/
.venv/
src/__pycache__/
src/models/__pycache__/
src/controllers/__pycache__/
src/clients/__pycache__/
src/test/__pycache__/
src/adapters/__pycache__/
src/api/__pycache__/
src/adapters/tf_adapter/__pycache__/
src/adapters/fm_adapter/__pycache__/

# Testing and coverage
.coverage
.pytest_cache/
htmlcov/
.tox/
.nox/
coverage.xml
*.cover
.hypothesis/

# IDE and editor files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Logs
*.log
logs/

# Temporary files
tmp/
temp/
*.tmp

# Node modules (if any)
node_modules/
npm-debug.log*

# Configuration files that shouldn't be in the image
src/conf/config.cfg
*.env
.env.local
.env.development
.env.test
.env.production

# Log files and directories
*.tgz
src/.log/

# Build artifacts
dist/
build/
 No newline at end of file
+0 −39
Original line number Diff line number Diff line
name: Build Docker Image

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

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

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

      - name: Log in to GitHub Container Registry (GHCR)
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Lowercase github.repository
        run: |
          echo "REPO_NAME=${GITHUB_REPOSITORY@L}" >> ${GITHUB_ENV}

      - name: Build Docker image
        run: |
          docker build -t ghcr.io/${{ env.REPO_NAME }}:0.0.1 .

      - name: Push Docker image
        run: |
          docker push ghcr.io/${{ env.REPO_NAME }}:0.0.1
+12 −0
Original line number Diff line number Diff line
@@ -9,3 +9,15 @@ src/test/__pycache__/

# Files
src/conf/config.cfg

*.tgz

src/.log/

src/adapters/__pycache__/

src/api/__pycache__/

src/adapters/tf_adapter/__pycache__/

src/adapters/fm_adapter/__pycache__/

.gitlab-ci.yml

0 → 100644
+52 −0
Original line number Diff line number Diff line
# GitLab CI/CD Pipeline for Federation Manager
# This pipeline builds and pushes Docker images for the federation-manager service

stages:
  - build

variables:
  IMAGE_NAME: federation-manager
  IMAGE_TAG: $CI_COMMIT_SHORT_SHA
  REGISTRY_IMAGE: $CI_REGISTRY_IMAGE/$IMAGE_NAME
  DOCKER_CONFIG: "/kaniko/.docker"

# Build Docker image for merge requests (no push)
build-mr:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  before_script:
    - echo "Skip pushing for merge requests"
  script:
    - echo "Building image for merge request validation..."
    - /kaniko/executor
        --context "$CI_PROJECT_DIR"
        --dockerfile "$CI_PROJECT_DIR/Dockerfile"
        --no-push
    - echo "Image built successfully for MR validation"
  only:
    - merge_requests

# Build and push Docker image for main branches
build-and-push:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  before_script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
  script:
    - echo "Building image and pushing to registry..."
    - /kaniko/executor
        --context "$CI_PROJECT_DIR"
        --dockerfile "$CI_PROJECT_DIR/Dockerfile"
        --destination "$REGISTRY_IMAGE:$IMAGE_TAG"
        --destination "$REGISTRY_IMAGE:latest"
        --cache=true
        --cache-ttl=24h
  only:
    - main
    - develop
    - tags

CI_CD_SETUP.md

0 → 100644
+140 −0
Original line number Diff line number Diff line
# GitLab CI/CD Setup for Federation Manager

This document explains how to set up and use the GitLab CI/CD pipeline for the Federation Manager project.

## Overview

The CI/CD pipeline includes a single stage with two different build jobs:
1. **Build (MR Validation)** - Builds Docker images for merge requests without pushing to registry
2. **Build and Push** - Builds Docker images and pushes them to the GitLab Container Registry for main branches

## Prerequisites

### GitLab Configuration

1. **Container Registry**: Ensure GitLab Container Registry is enabled for your project
2. **CI/CD Variables**: Configure the following variables in GitLab (Settings > CI/CD > Variables):

   | Variable | Description | Required |
   |----------|-------------|----------|
   | `CI_REGISTRY` | GitLab Container Registry URL | Auto-provided |
   | `CI_REGISTRY_USER` | Registry username | Auto-provided |
   | `CI_REGISTRY_PASSWORD` | Registry password | Auto-provided |

### Repository Setup

1. Ensure your GitLab project has a Container Registry enabled
2. The pipeline uses the project's Container Registry by default
3. Docker images will be tagged with commit SHA and 'latest'

## Pipeline Stages

### Build Stage

The build stage contains two different jobs depending on the trigger:

#### MR Build (build-mr)
- **Trigger**: On merge requests
- **Actions**:
  - Builds Docker image for validation
  - Tags with local name: `federation-manager:$CI_COMMIT_SHORT_SHA`
  - **Does NOT push to registry** (validation only)
  - No registry authentication required

#### Build and Push (build-and-push)
- **Trigger**: On main, develop branches, and tags
- **Actions**:
  - Builds Docker image
  - Tags with commit SHA and 'latest'
  - Pushes to GitLab Container Registry
  - Requires registry authentication

## Docker Image Information

### Image Naming Convention

#### Registry Images (build-and-push job)
- Registry: `$CI_REGISTRY_IMAGE/federation-manager`
- Tags:
  - `latest` - Latest build from main/develop branches
  - `$CI_COMMIT_SHORT_SHA` - Specific commit hash

#### Local Images (build-mr job)
- Local name: `federation-manager:$CI_COMMIT_SHORT_SHA`
- **Note**: These images are built locally for validation only and are NOT pushed to the registry

### Base Image
- Python 3.12 official image
- Includes system dependencies: bash, build-essential, git, wget, iptables, etc.
- Exposes port 8989
- Runs with Gunicorn (4 workers)

## Usage

### Triggering Builds

1. **Automatic triggers**:
   - **MR Build**: Create or update merge requests (builds for validation only)
   - **Build and Push**: Push to main or develop branches, create tags

2. **Manual triggers**:
   - Go to CI/CD > Pipelines in GitLab
   - Click "Run Pipeline"
   - Select branch/tag

### Build Types

#### Merge Request Validation
- **Purpose**: Validate that Docker builds work correctly before merging
- **Benefit**: Early feedback without affecting registry or consuming unnecessary resources
- **Output**: Local Docker image (not stored in registry)
- **Time**: Faster execution (no registry operations)

#### Production Builds
- **Purpose**: Create deployable images for main branches and releases
- **Output**: Images pushed to GitLab Container Registry
- **Accessibility**: Available for deployment and distribution

### Accessing Docker Images

**Note**: Only images from the `build-and-push` job are available in the registry. MR validation builds are local only.

1. **Pull from registry** (production images only):
   ```bash
   docker login registry.gitlab.com
   docker pull $CI_REGISTRY_IMAGE/federation-manager:latest
   ```

2. **Use in docker-compose**:
   ```yaml
   services:
     federation-manager:
       image: registry.gitlab.com/your-group/federation-manager/federation-manager:latest
   ```

### Monitoring Pipeline

- **Pipeline status**: GitLab project > CI/CD > Pipelines
- **Job logs**: Click on individual jobs to view logs
- **Coverage reports**: Available in merge request widgets
- **Container registry**: GitLab project > Packages & Registries > Container Registry

## Troubleshooting

### Common Issues

1. **Docker build fails**:
   - Check Dockerfile syntax
   - Verify all required files are present
   - Check .dockerignore doesn't exclude necessary files

2. **Registry push fails**:
   - Verify Container Registry is enabled
   - Check CI/CD variables are set correctly
   - Ensure sufficient permissions

3. **Build fails**:
   - Check Dockerfile syntax and build context
   - Verify all required files are present and not excluded by .dockerignore
   - Check Python 3.12 compatibility in requirements.txt
   - Ensure base image availability
Loading