Skip to content

This repository acts as a template for azure functions and should make the implementation and deplyoment easier

License

Notifications You must be signed in to change notification settings

binaryrain-net/Azure-Functions-Template

Repository files navigation

Azure-Functions-Template

This repository acts as a template for azure functions.



Prerequisites

Description

The function_builder file is a batch file designed to automate the setup of a Python-based Azure Function within a virtual environment. To activate it, just put the batch file inside the root directory and execute it.

Here are the main steps of the process:

  • Creating a Virtual Environment: The script then creates a Python virtual environment in the current directory. This isolates the Python environment for the Azure Function, preventing any conflicts with other Python projects on the same system.

  • User Input for Function Name: The script prompts the user to enter a name for the Azure Function.

  • Creating the Azure Function: The script creates a new directory named "Azure Functions", navigates into it, and then creates a new Azure Function with the provided name. The function is created with the Python worker runtime, using the v2 model, and the "Http Trigger" template for demo purpose..

  • Updating the Requirements File: The script navigates into the newly created Azure Function's directory and overwrites the requirements.txt file with a new set of dependencies.

Next Steps (Local)

  • Activate the Virtual Environment To activate the virtual env you have to run one of the activation applications inside the terminal. For PowerShell use the following command: bash PS C:\> <venv>\Scripts\Activate.ps1
  • Install the dependencies inside the function directory: pip install -r ./requirements.txt
  • Start the local azure function: func host start

    If the function does not return an exception you should see the localhost:https:// paths that are now active.

Next Steps (Deployment)

  • Make sure that you login with the azure CLI:
    az login
  • Create a resource group (either on portal.azure or with the following command):
    az group create --name <RESOURCEGROUPNAME> --location <LOCATION>
  • Create a storage account (either on portal.azure or with the following command):
    az storage account create --name <STORAGEACCOUNTNAME> --location <LOCATION> --resource-group <RESOURCEGROUPNAME> --sku Standard_LRS
  • Create a functionapp (either on portal.azure or with the following command):
    az functionapp create --resource-group <RESOURCEGROUPNAME> --consumption-plan-location <LOCATION> --runtime <RUNTIME> --functions-version 3 --name <FUNCTIONAPPNAME> --storage-account <STORAGEACCOUNTNAME> --os-type Linux
  • To download remote application settings:
    func azure functionapp fetch-app-settings <FUNCTIONAPPNAME>
  • To deploy your created function, use the following command:
    func azure functionapp publish <FUNCTIONAPPNAME>

Deployment with Github Actions

In order to use Github Actions for automatic deployment you have to adjust some settings. First make sure that you save the publish profile from your function:

  • In your Repo, go to [SETTINGS > SECRETS AND VARIABLES > ACTIONS] and store the publish profile from your azure function.
  • Go to the workflow and adjust the commented parts (the ones that start with "set this to your.....") to fit your own situation

Now when your code is ready for production, merge your code to the ["azure-production"] branch and the github action will deploy.

About

This repository acts as a template for azure functions and should make the implementation and deplyoment easier

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published