GreenLoop IT Solutions : Articles
Automation Course Part 10 – CI/CD with VSCode, github, and Azure Functions
Up to this point we’ve covered how to interact with REST APIs (1, 2, 3, 4, 5), create Azure Functions to do serverless compute via API calls (6, 7) store secrets securely in Azure KeyVaults (8), and store the data you’re working with in Azure storage accounts (9).
The next step in developing a mature MSP automation capability is the ability to do version control and continuous deployment. this enables you to deploy code at scale, manage dependencies, collaborate and ensure code stability. [See Why Use Version Control? (git-tower.com)]
In this knowledge-base, we will discuss how to develop a CI/CD (Continuous Integration/Continuous Deployment) pipeline between Visual Studio Code, GitHub, and Azure Functions. This process will help streamline the development and deployment process of Azure Functions, making it easier to manage changes, collaborate with other developers, and deploy code quickly and efficiently.
Before beginning, make sure you have Visual Studio Code installed and have a GitHub account with access to create Repositories in your organization.
Step 1: Setting Up a GitHub Repository
The first step in this process is to set up a GitHub repository to store your code. This repository will serve as the central location for your codebase and will be used to manage all changes and updates. You can create a new repository or use an existing one.
Step 2: Creating an Azure Function App
The next step is to create an Azure Function App in the Azure portal. You can choose the appropriate hosting plan, runtime stack, and storage account based on your requirements. Once the function app is created, you will need to copy the Function App URL and Function Key for later use.
Step 3: Installing Visual Studio Code Extensions
To integrate Visual Studio Code with GitHub and Azure Functions, you will need to install a few extensions. These extensions include:
• GitHub Pull Requests and Issues: This extension provides an easy way to manage GitHub pull requests and issues directly from Visual Studio Code.
• Azure Functions: This extension provides tools for developing and deploying Azure Functions from within Visual Studio Code.
Step 4: Creating an Azure Functions Project in Visual Studio Code
After installing the required extensions, you can create a new Azure Functions project in Visual Studio Code. Open the Command Palette (Ctrl+Shift+P) and select “Azure Functions: Create New Project”. Follow the prompts to create a new project and select the appropriate programming language and runtime stack. More here.
Step 5: Configuring GitHub Integration
Next, you will need to configure the GitHub integration with Visual Studio Code. Open the Source Control panel and select the “Initialize Repository” button. Then, select “GitHub” as the source control provider and sign in to your GitHub account. You can then select the repository you created in Step 1.
Step 6: Developing and Testing Azure Functions
With the project set up and GitHub integration configured, you can now start developing and testing your Azure Functions locally in Visual Studio Code. Use the Azure Functions extension to create new functions, edit existing ones, and test them using the integrated Azure Functions Core Tools.
Step 7: Creating a CI/CD Pipeline
Once your code is ready for deployment, you can create a CI/CD pipeline using Azure DevOps or another continuous integration and deployment service. This pipeline will automatically build, test, and deploy your code to the Azure Function App whenever changes are made to the GitHub repository.
Step 8: Configuring Azure Function App Settings
Finally, you will need to configure the settings for your Azure Function App. In the Azure portal, navigate to the “Configuration” section of your Function App and add any necessary application settings, connection strings, or other environment variables. Configuration settings