All Projects → jdubois → azure-native-spring-function

jdubois / azure-native-spring-function

Licence: Apache-2.0 License
Tutorial on running Spring Boot + GraalVM native images on Azure Functions

Programming Languages

java
68154 projects - #9 most used programming language
HCL
1544 projects
shell
77523 projects

Projects that are alternatives of or similar to azure-native-spring-function

clojure-rust-graalvm
An example of Clojure program calling a Rust library, all combined into one executable using GraalVM.
Stars: ✭ 113 (+101.79%)
Mutual labels:  graalvm, graal-native
quarkus-performance
Comparing the CPU/Memory utilisation - Quarkus via GraalVM Native Image vs. Quarkus via Java Runtime vs. Payara-Micro via Java Runtime.
Stars: ✭ 49 (-12.5%)
Mutual labels:  graalvm, graal-native
harry-potter-quarkus
Showcases in a web application Quarkus and Infinispan
Stars: ✭ 16 (-71.43%)
Mutual labels:  graalvm, graal-native
AzureFunctions.Extensions
This provides some useful extensions for Azure Functions.
Stars: ✭ 81 (+44.64%)
Mutual labels:  azure-functions
LogoRRR
A log viewer which visualises log events such that it is easy to identify problems or events of interest. This app was implemented using Scala and JavaFX, GluonHQ toolchain and GraalVM as platform.
Stars: ✭ 40 (-28.57%)
Mutual labels:  graalvm
azure-functions-auth
Authentication and Authorization for Azure Functions (with OAuth 2.0 and JWT)
Stars: ✭ 20 (-64.29%)
Mutual labels:  azure-functions
ScriptableMC-Engine
Create TypeScript/JavaScript plugins for Minecraft 1.16 Bukkit/Spigot/Paper
Stars: ✭ 36 (-35.71%)
Mutual labels:  graalvm
LearningPoint
A repository for learning different technologies, frameworks, features......
Stars: ✭ 66 (+17.86%)
Mutual labels:  azure-functions
HttpClientFactory.Azure.Functions
[Archived] Azure Functions and Azure WebJobs binding extensions for HttpClientFactory. This is no longer the best approach: https://www.tpeczek.com/2019/10/alternative-approach-to-httpclient-in.html
Stars: ✭ 14 (-75%)
Mutual labels:  azure-functions
graalvm
A Cloud Native Buildpack that provides the GraalVM implementations of JREs and JDKs
Stars: ✭ 21 (-62.5%)
Mutual labels:  graalvm
backend-csharp
A C# / Azure Functions implementation of the API for https://www.theurlist.com
Stars: ✭ 35 (-37.5%)
Mutual labels:  azure-functions
GitHubReadmeWebTrends
An automated tool created using Azure Functions that double checks each Readme to ensure every repository is leveraging Web Trends
Stars: ✭ 13 (-76.79%)
Mutual labels:  azure-functions
AppService
Blog posts from the App Service team
Stars: ✭ 66 (+17.86%)
Mutual labels:  azure-functions
netty-native-demo
Instant Netty startup using GraalVM's Native Image Generation
Stars: ✭ 58 (+3.57%)
Mutual labels:  graalvm
dtype-next
A Clojure library designed to aid in the implementation of high performance algorithms and systems.
Stars: ✭ 193 (+244.64%)
Mutual labels:  graal-native
leto-serverless
Angular server(less) side rendering
Stars: ✭ 13 (-76.79%)
Mutual labels:  azure-functions
AzUnzipEverything
A simple Azure Function to Unzip files from a blob storage to another one
Stars: ✭ 24 (-57.14%)
Mutual labels:  azure-functions
nodejs-postgresql-azure
Repositório responsável pela série de artigos sobre Node.js com PostgreSQL
Stars: ✭ 70 (+25%)
Mutual labels:  azure-functions
fl-image-resize
A library to quickly resize images with Azure Functions
Stars: ✭ 15 (-73.21%)
Mutual labels:  azure-functions
cosmosdb-materialized-views
A full sample that shows how to implement real-time updated Materalized Views with CosmosDB, Change Feed and Azure Functions
Stars: ✭ 20 (-64.29%)
Mutual labels:  azure-functions

Running Spring Boot + GraalVM native images on Azure Functions

This sample application shows how to:

  • Compile a Spring Boot application using GraalVM
  • Deploy and run that application on Azure Functions

This will use GitHub Actions to do all the heavy work: as we are creating a native image, it needs to be built on a Linux machine with GraalVM installed.

Prerequisites

To check if Azure is correctly set up, login using the CLI by running az login.

Fork this repository

All compilation and deployment will be done using GitHub Actions, so you need your own repository for this. The easiest way is to fork this repository to your own GitHub account, using the fork button on the top right-hand corner of this page.

