Azure Function App on Kubernetes with GitHub Actions and Argo Cd Series Part-I
--
Today, we will try to create a Container Image of Azure Function App via GitHub Actions and will store it on GitHub Container Registry.
Brief About Azure Function:
Azure Functions is a cloud service available on-demand that provides all the continually updated infrastructure and resources needed to run your applications. You focus on the pieces of code that matter most to you, and Functions handles the rest. Functions provides serverless compute for Azure. You can use Functions to build web APIs, respond to database changes, process IoT streams, manage message queues, and more.
Brief About GitHub Actions:
GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.
Things Required:
- VS 2022
- GitHub Account with GitHub Container Registry Feature on.
- Docker Desktop
Let’s get started, First Open your Visual Studio and click on Create a new Project. Then Search for Azure Functions and Select Azure Functions and Click on Next.
Give a proper Name and Click on Create
Now it will ask for which .Net version to choose and which trigger and what kind of Authentication, we are going to use. As this is for our Testing, please choose Authorization Level as Anonymous, but for production setup, please choose a higher security level. We will also choose .Net 6 for our project, as it is the latest stable one( Although .Net 7 preview is on the Horizon). For our purpose, we will use Http Trigger with Open Api.
Once our Project is created, we will rename Function1 according to our needs, or we can keep it as it is.
Then right click on the Project-> Add and then Select Docker Support. It will add a Dockerfile in the project.
Now lets Test it out by Selecting Docker as Running Option and See the Results.
As you can see the Program is already running, lets hit the endpoints and also check in the Docker Desktop.
Lets work on Creating the GitHub Action Workflow, to do that, first lets create a folder named .github and under that create another folder called workflows and add a new file named docker-publish.yml
Now create a Solution Folder by right clicking on the solution -> Add and clicking on New Solution Folder and named it as githubactions and also include and Existing item by right click on the githubactions -> Add and clicking on Existing item and browse and select earlier docker-publish.yml
Let’s create the workflow,
Our workflow will check out the code, determine the version ,set up Docker Build task, extract docker metadata, then build the docker image and push it to container registry and create a release(release will maintain a SemVer versioning of the repo)
Now that’s done create a GitHub Repository by clicking Add to Source Control and Select Git at the bottom of VS 2022. Select your remote option as GitHub and then click on Create and Push
Let’s explore on GitHub, go to your GitHub Repository, on the push, it will trigger the workflow.
Now go to Actions tab to check the GitHub Action status,
Click on the Commit Message, it will take you the Jobs available under this workflow, there should be only one job named Build, now click on that, you can find all the steps executed and if you expand the steps you can find the logs as well.
Now let’s go to the Code Again, there you can see the Packages and Releases. Under Packages you can find all the images created by the GitHub Action and under Releases, all the released packages are kept.
Now as our Image is already ready, we will work on creating a CD pipeline(although it is not exactly an pipeline) using Argo CD and deploy it in the local Kubernetes cluster. in Part 2.
Git Repo: https://github.com/arkapravasinha/K8SFunctions
Part-II available at https://arkapravasinha.medium.com/azure-function-app-on-kubernetes-with-github-actions-and-argo-cd-series-part-ii-c23631824ad4
For reference,