Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aiopslab/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ qualitative_eval: false

# Flag to enable/disable printing the session
print_session: false

# Offline mode configuration (for environments with restricted network access)
# When enabled, images are loaded from local tar files instead of pulling from registries
offline_mode: false
images_dir: ./images # Directory containing pre-downloaded image tar files
20 changes: 20 additions & 0 deletions aiopslab/orchestrator/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from aiopslab.utils.status import *
from aiopslab.utils.critical_section import CriticalSection
from aiopslab.service.telemetry.prometheus import Prometheus
from aiopslab.paths import BASE_DIR
import time
import inspect
import asyncio
Expand All @@ -30,6 +31,25 @@ def __init__(self, results_dir=None):
self.kubectl = KubeCtl()
self.use_wandb = os.getenv("USE_WANDB", "false").lower() == "true"
self.results_dir = results_dir

# Configure offline mode if enabled in config
self._configure_offline_mode()

def _configure_offline_mode(self):
"""Configure offline image loading if enabled in config."""
try:
from aiopslab.config import Config
config_path = BASE_DIR / "config.yml"
if config_path.exists():
config = Config(config_path)
offline_mode = config.get("offline_mode", False)
images_dir = config.get("images_dir", "./images")

if offline_mode:
Helm.configure_offline_mode(enabled=True, images_dir=images_dir)
except Exception as e:
# Config file might not exist or other error, that's OK
pass

def init_problem(self, problem_id: str):
"""Initialize a problem instance for the agent to solve.
Expand Down
4 changes: 4 additions & 0 deletions aiopslab/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""AIOpsLab Plugins Package"""
102 changes: 102 additions & 0 deletions aiopslab/plugins/offline_images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Offline Images Plugin

This plugin enables AIOpsLab to work in environments with restricted or no internet access by loading pre-downloaded Docker images from local tar files into Kind clusters.

## Why Use This?

- **Network Restrictions**: Some environments don't have access to Docker Hub, GHCR, or other registries
- **Slow Networks**: Pulling large images repeatedly can be time-consuming
- **Reproducibility**: Pre-downloaded images ensure consistent versions across deployments

## Quick Start

### 1. Download Images (with internet access)

```bash
# Run this on a machine with internet access
./scripts/download_images.sh ./images
```

This will download all required images and save them as tar files.

### 2. Transfer Images (if needed)

Copy the `./images` directory to your target machine.

### 3. Configure AIOpsLab

Edit `aiopslab/config.yml`:

```yaml
# Enable offline mode
offline_mode: true
images_dir: ./images
```

### 4. Run as Usual

```bash
python cli.py
# or
python service.py
```

Images will be automatically loaded from local tars before deploying applications.

## Manual Usage

You can also use the ImageLoader programmatically:

```python
from aiopslab.plugins.offline_images import ImageLoader

# Initialize loader
loader = ImageLoader(images_dir="./images", cluster_name="kind")

# Load all images
count = loader.load_all_from_directory()
print(f"Loaded {count} images")

# Or load a specific image
loader.load_image_from_tar(Path("./images/nginx_latest.tar"))
```

## Tar File Naming Convention

Image tar files should be named in the format:
```
{registry}_{image_path}_{tag}.tar
```

Examples:
- `ghcr.io_open-telemetry_demo_1.11.1.tar`
- `docker.io_library_nginx_latest.tar`
- `quay.io_prometheus_prometheus_v2.47.2.tar`

The `download_images.sh` script handles this naming automatically.

## Supported Registries

- `ghcr.io` (GitHub Container Registry)
- `docker.io` (Docker Hub)
- `quay.io`
- `registry.k8s.io`
- `gcr.io` (Google Container Registry)

## Troubleshooting

### Images not loading

1. Check that the tar files exist in the images directory
2. Ensure Docker daemon is running
3. Verify Kind cluster is running: `kind get clusters`

### Image name mismatch

If an image fails to load, check that the tar filename follows the naming convention.
You can manually check the image name in a tar:

```bash
docker load -i image.tar
# Output: Loaded image: registry/image:tag
```
20 changes: 20 additions & 0 deletions aiopslab/plugins/offline_images/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""
Offline Images Plugin for AIOpsLab

This plugin enables offline/local image loading for Kind clusters,
which is useful in environments with restricted network access.

Usage:
1. Download images: ./scripts/download_images.sh ./images
2. Enable in config.yml:
offline_mode: true
images_dir: ./images
3. Run AIOpsLab as usual - images will be loaded from local tars
"""

from .image_loader import ImageLoader, ensure_images_loaded

__all__ = ["ImageLoader", "ensure_images_loaded"]
Loading