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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"enableNonRootDocker": "true"
}
},
"postCreateCommand": "pip3 install --user -r requirements.txt",
"postCreateCommand": "pip3 install --user -r requirements.txt && curl -fsSL https://aka.ms/install-azd.sh | bash",
"customizations": {
"vscode": {
"extensions": [
Expand Down
38 changes: 20 additions & 18 deletions challenge-0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

**Expected Duration:** 30 minutes

Welcome to your very first challenge! Your goal in this challenge is to create the services and enviornment necessary to conduct this hackathon. You will deploy the required resources in Azure, create your development enviornment and all the assets necessary for the subsequent challenges. By completing this challenge, you will set up the foundation for the rest of the hackathon.
Welcome to your very first challenge! Your goal in this challenge is to create the services and enviornment necessary to conduct this hackathon. You will deploy the required resources in Azure, create your development enviornment and all the assets necessary for the subsequent challenges. By completing this challenge, you will set up the foundation for the rest of the hackathon.

If something is not working correctly, please do let your coach know!


## 1.1 Fork the Repository

Before you start, please fork this repository to your GitHub account by clicking the `Fork` button in the upper right corner of the repository's main screen (or follow the [documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo#forking-a-repository)). This will allow you to make changes to the repository and save your progress.


## 1.2 Development Environment

GitHub Codespaces is a cloud-based development environment that allows you to code from anywhere. It provides a fully configured environment that can be launched directly from any GitHub repository, saving you from lengthy setup times. You can access Codespaces from your browser, Visual Studio Code, or the GitHub CLI, making it easy to work from virtually any device.
Expand All @@ -24,40 +22,43 @@ Please select your forked repository from the dropdown and, if necessary, adjust

**NOTE:** If GitHub Codespaces is not enabled in your organization, you can enable it by following the instructions [here](https://docs.github.com/en/codespaces/managing-codespaces-for-your-organization/enabling-or-disabling-github-codespaces-for-your-organization), or, if you cannot change your GitHub organization's settings, create a free personal GitHub account [here](https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F&source=header-home). The Github Free Plan includes 120 core hours per month, equivalent to 60 hours on a 2-core machine, along with 15 GB of storage.


## 1.3 Resource Deployment Guide
The first step on this hackathon will be to create the resources we will use throughout the day. You can deploy using either the one-click button or manual method below.

Before anything else, let's log in into the CLI with our account. Please paste the code underneath and follow the necessary instructions.
We're now using the [Azure Developer CLI (azd)](https://learn.microsoft.com/azure/developer/azure-developer-cli/) to deploy the environment defined in `challenge-0/azure.yaml`. The Bicep template that provisions every resource lives in `challenge-0/infra/main.bicep`.

```bash
az login --use-device-code
```
### Prerequisites

## 1.3.1 Resources Deployment
- Install the Azure CLI and Azure Developer CLI (`azd`).
- Ensure you have the required Azure permissions to create resources and role assignments in your subscription.

Now, time to deploy our resources to Azure!
### Deploy with azd

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fmartaldsantos%2Fagentic-ai-hack%2Fmain%2Fchallenge-0%2Fiac%2Fazuredeploy.json)
From the repository root, run the following commands:

**Deployment Parameters:**
- servicePrincipalObjectId: Leave this field empty.
- resource group: Introduce the unique name for your resource group (example: rg-user01-yourinitials).
```powershell
azd auth login
azd env new <environment-name> --location swedencentral
azd up
```

**NOTE:** Some parts of your deployment may fail if the resource provider `Microsoft.AlertsManagement` is not registered in your. Follow the [documentation](https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-providers-and-types#register-resource-provider-1) to register it and the re-run the deployment.
- Replace `<environment-name>` with a friendly name (for example, `hackathon`).
- The `azd env new` command seeds environment configuration and prompts for the subscription and resource group name. The default location (`swedencentral`) aligns with the template.
- Create a new resource group when prompted (for example, `rg-aihackaton-<abc>` where `abc` are the first three letters of your last name).

Resource deployment can take up to 10 minutes, afterwards you'll be able to find most of the resources on your resource group.
The deployment usually completes within 10 minutes and creates all dependent role assignments automatically. If the deployment fails due to a missing resource provider (for example, `Microsoft.AlertsManagement`), register it and re-run `azd up`.

## 1.4 Verify the creation of your resources

Go back to your `Azure Portal` and find your `Resource Group`that should by now contain 9 resources and look like this:
Go back to your `Azure Portal` and find your `Resource Group` that should by now contain the storage account, Azure AI Foundry hub and project, Azure AI Search, Cosmos DB (serverless), Container Registry, Log Analytics workspace with Application Insights, and a Key Vault.

![alt text](image.png)

## 1.5 Let's retrieve the necessary keys

After deploying the resources, you will need to configure the environment variables in the `.env` file. Double check you have logged in into your Azure account on the CLI. If that's settled, let's move into retrieving our keys. The `.env` file is a configuration file that contains the environment variables for the application. The `.env` file is automatically created by running the following command within the terminal in your Codespace.

**Then run the get-keys script with your resource group name:**

```bash
cd challenge-0 && ./get-keys.sh --resource-group YOUR_RESOURCE_GROUP_NAME
```
Expand All @@ -75,6 +76,7 @@ The repo has an `.env.sample` file that shows the relevant environment variables
If the file is not created, simply copy over `.env.sample` to `.env` - then populate those values manually from the respective Azure resource pages using the Azure Portal.

## Conclusion

By reaching this section you should have every resource and installed the requirements necessary to conduct the hackathon. In the next challenges, you will use these services to start strongly your Azure AI Agents journey.

Now the real fun begins!
10 changes: 10 additions & 0 deletions challenge-0/azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: agentic-ai-hack-challenge-0
metadata:
template: challenge-0
infra:
provider: bicep
path: ./infra
template: main.bicep
parameters:
location: ${AZURE_LOCATION}
servicePrincipalObjectId: ${SERVICE_PRINCIPAL_OBJECT_ID:-''}
41 changes: 18 additions & 23 deletions challenge-0/get-keys.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#
# This script will retrieve necessary keys and properties from Azure Resources
# deployed using "Deploy to Azure" button and will store them in a file named
# ".env" in the parent directory.
# This script retrieves the keys and connection information emitted by the
# Challenge 0 infrastructure deployment (now managed via Azure Developer CLI)
# and stores them in a file named ".env" in the repository root.

# Login to Azure
if [ -z "$(az account show)" ]; then
Expand Down Expand Up @@ -30,12 +30,17 @@ fi

# Get resource group deployments, find deployments starting with 'Microsoft.Template' and sort them by timestamp
echo "Getting the deployments in '$resourceGroupName'..."
deploymentName=$(az deployment group list --resource-group $resourceGroupName --query "[?contains(name, 'Microsoft.Template') || contains(name, 'azuredeploy')].{name:name}[0].name" --output tsv)
deploymentName=$(az deployment group list --resource-group $resourceGroupName --query "sort_by([], &properties.timestamp)[-1].name" --output tsv)
if [ $? -ne 0 ]; then
echo "Error occurred while fetching deployments. Exiting..."
exit 1
fi

if [ -z "$deploymentName" ]; then
echo "No deployments found in resource group '$resourceGroupName'. Ensure 'azd up' completed successfully."
exit 1
fi

# Get output parameters from last deployment using Azure CLI queries instead of jq
echo "Getting the output parameters from the last deployment '$deploymentName' in '$resourceGroupName'..."

Expand Down Expand Up @@ -63,7 +68,7 @@ aiFoundryProjectEndpoint=$(az deployment group show --resource-group $resourceGr


# If deployment outputs are empty, try to discover resources by type
if [ -z "$storageAccountName" ] || [ -z "$logAnalyticsWorkspaceName" ] || [ -z "$apiManagementName" ] || [ -z "$keyVaultName" ] || [ -z "$containerRegistryName" ]; then
if [ -z "$storageAccountName" ] || [ -z "$logAnalyticsWorkspaceName" ] || [ -z "$keyVaultName" ] || [ -z "$containerRegistryName" ]; then
echo "Some deployment outputs not found, discovering missing resources by type..."

if [ -z "$storageAccountName" ]; then
Expand All @@ -78,10 +83,6 @@ if [ -z "$storageAccountName" ] || [ -z "$logAnalyticsWorkspaceName" ] || [ -z "
searchServiceName=$(az search service list --resource-group $resourceGroupName --query "[0].name" -o tsv 2>/dev/null || echo "")
fi

if [ -z "$apiManagementName" ]; then
apiManagementName=$(az apim list --resource-group $resourceGroupName --query "[0].name" -o tsv 2>/dev/null || echo "")
fi

if [ -z "$aiFoundryHubName" ]; then
aiFoundryHubName=$(az cognitiveservices account list --resource-group $resourceGroupName --query "[?kind=='AIServices'].name | [0]" -o tsv 2>/dev/null || echo "")
fi
Expand Down Expand Up @@ -243,8 +244,14 @@ echo "AI_FOUNDRY_HUB_NAME=\"$aiFoundryHubName\"" >> ../.env
echo "AI_FOUNDRY_PROJECT_NAME=\"$aiFoundryProjectName\"" >> ../.env
echo "AI_FOUNDRY_ENDPOINT=\"$aiFoundryEndpoint\"" >> ../.env
echo "AI_FOUNDRY_KEY=\"$aiFoundryKey\"" >> ../.env
acr_username=$(az acr credential show --name $containerRegistryName --query username -o tsv)
acr_password=$(az acr credential show --name $containerRegistryName --query passwords[0].value -o tsv)

if [ -n "$containerRegistryName" ]; then
acr_username=$(az acr credential show --name $containerRegistryName --query username -o tsv 2>/dev/null || echo "")
acr_password=$(az acr credential show --name $containerRegistryName --query passwords[0].value -o tsv 2>/dev/null || echo "")
else
acr_username=""
acr_password=""
fi
# Construct AI Foundry Hub Endpoint if missing
if [ -z "$aiFoundryHubEndpoint" ] && [ -n "$aiFoundryHubName" ]; then
echo "Constructing AI Foundry Hub Endpoint..."
Expand All @@ -256,17 +263,6 @@ if [ -z "$aiFoundryHubEndpoint" ] && [ -n "$aiFoundryHubName" ]; then
fi
echo "AI_FOUNDRY_HUB_ENDPOINT=\"$aiFoundryHubEndpoint\"" >> ../.env

# Construct AI Foundry Project Endpoint if not found in deployment outputs
if [ -z "$aiFoundryProjectEndpoint" ] && [ -n "$aiFoundryHubName" ] && [ -n "$aiFoundryProjectName" ]; then
echo "Constructing AI Foundry Project Endpoint..."
aiFoundryProjectEndpoint="https://${aiFoundryHubName}.services.ai.azure.com/api/projects/${aiFoundryProjectName}"
echo "Constructed project endpoint: $aiFoundryProjectEndpoint"
elif [ -n "$aiFoundryProjectEndpoint" ] && [[ "$aiFoundryProjectEndpoint" == *"ai.azure.com/build/overview"* ]]; then
# If we got a web UI URL from deployment outputs, convert it to API endpoint
echo "Converting web UI URL to API endpoint..."
aiFoundryProjectEndpoint="https://${aiFoundryHubName}.services.ai.azure.com/api/projects/${aiFoundryProjectName}"
echo "Converted project endpoint: $aiFoundryProjectEndpoint"
fi
echo "AI_FOUNDRY_PROJECT_ENDPOINT=\"$aiFoundryProjectEndpoint\"" >> ../.env
echo "AZURE_AI_CONNECTION_ID=\"$azureAIConnectionId\"" >> ../.env
# Azure Cosmos DB
Expand All @@ -289,7 +285,6 @@ echo "=== Configuration Summary ==="
echo "Storage Account: $storageAccountName"
echo "Log Analytics Workspace: $logAnalyticsWorkspaceName"
echo "Search Service: $searchServiceName"
echo "API Management: $apiManagementName"
echo "AI Foundry Hub: $aiFoundryHubName"
echo "AI Foundry Project: $aiFoundryProjectName"
echo "Key Vault: $keyVaultName"
Expand Down
Loading