# Using Micronaut with NubesGen
This documentation is for running Micronaut applications with NubesGen. There are two other options that might interest you:
- You can also use Java with NubesGen, which is similar, but does not use the specific Micronaut Framework application properties.
- As Micronaut Framework applications can be packaged with Docker, you can also run them as Docker applications with NubesGen.
# Tutorial: running a Micronaut Launch project with NubesGen
This tutorial is similar to the Java on NubesGen tutorial, as this simple Micronaut application is also a Java application.
Prerequisites:
Tip: You can go to https://aka.ms/nubesgen-azure-shell (opens new window) to have those prerequisites installed, and run the script from a Web browser.
- Bash (opens new window), which is installed by default on most Linux distributions and on Mac OS X. If you're using Windows, one solution is to use WSL (opens new window).
- Azure CLI (opens new window). To login, use
az login
. - (optional) GitHub CLI (opens new window). To login, use
gh auth login
.
Steps:
- Create a sample Java Web application using https://launch.micronaut.io/ (opens new window). Here we are requesting a Gradle build.
curl --location --request GET 'https://launch.micronaut.io/create/default/com.example.micronaut-sample-app?lang=JAVA&build=GRADLE&test=JUNIT&javaVersion=JDK_11' | tar -xzvf -
- Create a project on GitHub called
micronaut-sample-app
, and push the generated project to that repository. Change<your-github-account>
by the name of your GitHub account:cd micronaut-sample-app git init git add . git commit -m "first commit" git remote add origin https://github.com/<your-github-account>/micronaut-sample-app.git git branch -M main git push -u origin main
- In the cloned project (
cd micronaut-sample-app
), set up GitOps with NubesGen by running the NubesGen CLI (more information here):./nubesgen-cli-linux gitops
- Use the command-line with NubesGen (more information here) to generate a NubesGen configuration:Or if you have chosen a Maven build, then use the following command:
curl "https://nubesgen.com/demo.tgz?runtime=micronaut_gradle&application=app_service.standard&gitops=true" | tar -xzvf -
curl "https://nubesgen.com/demo.tgz?runtime=micronaut&application=app_service.standard&gitops=true" | tar -xzvf -
- Push the generated terraform and GitHub action to the
main
branch of the repository:cd micronaut-sample-app git add . git commit -m "Configure GitOps with NubesGen" git push -u origin main
- Create a new branch called
env-dev
, and push it to trigger a build:git checkout -b env-dev git push --set-upstream origin env-dev
- Go to your GitHub project, and check that the GitHub Action is running.
- You can go to the Azure Portal (opens new window) to check the created resources.
- The application should be deployed on your App Service instance. Its URL should be in the form
https://app-demo-XXXX-XXXX-XXXX-XXXX-dev-001.azurewebsites.net/
, and you can also find it in the GitHub Action workflow (Job: "display-information", step "Display Azure infrastructure information"), or in the Azure portal. As it is an empty application, you should get a 404 page with JSON describing the request. - Once you have finished, you should clean up your resources:
- Delete the resource group that was created by NubesGen to host your resources, which is named
rg-demo-XXXX-XXXX-XXXX-XXXX-001
. - Delete the storage account used to store your Terraform state, in the
rg-terraform-001
resource group.
- Delete the resource group that was created by NubesGen to host your resources, which is named
# Tutorial 2: running a Micronaut Guide project with a PostgreSQL database
For this tutorial, we will take the Maven/Java Micronaut GraphQL guide project and deploy it to Azure using NubesGen GitOps.
- Go to the Maven/Java version of the Micronaut Todos GraphQL guide (opens new window).
- Download the solution (opens new window) and extract it.
- Create a project on GitHub called
micronaut-graphql-todo
and push the downloaded project to that repository. Change<your-github-account>
by the name of your GitHub account:cd micronaut-graphql-todo git init git add . git commit -m "first commit" git remote add origin https://github.com/<your-github-account>/micronaut-graphql-todo.git git branch -M main git push -u origin main
- In the same directory, set up GitOps with NubesGen by running the NubesGen CLI (more information here):
./nubesgen-cli-linux gitops
- Use the command-line with NubesGen (more information here) to generate a NubesGen configuration:Or, if you are using a Gradle build, you will need to change runtime to
curl "https://nubesgen.com/demo.tgz?database=postgresql&runtime=micronaut&application=app_service.standard&gitops=true" | tar -xzvf -
micronaut_gradle
like so:curl "https://nubesgen.com/demo.tgz?database=postgresql&runtime=micronaut_gradle&application=app_service.standard&gitops=true" | tar -xzvf -
- Push the generated terraform and GitHub action to the
main
branch of the repository:git add . git commit -m "Configure GitOps with NubesGen" git push
- Create a new branch called
env-dev
, and push it to trigger a build:git checkout -b env-dev git push -u origin env-dev
- Go to your GitHub project, and check that the GitHub Action is running.
- You can go to the Azure Portal (opens new window) to check the created resources.
- Once deployed, you can access the application at
https://app-demo-XXXX-XXXX-XXXX-XXXX-dev-001.azurewebsites.net/
. Add a TODO to the database:
> curl -X POST 'https://app-demo-XXXX-XXXX-XXXX-XXXX-dev-001.azurewebsites.net/graphql' \
-H 'content-type: application/json' \
--data-binary '{"query":"mutation { createToDo(title:\"Create GraphQL Guide\", author:\"Tim Yates\") { id } }"}'
{"data":{"createToDo":{"id":"1"}}}
List the current TODOs:
> curl -X POST 'https://app-demo-XXXX-XXXX-XXXX-XXXX-dev-001.azurewebsites.net/graphql' \
-H 'content-type: application/json' \
--data-binary '{"query":"{ toDos { title, completed, author { username } } }"}'
{"data":{"toDos":[{"title":"Create GraphQL Guide","completed":false,"author":{"username":"Tim Yates"}}]}}
- Once you have finished, you should clean up your resources:
- Delete the resource group that was created by NubesGen to host your resources, which is named
rg-demo-XXXX-XXXX-XXXX-XXXX-001
. - Delete the storage account used to store your Terraform state, in the
rg-terraform-001
resource group.
# Which Azure resources will be created
If you deploy your Micronaut application to an Azure App Service instance, NubesGen will generate:
- An Azure App Service plan (opens new window) to define the type of App Service instance you will use.
- An Azure App Service instance (opens new window), configured to run Java code natively.
If you deploy your Micronaut application to an Azure Function, NubesGen will generate:
- An Azure App Service plan (opens new window) to define the type of Azure Functions instance you will use.
- An Azure Functions instance (opens new window), configured to run Java code natively.
- An Azure Storage Account (opens new window), to store your Java application.
# Maven vs Gradle
NubesGen supports both Maven and Gradle, so you can use the build system you prefer.
For Maven, change runtime=micronaut_gradle
to runtime=micronaut
in Step 5 above.
# Configuration options
In the generated terraform/modules/app-service/main.tf
file, NubesGen will configure some environment variables for your application.
Those are standard Micronaut properties, so your Micronaut application should be automatically configured (for example: your database connection should be working out-of-the-box).
DATASOURCES_DEFAULT_URL
: the JDBC URL to your databaseDATASOURCES_DEFAULT_USERNAME
: the database user nameDATASOURCES_DEFAULT_PASSWORD
: the database passwordREDIS_HOST
: the Redis host nameREDIS_PASSWORD
: the Redis passwordREDIS_PORT
: the Redis port (by default6380
)REDIS_SSL
: if Redis uses SSL (by defaulttrue
)MONGODB_URI
: the MongoDB database URL