Skip to content

Commit a713655

Browse files
Add container functionality
1 parent c879815 commit a713655

File tree

9 files changed

+1098
-85
lines changed

9 files changed

+1098
-85
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Docker-related files
2+
.env
3+
output/
4+
*.log
5+
6+
# Python cache
7+
__pycache__/
8+
*.pyc
9+
*.pyo
10+
11+
# Migration output
12+
migration_*.json
13+
agent_*.json
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# V1 to V2 Migration Environment Configuration
2+
# Copy this file to .env and fill in your values
3+
4+
# Azure Project Configuration (choose one method)
5+
# Method 1: Project Endpoint
6+
PROJECT_ENDPOINT_URL=https://your-project-name.cognitiveservices.azure.com
7+
8+
# Method 2: Project Connection String
9+
# PROJECT_CONNECTION_STRING=endpoint=https://your-project.cognitiveservices.azure.com;subscriptionid=your-sub-id;resourcegroupname=your-rg;projectname=your-project
10+
11+
# Cosmos DB Configuration (optional - for Cosmos input/output)
12+
# COSMOS_DB_CONNECTION_STRING=AccountEndpoint=https://your-cosmos.documents.azure.com:443/;AccountKey=your-key==;
13+
# COSMOS_DB_DATABASE_NAME=assistants
14+
# COSMOS_DB_CONTAINER_NAME=v1_assistants
15+
16+
# OpenAI v1 API Configuration (optional - for v1 API input)
17+
# ASSISTANT_API_BASE=https://api.openai.com/v1
18+
# ASSISTANT_API_KEY=sk-your-openai-key
19+
# ASSISTANT_API_VERSION=v1
20+
21+
# Azure OpenAI v1 Configuration (optional - alternative to OpenAI)
22+
# ASSISTANT_API_BASE=https://your-aoai.openai.azure.com
23+
# ASSISTANT_API_KEY=your-azure-openai-key
24+
# ASSISTANT_API_VERSION=2024-02-15-preview
25+
26+
# v2 API Configuration (optional - for v2 API output)
27+
# V2_API_BASE=https://your-v2-api.cognitiveservices.azure.com
28+
# V2_API_KEY=your-v2-api-key
29+
# V2_API_VERSION=2024-05-01-preview
30+
31+
# Azure Authentication (optional - for service principal auth)
32+
# AZURE_TENANT_ID=your-tenant-id
33+
# AZURE_CLIENT_ID=your-client-id
34+
# AZURE_CLIENT_SECRET=your-client-secret
35+
# AZURE_SUBSCRIPTION_ID=your-subscription-id
36+
# AZURE_RESOURCE_GROUP=your-resource-group
37+
# AZURE_PROJECT_NAME=your-project-name
38+
39+
# Example configurations for common scenarios:
40+
41+
# Scenario 1: Migrate from Azure AI Project to v2 API
42+
# PROJECT_ENDPOINT_URL=https://myproject-eastus.cognitiveservices.azure.com
43+
# V2_API_BASE=https://myproject-v2-eastus.cognitiveservices.azure.com
44+
# V2_API_KEY=your-v2-key
45+
46+
# Scenario 2: Migrate from OpenAI to Cosmos DB
47+
# ASSISTANT_API_BASE=https://api.openai.com/v1
48+
# ASSISTANT_API_KEY=sk-your-key
49+
# COSMOS_DB_CONNECTION_STRING=AccountEndpoint=https://...;AccountKey=...;
50+
51+
# Scenario 3: Migrate from Cosmos DB to Azure AI Project v2
52+
# COSMOS_DB_CONNECTION_STRING=AccountEndpoint=https://...;AccountKey=...;
53+
# PROJECT_ENDPOINT_URL=https://myproject.cognitiveservices.azure.com
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Use Python 3.11 slim image
2+
FROM python:3.11-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
curl \
10+
gnupg \
11+
lsb-release \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Install Azure CLI
15+
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
16+
17+
# Copy requirements file
18+
COPY requirements.txt .
19+
20+
# Install Python dependencies from requirements.txt
21+
RUN pip install -r requirements.txt
22+
23+
# Copy the migration script and supporting files
24+
COPY v1_to_v2_migration.py .
25+
COPY read_cosmos_data.py .
26+
27+
# Create a non-root user for security
28+
RUN useradd -m -u 1000 migration && chown -R migration:migration /app
29+
30+
# Create Azure CLI directory with proper permissions for the migration user
31+
RUN mkdir -p /home/migration/.azure && chown -R migration:migration /home/migration/.azure
32+
33+
# Switch to migration user
34+
USER migration
35+
36+
# Set environment variables
37+
ENV PYTHONUNBUFFERED=1
38+
ENV PYTHONPATH=/app
39+
ENV AZURE_CONFIG_DIR=/home/migration/.azure
40+
41+
# Default command
42+
ENTRYPOINT ["python", "v1_to_v2_migration.py"]
43+
CMD ["--help"]
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# V1 to V2 Agent Migration - Docker Container
2+
3+
This directory contains the containerized version of the v1 to v2 agent migration script.
4+
5+
## Quick Start
6+
7+
### Prerequisites
8+
- Docker installed and running
9+
- Azure CLI installed and authenticated (`az login`)
10+
- Access to source data (Cosmos DB, API, or Project)
11+
12+
### Build and Run
13+
14+
#### Option 1: Using the helper scripts (Recommended)
15+
16+
**Linux/macOS:**
17+
```bash
18+
# Make the script executable
19+
chmod +x run-migration.sh
20+
21+
# Run migration with arguments
22+
./run-migration.sh --help
23+
./run-migration.sh --use-api --use-v2-api
24+
./run-migration.sh asst_abc123 --project-connection-string "eastus.api.azureml.ms;...;...;..."
25+
```
26+
27+
**Windows:**
28+
```cmd
29+
# Run migration with arguments
30+
run-migration.bat --help
31+
run-migration.bat --use-api --use-v2-api
32+
run-migration.bat asst_abc123 --project-connection-string "eastus.api.azureml.ms;...;...;..."
33+
```
34+
35+
#### Option 2: Using Docker directly
36+
37+
```bash
38+
# Build the image
39+
docker build -t v1-to-v2-migration .
40+
41+
# Run with arguments
42+
docker run --rm -it \
43+
--network host \
44+
-v ~/.azure:/home/migration/.azure:ro \
45+
-v "$(pwd)/output:/app/output" \
46+
-e COSMOS_CONNECTION_STRING \
47+
v1-to-v2-migration --help
48+
```
49+
50+
#### Option 3: Using Docker Compose
51+
52+
```bash
53+
# Create .env file from example
54+
cp .env.example .env
55+
# Edit .env with your values
56+
57+
# Run with Docker Compose
58+
docker-compose run --rm v1-to-v2-migration --help
59+
docker-compose run --rm v1-to-v2-migration --use-api --use-v2-api
60+
```
61+
62+
## Configuration
63+
64+
### Environment Variables
65+
66+
The container supports all the same environment variables as the standalone script:
67+
68+
- `COSMOS_CONNECTION_STRING`: Cosmos DB connection string
69+
- `AGENTS_HOST`: API host (default: eastus.api.azureml.ms)
70+
- `AGENTS_SUBSCRIPTION`: Azure subscription ID
71+
- `AGENTS_RESOURCE_GROUP`: Resource group for v1 API
72+
- `AGENTS_RESOURCE_GROUP_V2`: Resource group for v2 API
73+
- `AGENTS_WORKSPACE`: Workspace for v1 API
74+
- `AGENTS_WORKSPACE_V2`: Workspace for v2 API
75+
- `AGENTS_API_VERSION`: API version (default: 2025-05-15-preview)
76+
- `AZ_TOKEN`: Optional Azure token (will use Azure CLI if not provided)
77+
78+
### Volume Mounts
79+
80+
- `~/.azure:/home/migration/.azure:ro`: Azure CLI configuration (read-only)
81+
- `./output:/app/output`: Output directory for logs and results
82+
83+
## Usage Examples
84+
85+
### Test Tool Injection
86+
```bash
87+
# Test all tool types
88+
./run-migration.sh --add-test-function --add-test-mcp --add-test-computer --add-test-imagegen --add-test-azurefunction --use-api
89+
90+
# Test specific tool combinations
91+
./run-migration.sh --add-test-mcp --add-test-computer --project-connection-string "eastus.api.azureml.ms;...;...;..."
92+
```
93+
94+
### Migration Workflows
95+
```bash
96+
# Migrate all assistants from API to v2 API
97+
./run-migration.sh --use-api --use-v2-api
98+
99+
# Migrate specific assistant from Cosmos DB to Cosmos DB
100+
./run-migration.sh asst_abc123
101+
102+
# Migrate from project connection to v2 API
103+
./run-migration.sh --project-connection-string "eastus.api.azureml.ms;...;...;..." --use-v2-api
104+
```
105+
106+
## Features
107+
108+
**Complete Migration Pipeline**: All 4 input methods, 2 output methods
109+
**Tool Testing**: 5 different test tool types for validation
110+
**Azure CLI Integration**: Automatic token management
111+
**Security**: Non-root user, read-only mounts
112+
**Cross-Platform**: Works on Linux, macOS, and Windows
113+
**Flexible Configuration**: Environment variables, volume mounts
114+
**Network Access**: Host networking for localhost v2 API access
115+
116+
## Troubleshooting
117+
118+
### Docker Issues
119+
- Ensure Docker is running: `docker info`
120+
- Check image build: `docker images | grep v1-to-v2-migration`
121+
122+
### Authentication Issues
123+
- Verify Azure CLI: `az account show`
124+
- Check token: `az account get-access-token --scope https://ai.azure.com/.default`
125+
126+
### Network Issues
127+
- For localhost v2 API, ensure `--network host` is used
128+
- Check firewall settings for container network access
129+
130+
### Permission Issues
131+
- Ensure Azure CLI config is readable: `ls -la ~/.azure`
132+
- Check output directory permissions: `ls -la ./output`
133+
134+
## Development
135+
136+
To modify the container:
137+
138+
1. Edit the migration script: `v1_to_v2_migration.py`
139+
2. Update dependencies: `requirements.txt`
140+
3. Rebuild the image: `docker build -t v1-to-v2-migration .`
141+
4. Test changes: `./run-migration.sh --help`

0 commit comments

Comments
 (0)