GitHub Copilot Customization Explained for Beginners: Instructions, Prompt Files, Skills, Agents, and Hooks  Introduction If you've recently started using GitHub Copilot, you've probably come across terms like Instructions , Prompt Files , Skills , Agents , and Hooks . At first glance, they all seem to do the same thing—they tell Copilot what to do. So why does GitHub have five different customization features? The answer is simple: each feature solves a different problem. Think of GitHub Copilot as a new developer joining your team. On their first day, you don't just hand them code. You explain your coding standards, give them reusable templates, teach them specialized knowledge, assign them a role, and automate repetitive tasks. That's exactly how GitHub Copilot customization works. In this article, you'll learn what each feature does, when to use it, and how they all work together. By the end, you'll know which feature to start with and which ones can wait un...

Azure Function in a Docker Container - Part 1

From Azure Function v2, .NET developers can now write functions using .NET Core. This means you can develop and run your Azure functions in more places (cross-platform). This opens up opportunities for running your Azure function in Docker container and taking it one step ahead by running Azure Functions on Kubernetes with KEDA (Kubernetes-based Event Driven Autoscaling). In this blog post, we will see how to run Azure Function in Docker Container.    

Now few questions arise like why do we need to run in a container, do we lose the benefit of Serverless because you will be paying only for the time your function is running based on your plan in Azure Function, etc. All these questions are valid but as soon as we enter the world of containerization and Kubernetes we want our application to be flexible enough to be hosted in an on-premises/cloud/hybrid environment. With containerization now you can use Azure Functions as your event-driven host regardless of the environment. By having Azure Function in a docker container it enables options for hosting in different environments.

Pre-requisites

Build the Azure Functions container image and test locally

1. In this demo we will Create Azure Functions with HttpTriggered template and to support cross-platform we will be creating Azure Function v2 and v3 versions. You can similarly create new Azure Functions using Azure CLI commands e.g. func new
2. Create a Docker file for the respective version of Azure Function using following command.
  • Navigate to Azure Functions Project folder
  • Using the CLI tool/cmd prompt/PowerShell terminal use the following command
func init --docker-only --worker-runtime dotnet --chsarp    
 In the above command flag --docker tells Azure Function Core Tool to generate the Dockerfile
  • By default, the Docker file is created for Azure Function v2 even if you are using for Azure function v3 version. In that case please update the Docker file with the appropriate image version as shown in the below code snippet.
Azure Function v2 version of Docker file:
FROM microsoft/dotnet:2.2-sdk AS installer-env

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish *.csproj --output /home/site/wwwroot

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:2.0-appservice 
FROM mcr.microsoft.com/azure-functions/dotnet:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

Azure Function v3 version of Docker file:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS installer-env

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish *.csproj --output /home/site/wwwroot

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:3.0-appservice 
FROM mcr.microsoft.com/azure-functions/dotnet:3.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
  • Build Azure Function docker images using the below commands by navigating to the docker file folder.
docker build -t azurefuncv3 .
  • From the above step docker image is built locally, now let's see what is the command for running it locally.
 docker run --rm -it -p 7071:80/tcp azurefuncv3:latest


Now you should be able to browse the HttpTriggered endpoint Azure function which is running inside a container.


Now you might be interested in how to run it on Azure, check out this post Azure Function in a Docker Container - Part 2

Comments

Popular posts from this blog

Tidy up - Unused Project and Nuget package reference using Visual Studio 2019

Azure Front Door vs Azure Traffic Manager?

Authenticate Azure Functions - API Keys