Create the cloud infrastructure using Terraform

You need to configure the following environment variables:

export TF_VAR_AZ_LOCATION=westeurope
export TF_VAR_AZ_RESOURCE_GROUP=azure-native-spring-function
export TF_VAR_AZ_FUNCTION_NAME_APP=<your-unique-name>
export TF_VAR_AZ_STORAGE_NAME=<your-unique-name>
  • TF_VAR_AZ_LOCATION : The name of the Azure location to use. Use az account list-locations to list available locations. Common values are eastus, westus, westeurope.
  • TF_VAR_AZ_RESOURCE_GROUP : The resource group in which you will work. It should be unique in your subscription, so you can probably keep the default azure-native-spring-function.
  • TF_VAR_AZ_FUNCTION_NAME_APP : Functions will run into an application, and its name should be unique across Azure. It must contain only alphanumeric characters and dashes and up to 60 characters in length.
  • TF_VAR_AZ_STORAGE_NAME : Functions binaries and configuration will be stored inside a storage account. Its name should also be unique across Azure. It must be between 3 and 24 characters in length and may contain numbers and lowercase letters only.

In order not to type those values again, you can store them in a .env file at the root of this project:

  • This .env file will be ignored by Git (so it will remain on your local machine and won't be shared).
  • You will be able to configure those environment variables by running source .env.

Go to the terraform directory and run:

  • terraform init to initialize your Terraform environment
  • terraform apply --auto-approve to create all the necessary Azure resources

This will create the following Azure resources:

  • A resource group that will store all resources (just delete this resource group to remove everything)
  • An Azure Functions plan. This is a consumption plan, running on Linux: you will only be billed for your usage, with a generous free tier. Here is the full pricing documentation.
  • An Azure Functions application, that will use the plan described in the point above.
  • An Azure Storage account, which will be used to store your function's data (the binary and the configuration files).

Configure GitHub Actions to build and deploy the application

The GitHub Actions workflow that we will use is available in .github/workflows/build-and-deploy.yml.

This GitHub Action will need to use some variables, for this go to your project fork and select "Settings", then "Secrets".

Configure the AZ_FUNCTION_NAME_APP secret

The AZ_FUNCTION_NAME_APP is the name of your function application. It is the same as the TF_VAR_AZ_FUNCTION_NAME_APP environment variable that we configured earlier with Terraform.

Create a new secret called AZ_FUNCTION_NAME_APP, paste the value in it, and click "Add secret".

Configure the AZURE_CREDENTIALS secret

The AZURE_CREDENTIALS will allow the GitHub Actions workflow to log in your Azure account, and deploy the application.

This is a JSON payload that we will get by executing the following command:

RESOURCE_ID=$(az group show --name $TF_VAR_AZ_RESOURCE_GROUP --query id -o tsv)
SPNAME="sp-$(az functionapp list --resource-group $TF_VAR_AZ_RESOURCE_GROUP  --query '[].name' -o tsv)"
az ad sp create-for-rbac --name "${SPNAME}" --role contributor --scopes "$RESOURCE_ID" --sdk-auth

Create a new secret called AZURE_CREDENTIALS, paste the JSON payload in it, and click "Add secret".

Deploy and test

Now that everything is set up, your application will be automatically built as a GraalVM native image, and deployed to Azure Functions.

You can change some code, or force a commit to trigger such a build:

git commit -m "force build" --allow-empty && git push

You will be able to monitor that process in the "Actions" tab of your fork of the project.

Once the function is deployed, you can access it though the Azure Portal. You will there be able to monitor it and test it.

  • Select your resource group
  • Select the Azure Functions application you created (its type is "App Service")
  • In "Functions", find the function that you have just deployed
  • Select "Code + Test"
  • You can click on "Test/Run": select a "POST" method, and enter Azure as body. You should have the following output: {"message": "Hello, Azure!\n"}

As you will want to test the performance of this function, still on the "Code + Test" screen, select "Get function URL". Use that function URL to test the performance of your function:

time curl <YOUR-FUNCTION-URL> -d 'Azure' -H "Content-Type: application/json"

For monitoring your function, you can also select the "Monitor" tab and create an Azure Applications Insight instance, which will be able to give you detailed metrics (like RAM usage) of your function.

Tuning the function

The function configuration is in src/main/function:

  • The name of the directory should be the same as the name of the function. That's how Azure Functions can apply the configuration.
  • Documentation for the host.json and function.json files can be found at Azure Functions custom handlers.

The application used here is very simple, and comes from https://github.com/spring-projects-experimental/spring-graalvm-native/tree/master/spring-graalvm-native-samples/function-netty.

If you want to work on this function or run it locally, the https://github.com/spring-projects-experimental/spring-graalvm-native project gives all the necessary documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].