Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
55 changes: 55 additions & 0 deletions .devcontainer/Ollama/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": ".NET AI Workshop - Ollama",
"image": "mcr.microsoft.com/devcontainers/dotnet:9.0",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/azure-cli:1": {
"installBicep": true,
"version": "latest"
},
"ghcr.io/azure/azure-dev/azd:0": {
"version": "stable"
},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/prulloac/devcontainer-features/ollama:latest": {}
},
"customizations": {
"vscode": {
"extensions": [
"GitHub.copilot",
"ms-dotnettools.csdevkit",
"ms-azuretools.vscode-azure-github-copilot"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
17057,
11434
],
"portsAttributes": {
"17057": {
"protocol": "http",
"label": ".NET Aspire Dashboard"
},
"11434": {
"protocol": "http",
"label": "Ollama API"
}
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "sudo dotnet workload update && dotnet new install Microsoft.Extensions.AI.Templates && ollama pull all-minilm && ollama pull llama3.2 && ollama pull phi4-mini && cd src/start/GenAiLab && dotnet restore",
"postStartCommand": "",
Comment on lines +44 to +45
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postCreateCommand chains multiple operations with &&. If any intermediate command fails (e.g., ollama pull due to network issues), subsequent commands won't execute, but the container will still be created. Consider using postCreateCommand for critical setup only and moving optional operations to postStartCommand or using ; instead of && to ensure container creation succeeds even if non-critical commands fail.

Suggested change
"postCreateCommand": "sudo dotnet workload update && dotnet new install Microsoft.Extensions.AI.Templates && ollama pull all-minilm && ollama pull llama3.2 && ollama pull phi4-mini && cd src/start/GenAiLab && dotnet restore",
"postStartCommand": "",
"postCreateCommand": "sudo dotnet workload update && dotnet new install Microsoft.Extensions.AI.Templates && cd src/start/GenAiLab && dotnet restore",
"postStartCommand": "ollama pull all-minilm; ollama pull llama3.2; ollama pull phi4-mini",

Copilot uses AI. Check for mistakes.

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode",
"hostRequirements": {
"memory": "16gb",
"cpus": 4
},
// Open the starting solution when the container starts
"workspaceFolder": "/workspaces/ai-workshop",
"postAttachCommand": "code src/start/GenAiLab/GenAiLab.sln"
}
183 changes: 183 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# Running the .NET AI Workshop in GitHub Codespaces

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/dotnet-presentations/ai-workshop?quickstart=1)

This workshop provides full support for GitHub Codespaces, allowing you to run the entire lab without installing Docker or any other prerequisites on your local machine. This is particularly useful for users who:

- Can't install Docker on their machine
- Have corporate firewall or security restrictions
- Want to get started quickly without local setup
- Prefer a cloud-based development environment

## πŸš€ Quick Start

Click the badge above or follow these steps:

1. **Create a Codespace:**
- Navigate to https://github.com/dotnet-presentations/ai-workshop
- Click the **Code** button (green button)
- Select the **Codespaces** tab
- Click **Create codespace on main**

2. **Choose Configuration:**
- VS Code will prompt you to select a dev container configuration
- Choose **".NET AI Workshop"** for the standard configuration
- Or choose **".NET AI Workshop - Ollama"** if you want to use local AI models

3. **Wait for Setup:**
- The container will automatically install all dependencies
- This includes .NET 9.0, Docker-in-Docker, Azure CLI, and the AI templates
- Setup typically takes 3-5 minutes

4. **Start Building:**
- Once ready, the solution will open automatically in `src/start/GenAiLab/`
- Follow the workshop instructions starting from [Part 2](../Part%202%20-%20Project%20Creation/README.md)

## πŸ“‹ What's Included

Both dev container configurations include:

### Standard Configuration (`.devcontainer/devcontainer.json`)

**Best for:** Most users following the standard workshop path

**Includes:**
- βœ… .NET 9.0 SDK with Aspire workload
- βœ… Docker-in-Docker (for Qdrant vector database)
- βœ… Azure CLI and Azure Developer CLI
- βœ… GitHub CLI
- βœ… AI Web Chat template pre-installed
- βœ… VS Code extensions: GitHub Copilot, C# Dev Kit, Azure GitHub Copilot

**Use this if you:**
- Have a GitHub account for GitHub Models
- Plan to use Azure OpenAI
- Want to follow the workshop as designed

### Ollama Configuration (`.devcontainer/Ollama/devcontainer.json`)

**Best for:** Developers who want to work offline or use local models

**Includes everything from Standard Configuration, plus:**
- βœ… Ollama for running local LLMs
- βœ… Pre-pulled models: `llama3.2`, `phi4-mini`, `all-minilm`

**Use this if you:**
- Don't have a GitHub account
- Hit GitHub Models token limits
- Want to work completely offline
- Prefer using local models for privacy/security
- Want to experiment with different models

## πŸ—οΈ Starting Solution

The Codespace includes a pre-configured starting solution in `src/start/GenAiLab/`. This is a copy of the Part 2 GenAiLab project that you can use to follow along with the workshop.

The solution includes:
- **GenAiLab.Web**: Blazor web application with AI chat interface
- **GenAiLab.AppHost**: .NET Aspire orchestration for distributed applications
- **GenAiLab.ServiceDefaults**: Shared service defaults for Aspire projects

## πŸ”§ Working with the Codespace

### Running the Application

To run the AI Web Chat application in Codespaces:

```bash
cd src/start/GenAiLab
dotnet run --project GenAiLab.AppHost
```

The .NET Aspire dashboard will be automatically forwarded and accessible via the **Ports** tab in VS Code.

### Setting Up GitHub Models

1. Create a GitHub personal access token with **Models: Read-only** permission
2. Store it as a Codespace secret named `WORKSHOP_GITHUB_TOKEN`
3. Or set it as an environment variable in your terminal:
```bash
export WORKSHOP_GITHUB_TOKEN="your-token-here"
```

### Port Forwarding

Codespaces automatically forwards these ports:
- **17057**: .NET Aspire dashboard (Standard config)
- **17057**: .NET Aspire dashboard (Ollama config)
- **11434**: Ollama API (Ollama config only)

Access them via the **Ports** tab in VS Code.

## πŸ’‘ Tips for Codespaces

1. **Save Your Work**: Codespaces automatically saves your files, but make sure to commit and push your changes regularly.

2. **Stop When Done**: Stop your Codespace when not in use to conserve free hours (Settings β†’ Stop Codespace).

3. **Rebuild Container**: If something goes wrong, you can rebuild the container:
- Press `F1` or `Ctrl+Shift+P`
- Select "Codespaces: Rebuild Container"

4. **Switch Configurations**: To switch between Standard and Ollama configurations:
- Press `F1` or `Ctrl+Shift+P`
- Select "Codespaces: Add Dev Container Configuration Files"
- Choose the other configuration

5. **Performance**: Codespaces provides 4 vCPUs and 16GB RAM, which is sufficient for this workshop. For better performance, you can upgrade to a larger machine type in your Codespace settings.

## πŸ†š Codespaces vs Local Development

| Feature | Codespaces | Local Development |
|---------|-----------|-------------------|
| Setup Time | 3-5 minutes | 20-30 minutes |
| Prerequisites | None (all in cloud) | Docker, .NET 9.0, Visual Studio |
| Access | Any device with browser | Specific machine only |
| Cost | Free tier available | Free (local resources) |
| Performance | Cloud-based | Local machine dependent |

## πŸ”— Related Documentation

- [.NET Aspire Dev Containers](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/dev-containers)
- [GitHub Codespaces Documentation](https://docs.github.com/en/codespaces)
- [Workshop Part 1: Setup](../Part%201%20-%20Setup/README.md)
- [Workshop Part 2: Project Creation](../Part%202%20-%20Project%20Creation/README.md)

## πŸ› Troubleshooting

### Container Build Fails

If the container fails to build:
1. Check the build logs in the VS Code output panel
2. Try rebuilding: `F1` β†’ "Codespaces: Rebuild Container"
3. Ensure your GitHub account has access to the repository

### Docker Issues

Docker-in-Docker is pre-configured. If you encounter Docker issues:
```bash
sudo service docker status
sudo service docker start
```

### Ollama Models Not Loading

If Ollama models don't load in the Ollama configuration:
```bash
ollama list # Check available models
ollama pull llama3.2 # Manually pull a model
```

### Performance Issues

If the Codespace is slow:
1. Check your machine type: Settings β†’ Change machine type
2. Stop and restart the Codespace
3. Close unused browser tabs and applications

## πŸ“ž Getting Help

If you encounter issues:
1. Check the [GitHub Codespaces documentation](https://docs.github.com/en/codespaces)
2. Review the workshop [README](../README.md)
3. Open an issue in the [repository](https://github.com/dotnet-presentations/ai-workshop/issues)
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": ".NET AI Workshop",
"image": "mcr.microsoft.com/devcontainers/dotnet:9.0",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/azure-cli:1": {
"installBicep": true,
"version": "latest"
},
"ghcr.io/azure/azure-dev/azd:0": {
"version": "stable"
},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"GitHub.copilot",
"ms-dotnettools.csdevkit",
"ms-azuretools.vscode-azure-github-copilot"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
17057
],
"portsAttributes": {
"17057": {
"protocol": "http",
"label": ".NET Aspire Dashboard"
}
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "sudo dotnet workload update && dotnet new install Microsoft.Extensions.AI.Templates && cd src/start/GenAiLab && dotnet restore",
"postStartCommand": "",
Comment on lines +38 to +39
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postCreateCommand chains multiple operations with &&. If any intermediate command fails, subsequent commands won't execute, but the container will still be created. Consider using postCreateCommand for critical setup only and moving optional operations to postStartCommand or using ; instead of && to ensure container creation succeeds even if non-critical commands fail.

Suggested change
"postCreateCommand": "sudo dotnet workload update && dotnet new install Microsoft.Extensions.AI.Templates && cd src/start/GenAiLab && dotnet restore",
"postStartCommand": "",
"postCreateCommand": "sudo dotnet workload update && dotnet new install Microsoft.Extensions.AI.Templates",
"postStartCommand": "cd src/start/GenAiLab && dotnet restore",

Copilot uses AI. Check for mistakes.

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode",
"hostRequirements": {
"memory": "16gb",
"cpus": 4
},
// Open the starting solution when the container starts
"workspaceFolder": "/workspaces/ai-workshop",
"postAttachCommand": "code src/start/GenAiLab/GenAiLab.sln"
}
4 changes: 4 additions & 0 deletions .github/.devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Development Container Options

> **πŸ“ LOCATION UPDATE**: The primary devcontainer configuration has moved to `/.devcontainer/` for GitHub Codespaces support. This location is kept for backward compatibility with local VS Code dev containers.
>
> **For GitHub Codespaces**, use the configurations at [`/.devcontainer/`](../../.devcontainer/README.md)

[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/dotnet-presentations/ai-workshop)

This workshop provides two development container configurations to suit different needs:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'Part 6 - Deployment/**'
- 'Part 7 - MCP Server Basics/**'
- 'Part 8 - Enhanced MCP Server/**'
- 'src/start/**'
pull_request:
branches:
- main
Expand All @@ -17,6 +18,7 @@ on:
- 'Part 6 - Deployment/**'
- 'Part 7 - MCP Server Basics/**'
- 'Part 8 - Enhanced MCP Server/**'
- 'src/start/**'
workflow_dispatch:

jobs:
Expand All @@ -30,6 +32,9 @@ jobs:
dotnet-version: '9.0.x'
- solution: "Part 6 - Deployment/GenAiLab/GenAiLab.sln"
dotnet-version: '9.0.x'
# Codespaces starting solution
- solution: "src/start/GenAiLab/GenAiLab.sln"
dotnet-version: '9.0.x'
# No solution file exists for MyMcpServer; using project file directly
- solution: "Part 7 - MCP Server Basics/MyMcpServer/MyMcpServer.csproj"
dotnet-version: '9.0.x'
Expand Down
Loading