diff --git a/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/README.md b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/README.md index d7a7bbd..a978902 100644 --- a/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/README.md +++ b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/README.md @@ -1,44 +1,263 @@ # Getting Started with Copilot for Azure to Deploy to the Cloud -[Learning Objectives](#Learn) • [Prerequisites](#pre-req) • [Resources](#book) +Managing and deploying cloud resources has historically required developers to switch between various interfaces—integrated development environments (IDEs), command-line tools, Azure Portal dashboards, and third-party CI/CD solutions. This context switching interrupts workflows, multiplies sources of truth, and slows down delivery. With the rise of AI-powered developer tools, a new paradigm is emerging: agentic, autonomous AI collaborators that reside within the IDE, orchestrate across cloud and DevOps environments, and allow developers to command the cloud as simply as they manipulate code. -Learn cloud deployment with GitHub Copilot for Azure—your ultimate guide to streamlined cloud success. Begin by building a strong foundation to boost coding efficiency, then transition to effortless application deployment, leveraging Azure’s powerful scalability. Conclude with advanced troubleshooting techniques to ensure your applications are reliable and high-performing. With Copilot as your trusted assistant, you’ll confidently create, deploy, and manage top-tier applications, enhancing your cloud expertise at every stage. +This detailed hands-on workshop will guide developers through harnessing GitHub Copilot Agent Mode in GitHub Codespaces (also available to run in VS Code), integrated with the Azure Model Context Protocol (MCP) server. By the end of this session, you'll be able to set up GitHub Copilot’s Coding Agent, connect it to the Azure MCP server for secure, natural language–driven management of cloud infrastructure, and seamlessly complete tasks such as provisioning resources, retrieving secrets, diagnosing issues, and deploying applications from your IDE—directly on top of an existing database API codebase. -- **Who is this for**: Developers and Operations (ITPRO) +This workshop emphasizes how Copilot Agent Mode plus Azure MCP together alleviate pain points like context switching and fragmented workflows, providing developers with a unified, rapid, and secure cloud experience. + +- **Who is this for**: Developers, DevOps Engineers, and Operations (IT Pros) - **What you'll learn**: Gain a comprehensive understanding of GitHub Copilot for Azure through three key phases: learning, deployment, and troubleshooting. -- **What you'll build**: You’ll confidently build, deploy, and maintain high-quality applications. +- **What you'll build**: Confidently create, deploy, and maintain robust, scalable applications—powered by AI and optimized for the cloud. - +By the end of this workshop, you will: +- Master foundational concepts and best practices of GitHub Copilot for Azure. +- Implement applications on Azure with seamless integration and scalability. +- Use advanced tools to diagnose and resolve issues, ensuring reliable performance. -## Learning Objectives +## Prerequisite Reading +- [What is GitHub Copilot for Azure?](https://learn.microsoft.com/azure/developer/github-copilot-azure/introduction) +- [What is the Azure MCP Server?](https://learn.microsoft.com/azure/developer/azure-mcp-server/overview) -In this workshop, you will: +## Requirements +1. [GitHub Account](https://docs.github.com/get-started/start-your-journey/creating-an-account-on-github) +2. [GitHub Copilot Chat extension](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot): GitHub Copilot is an AI pair programmer tool that helps you write code faster and smarter. +3. [GitHub Copilot for Azure](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azure-github-copilot): GitHub Copilot for Azure is the @azure extension. It’s designed to help streamline the process of developing for Azure. You can ask @azure questions about Azure services or get help with tasks related to Azure and developing for Azure, all from within Visual Studio Code. +4. [Microsoft Azure Account](https://azure.microsoft.com/pricing/purchase-options/azure-account): Start building, deploying, and managing applications seamlessly across the cloud, on-premises, and edge environments with Azure's scalable and cost-efficient services. Try Azure free for up to 30 days with no upfront commitment—cancel anytime. +5. [Azure MCP Server Extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azure-mcp-server) -- Master foundational concepts and best practices of GitHub Copilot for Azure utilization. -- Implement applications on Azure with seamless integration and scalability. -- Use advanced tools to diagnose and resolve issues, ensuring reliable performance. +## 💪🏽 Exercise + +**Right-click the following Codespaces button to open your Codespace in a new tab:** + +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/Azure-Samples/msdocs-python-flask-webapp-quickstart) + +This hands-on workshop guides you through setting up and using GitHub Copilot Agent Mode in Visual Studio Code, integrated with the Azure MCP server, to streamline cloud resource management and deployment workflows. Participants will start with a prebuilt database API demo and learn how to interact with the Copilot Coding Agent directly from their IDE—assigning cloud-related tasks, provisioning infrastructure, retrieving secrets, diagnosing issues, and deploying applications—all without switching to the Azure Portal or CLI. + +### 🗒️ Section 1: Exploring & Configuring Your Project + +🎯 **Learning Goals** +- Set up the GitHub Copilot Coding Agent and the GitHub Copilot for Azure extensions +- Understand Agent Mode +- Connect to your Azure subscription + +In this first section we are going to set up our environment and get started with GitHub Copilot for Azure, understanding the capabilities and features available to us. + +Let's get started! + +1. Click the Copilot Chat icon in the top-right corner of the Codespace window: + +
+Open GitHub Copilot Chat +
+ +2. This is GitHub Copilot Chat and Agent Mode should be displayed by default in the bottom-left corner. Notice in the text box you can “add context,” which allows you to attach files, folders, and other items so Copilot can better understand your codebase. You can also choose the model. + +
+Agent view in Copilot Chat +
+ +3. If you have not already done so, install the [GitHub Copilot for Azure extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azure-github-copilot). + +**Note:** You will need to authenticate to your Azure subscription. You should be prompted when it's installed. If not, when you go to the next step you will receive a prompt. + +4. In the Copilot Chat window type `@Azure` and look at the list available. You will notice a list of slash commands that you can execute to quickly ask questions. Take time to try several. In the example below, Azure was queried for available tools in the extension. + +
+Output of Chat with @Azure extension +
+ +5. After you have explored the responses from Copilot, select the tool icon in the chat pane. It opens the extension tools. Review the tools available that you can enable and disable. + +
+View of Azure tools +
+ +In the above exercises we achieved the following: +- ✅ Configured Copilot Chat and installed the GitHub Copilot for Azure extension +- ✅ Queried the `@Azure` extension and explored features and tools + +Now that we have toured and configured our environment, we're going to add context and configure the Azure MCP Server. + +### 🗒️ Section 2: Configuring the Azure MCP Server and Using Agent Mode + +🎯 **Learning Goals** +- Set up the Azure MCP Server +- Deploy an application to Azure using Agent Mode + +The Azure MCP Server is an open implementation of the Model Context Protocol—a standardized interface for exposing external tools, data sources, and actions to AI agents, such as Copilot in Agent Mode. It functions as a middle layer between the agent (client) and your Azure environment, enabling secure, context-aware natural language management of cloud resources. + +Key points: +- Supports broad Azure services: App Configuration, Key Vault, Storage, Cosmos DB, SQL, Kubernetes, Azure Developer CLI (azd), Azure CLI, etc. +- Authentication: Uses Azure authentication flow; inherits RBAC and user scopes +- Command/Tool abstraction: Each Azure resource operation is exposed as a discrete tool, discoverable and invocable by Copilot +- Security: Enforces permissions, supports HTTPS, can be bound to Entra ID, follows least privilege principles + +Now we are going to build a simple Python application in Azure using Flask. -
+1. The Azure MCP Server extension should have installed with the GitHub Copilot for Azure extension. The Azure MCP Server should start by default. To test this, in the chat pane type: `List my Azure resources`. -## Prerequisites +
+Output of Azure subscription +
-- [GitHub Copilot Chat](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot): GitHub Copilot is an AI pair programmer tool that helps you write code faster and smarter. -- [.NET Install Tool](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.vscode-dotnet-runtime): This extension provides a unified way for other extensions like the C# and C# Dev Kit extensions to install local versions of the .NET Runtime, and machine-wide versions of the .NET SDK. Those extensions tell the .NET Install Tool when they would like a .NET SDK to be on the machine, and we install one for them if there's not already one that matches the SDK they need to run properly. Users can also install the .NET SDK themselves by reading below. -- [GitHub Copilot for Azure](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azure-github-copilot): GitHub Copilot for Azure is the @azure extension. It’s designed to help streamline the process of developing for Azure. You can ask @azure questions about Azure services or get help with tasks related to Azure and developing for Azure, all from within Visual Studio Code. -- [Microsoft Azure Account](https://azure.microsoft.com/pricing/purchase-options/azure-account): Start building, deploying, and managing applications seamlessly across the cloud, on-premises, and edge environments with Azure's scalable and cost-efficient services. Try Azure free for up to 30 days with no upfront commitment—cancel anytime. +**Note:** If the MCP server has not been started, you can configure it to do so by opening `Settings` in VS Code (or your Codespace), searching for `chat.mcp.autostart`, and selecting `newAndOutdated` to automatically start the extension. -
+2. Once we've confirmed that the MCP server is running, let's build a simple web app and deploy it to Azure. First, create a branch to work from. As we're using Agent Mode, we can give Copilot a list of requirements to fully deploy our app. Provide Agent Mode a detailed prompt. Copy and paste the prompt below into the chat window: -## 🗃️ Lessons -| | Lesson Link | Concepts Taught | Learning Goal | -| :---: | :------------------------------------: | :---------------------------------------------------------: | ----------------------------------------------------------- | -| 01 | [Getting Started with GitHub Copilot for Azure](https://github.com/microsoft/Mastering-GitHub-Copilot-for-Paired-Programming/blob/main/09-Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/01-Getting-Started-with-GitHub-Copilot-for-Azure.md) | Unlock seamless coding and boost productivity with GitHub Copilot for Azure Preview.| This guide covers setup, installation in Visual Studio Code, and crafting your first prompt to harness Azure’s full potential effortlessly. | -| 02 | [Build and deploy your application with GitHub Copilot for Azure Preview](https://github.com/microsoft/Mastering-GitHub-Copilot-for-Paired-Programming/blob/main/09-Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/02-Build-and-deploy-your-application-with-GitHub-Copilot-for-Azure.md) | Integrate GitHub Copilot for Azure into your development and deployment workflow | Learn how to use GitHub Copilot for Azure Preview to create and deploy a website, showcasing its integration into your development and deployment workflow. | -| 03 | [Get answers to your questions about Azure services and resources](https://github.com/microsoft/Mastering-GitHub-Copilot-for-Paired-Programming/blob/main/09-Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/03-Get-Answers-to-your-Questions-about-Azure-Services-and-Resources.md) | Begin with open-ended questions about your Azure services or resources, then refine with specifics like technologies or features for better answers. | In this exercise, explore Azure’s potential for your application using example prompts to guide your queries effectively. | +``` +There is a Python web app in this repo. Please help me build and deploy it to Azure. +- Use Azure App Service for hosting. +- Create a new resource group with the name `RG-flaskapp` +- Set up any required Azure resources (App Service Plan basic, Storage, etc.). Use the naming convention of `flaskapp` +- Configure environment variables from my `.env` file as application settings. +- Build the app and deploy it. +- Finally, return the deployed app’s public URL. +``` -## :books: Resources +Copilot will work through the prompt. It will look to understand what was asked, and in the example below it referenced Azure best practices to help itself better execute the request. +Using Agent Mode and the Azure MCP Server, Copilot was able to achieve: + +**Build and Deploy Code:** +- Python environment setup +- Installation of application dependencies +- Authentication to Azure using service principal credentials +- Deployment to Azure Web App using the azure/webapps-deploy action + +**Azure Resources Deployed:** +- Resource Group: RG-flaskapp +- App Service Plan (Basic tier) +- App Service named flaskapp +- Environment variables configured as App Settings + +**Security and Authentication:** +- Requires `AZURE_CREDENTIALS` secret in GitHub repository +- Uses service principal authentication to Azure +- Deployment happens in a 'Production' environment with URL tracking + +3. Next, let’s take it a step further by asking Copilot to create a workflow file for us. This sets up CI/CD (Continuous Integration and Delivery) to Azure—with testing and deployment tracking built in—making deployments smoother and more reliable. In the chat window, type or copy: `Write a GitHub Actions workflow to deploy my Python app to Azure, include testing for CI/CD`. + +Copilot provided the following workflow. Review and accept the changes (or prompt Copilot to remediate if needed): + +```yaml +name: Python Flask CI/CD + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_dispatch: + +env: + AZURE_WEBAPP_NAME: flaskapp + PYTHON_VERSION: '3.10' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest pytest-cov + + - name: Run tests with pytest + run: | + pytest --cov=./ --cov-report=xml + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + with: + file: ./coverage.xml + flags: unittests + + build-and-deploy: + needs: test + runs-on: ubuntu-latest + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Log in to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ env.AZURE_WEBAPP_NAME }} + package: . +``` + +This workflow file includes the following capabilities: +- Testing job: Runs on every push and pull request to `main`, sets up Python 3.10, installs dependencies and testing tools, runs pytest with coverage reporting, uploads coverage reports to Codecov. +- Build and deploy job: Only runs after tests pass; sets up Python environment, installs dependencies, logs into Azure using credentials, deploys to Azure Web App. + +4. There are many tasks you can complete with Copilot. Here are some sample ideas: + +- Connect a database to your app using PostgreSQL +- Add a user sign-in to your Python web app +- Run your Python app in a container +- Add monitoring by enabling Application Insights +- Secure secrets by storing connection strings in Azure Key Vault +- Query Azure to perform cloud cost optimization (identify and remove unused resources) or ask Copilot for estimated costs of provisioned resources +- Ask Copilot to review security best practices for the application’s Azure setup +- Create an architecture diagram from the deployment + +🚀 Congratulations! You’ve just leveled up by using GitHub Copilot with Azure MCP to code, deploy, and manage cloud resources—all without leaving your IDE. + +In the above exercises we achieved the following: +- ✅ Enabled Azure MCP Server +- ✅ Used Agent Mode to clearly define tasks +- ✅ Created a CI/CD workflow, including tests +- ✅ Reviewed advanced use cases for GitHub Copilot Chat with the Azure MCP Server + +[Check out the other learning pathways in this repository.](#useful-links-and-further-learning) + +### Useful Links and Further Learning - [Blog: Introducing GitHub Copilot for Azure: Your Cloud Coding Companion in VS Code!](https://techcommunity.microsoft.com/t5/microsoft-developer-community/introducing-github-copilot-for-azure-your-cloud-coding-companion/ba-p/4127644) - [Blog: GitHub Copilot for Azure: 6 Must-Try Features](https://techcommunity.microsoft.com/t5/microsoft-developer-community/github-copilot-for-azure-6-must-try-features/ba-p/4283126) - [Video: GitHub Copilot for Azure: 6 Must-Try Features](https://youtube.com/playlist?list=PLlrxD0HtieHgdwrN6ooxApdfBKTJK7465&si=9rl-kNItvFPeqhwa) - [Video: Build intelligent apps with Visual Studio Code, GitHub, and Azure](https://youtu.be/30OpmbWL1t8?si=FvkRqa-wxTHaU3qA&t=1024) + +## Legal Notices + +Microsoft and any contributors grant you a license to the Microsoft documentation and other content +in this repository under the [Creative Commons Attribution 4.0 International Public License](https://creativecommons.org/licenses/by/4.0/legalcode), +see the [LICENSE](LICENSE) file, and grant you a license to any code in the repository under the [MIT License](https://opensource.org/licenses/MIT), see the +[LICENSE-CODE](LICENSE-CODE) file. + +Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation +may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. +The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. +Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653. + +Privacy information can be found at https://privacy.microsoft.com/en-us/. + +Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, +or trademarks, whether by implication, estoppel or otherwise. \ No newline at end of file diff --git a/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/001-chat.jpg b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/001-chat.jpg new file mode 100644 index 0000000..159b8db Binary files /dev/null and b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/001-chat.jpg differ diff --git a/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/002-agentview.jpg b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/002-agentview.jpg new file mode 100644 index 0000000..0635a8f Binary files /dev/null and b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/002-agentview.jpg differ diff --git a/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/003-azuretools.jpg b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/003-azuretools.jpg new file mode 100644 index 0000000..ddbb561 Binary files /dev/null and b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/003-azuretools.jpg differ diff --git a/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/004-tools.jpg b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/004-tools.jpg new file mode 100644 index 0000000..5c4406a Binary files /dev/null and b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/004-tools.jpg differ diff --git a/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/005-MCPquery.jpg b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/005-MCPquery.jpg new file mode 100644 index 0000000..ad635ae Binary files /dev/null and b/Using-GitHub-Copilot-for-Azure-to-Deploy-to-Cloud/images/005-MCPquery.jpg differ