# gitlabhq/gitlab-runner architecture

> Architecture diagram of the GitHub repository gitlabhq/gitlab-runner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gitlabhq/gitlab-runner
- Repository: https://github.com/gitlabhq/gitlab-runner

## Overview

##### Main Components

a. Core Components:
- Runner Service (main coordinator)
- Executors Layer
- Network Communication Layer
- Cache System
- Session Management
- Shell Execution Layer

b. Executor Types (show as parallel components):
- Docker
- Kubernetes
- Shell
- SSH
- VirtualBox
- Parallels
- Custom
- Instance
- Docker Machine (autoscaling)

c. Supporting Systems:
- Secret Management (Vault, Azure Key Vault, GCP Secret Manager, etc.)
- Logging System
- Metrics & Monitoring
- Configuration Management

##### Component Relationships

a. Primary Flow:
**GitLab Server <-> Network Layer <-> Runner Service <-> Executor Layer <-> Job Execution**

b. Secondary Flows:
- Cache System interactions with various cloud providers (S3, GCS, Azure)
- Secret resolution flow through different providers
- Session proxy for interactive terminals
- Helper container interactions for Docker/Kubernetes executors

##### Detailed Component Breakdown

a. Runner Service:
- Configuration Management
- Job Coordination
- Build Management
- Cache Coordination
- Security & Authentication

b. Executor Layer:
- Abstract Executor Interface
- Executor-specific Implementations
- Build Steps Management
- Shell Command Generation
- Container Management (for container-based executors)

c. Network Layer:
- API Client
- Job Status Updates
- Artifact Transfer
- Cache Transfer
- Rate Limiting

##### Implementation Details

a. Key Technologies (include as annotations):
- Go (primary language)
- gRPC (for helper communication)
- Docker API
- Kubernetes API
- Cloud Provider SDKs

b. Configuration Elements:
- config.toml settings
- Environment variables
- Feature flags
- Runtime configuration

##### Operational Aspects

a. Monitoring Points:
- Prometheus metrics
- Logging endpoints
- Health checks
- Performance monitoring

b. Management Interfaces:
- CLI commands
- API endpoints
- Status reporting

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core
        RS[Runner Service]:::core
        EL[Executors Layer]:::core
        NCL[Network Layer]:::core
        CS[Cache System]:::core
        SM[Session Management]:::core
        SEL[Shell Execution Layer]:::core
    end

    subgraph Executors
        DE[Docker]:::executor
        KE[Kubernetes]:::executor
        SE[Shell]:::executor
        SSHE[SSH]:::executor
        VBE[VirtualBox]:::executor
        PE[Parallels]:::executor
        CE[Custom]:::executor
        DME[Docker Machine]:::executor
    end

    subgraph "Supporting Systems"
        SecM[Secret Management]:::support
        LS[Logging System]:::support
        MM[Metrics & Monitoring]:::support
        CM[Configuration Management]:::support
        BM[Build Management]:::support
    end

    subgraph "Cache Providers"
        S3[S3 Cache]:::cache
        GCS[GCS Cache]:::cache
        AZ[Azure Cache]:::cache
    end

    GS[GitLab Server]:::external

    GS <--> NCL
    NCL <--> RS
    RS --> EL
    RS --> CS
    RS --> SM
    RS --> SEL

    EL --> DE
    EL --> KE
    EL --> SE
    EL --> SSHE
    EL --> VBE
    EL --> PE
    EL --> CE
    EL --> DME

    CS --> S3
    CS --> GCS
    CS --> AZ

    RS --> SecM
    RS --> LS
    RS --> MM
    RS --> CM
    RS --> BM

    %% Click Events
    click RS "https://github.com/gitlabhq/gitlab-runner/tree/main/commands"
    click EL "https://github.com/gitlabhq/gitlab-runner/tree/main/executors"
    click NCL "https://github.com/gitlabhq/gitlab-runner/tree/main/network"
    click CS "https://github.com/gitlabhq/gitlab-runner/tree/main/cache"
    click SM "https://github.com/gitlabhq/gitlab-runner/tree/main/session"
    click SEL "https://github.com/gitlabhq/gitlab-runner/tree/main/shells"
    click DE "https://github.com/gitlabhq/gitlab-runner/tree/main/executors/docker"
    click KE "https://github.com/gitlabhq/gitlab-runner/tree/main/executors/kubernetes"
    click SE "https://github.com/gitlabhq/gitlab-runner/tree/main/executors/shell"
    click SSHE "https://github.com/gitlabhq/gitlab-runner/tree/main/executors/ssh"
    click VBE "https://github.com/gitlabhq/gitlab-runner/tree/main/executors/virtualbox"
    click PE "https://github.com/gitlabhq/gitlab-runner/tree/main/executors/parallels"
    click CE "https://github.com/gitlabhq/gitlab-runner/tree/main/executors/custom"
    click SecM "https://github.com/gitlabhq/gitlab-runner/tree/main/helpers/secrets"
    click LS "https://github.com/gitlabhq/gitlab-runner/tree/main/log"
    click MM "https://github.com/gitlabhq/gitlab-runner/tree/main/helpers/prometheus"
    click CM "https://github.com/gitlabhq/gitlab-runner/tree/main/common/config"
    click BM "https://github.com/gitlabhq/gitlab-runner/tree/main/common/buildlogger"
    click S3 "https://github.com/gitlabhq/gitlab-runner/tree/main/cache/s3"
    click GCS "https://github.com/gitlabhq/gitlab-runner/tree/main/cache/gcs"
    click AZ "https://github.com/gitlabhq/gitlab-runner/tree/main/cache/azure"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef executor fill:#2ecc71,stroke:#27ae60,color:white
    classDef support fill:#f1c40f,stroke:#f39c12,color:black
    classDef cache fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Executors]:::executor
        L3[Supporting Systems]:::support
        L4[Cache Systems]:::cache
        L5[External Systems]:::external
    end
```
