Skip to content

SpaceKatt/azure-func-dotnet-play

Repository files navigation

Azure Func Dotnet Playgound

Release CD Stage/Prod

Testing ground for C# (Dotnet) Azure Functions

Prerequisites

  • Install Dotnet 5
  • Install Azure Function CLI
  • Install Azure CLI

Run Functions Locally

func start

CI/CD

Setting Up CI/CD

See tutorial for Deploying Bicep with GitHub Actions.

We need to set up Azure for each of our environments by...

  1. Creating a resource group.
  2. Creating a service principal for modifying resource group.
  3. Adding appropriate secrets to the GitHub repository.
  4. (Issue) Run pipeline to deploy resources, then download Azure Functions Publish Profile and add to repo secrets.

Create resource group.

az login
az group create --name ${AZURE_RG_DEV} --location westus

Create a Service Principal to authenticate the GitHub Actions runner CI/CD process(es) with Azure, for each resource group we wish to deploy to.

 az ad sp create-for-rbac --name ${AZURE_SERVICE_PRINCIPAL_NAME_DEV} --role contributor --scopes /subscriptions/${AZURE_SUB_ID}/resourceGroups/${AZURE_RG_DEV} --sdk-auth

Save the output of the Service Principal creation, as this will be out AZURE_CREDENTIALS_* secret.

Add secrets to GitHub for GitHub Actions to authenticate with Azure.

Note: The author recommends only setting up the *_DEV secrets at first, then setting up additional envs later.

GitHub Repo Secrets Name Description
AZURE_RG_DEV Azure resource group which we created for the project's dev env.
AZURE_RG_STAG Azure resource group which we created for the project's dev env.
AZURE_RG_PROD Azure resource group which we created for the project's prod env.
AZURE_CREDENTIALS_DEV Output of az ad sp create-for-rbac command; service principal credentials.
AZURE_CREDENTIALS_STAG Output of az ad sp create-for-rbac command; service principal credentials.
AZURE_CREDENTIALS_PROD Output of az ad sp create-for-rbac command; service principal credentials.
AZURE_FUNCTION_PUB_PROF_DEV Azure Functions publish profile (XML), downloaded from Azure.
AZURE_FUNCTION_PUB_PROF_STAG Azure Functions publish profile (XML), downloaded from Azure.
AZURE_FUNCTION_PUB_PROF_PROD Azure Functions publish profile (XML), downloaded from Azure.
AZURE_SUBSCRIPTION Azure subscription Id.

Issue: Function Publish Profile has to be fetched (currently) after deployment. Thus, initial set up will likely end in failure until secret for profile is fetched and set and pipeline is rerun.

Pipeline Inventory

The following CICD pipelines exist in this project...

Pipeline Description Badge
CI Workflow Runs CI workflow on pull requests to main. CI Workflow
CD Workflow Deploys dev resources on merge to main. Azure Bicep Deploy and Publish
Release Workflow Deploys staging and prod resources on push to release/*. Release CD Stage/Prod

Insomnia Request Examples

Insomnia is a fun tool used to test RESTful APIs. (Similar to Postman.)

Example requests are given in an Insomnia collection JSON export.

See the docs to learn how to import request collections.

(DEPRECATED) Deploy to Azure without CI/CD

NOTE: These docs ARE out of date

Create resource group.

az login
az group create --name spacekatt-func-play --location westus

Deploy resources into group

az deployment group create --resource-group spacekatt-func-play --template-file deploy/resources/main.bicep --mode Complete

Publish Function App

func azure functionapp publish fun-spacekattfunc

About

Testing ground for C# (Dotnet) Azure Functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published