From 323e894da1a09fd7dd9ea9ef33a4d3e672388ec5 Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Mon, 2 Feb 2026 12:49:32 -0500 Subject: [PATCH] Add Nomad job definitions, Qodana setup, and release pipeline - Add `from-github.nomad` and `from-local.nomad` for running JARs from GitHub releases or locally. - Expand README with execution instructions for both setups. - Introduce `.github/workflows/qodana_code_quality.yml` for Qodana scans. - Add `qodana.yaml` to configure inspection profiles and quality gates. - Create `.github/workflows/release.yml` for building, packaging, and publishing releases. - Update Maven `pom.xml` with `finalName` for consistent artifact naming. - Remove unused `application-nomad.properties`. --- .github/workflows/qodana_code_quality.yml | 40 +++++++++ .github/workflows/release.yml | 48 ++++++++++ README.md | 90 ++++++++++++------- from-github.nomad | 23 +++++ from-local.nomad | 29 ++++++ pom.xml | 1 + qodana.yaml | 49 ++++++++++ .../resources/application-nomad.properties | 1 - 8 files changed, 247 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/qodana_code_quality.yml create mode 100644 .github/workflows/release.yml create mode 100644 from-github.nomad create mode 100644 from-local.nomad create mode 100644 qodana.yaml delete mode 100644 src/main/resources/application-nomad.properties diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml new file mode 100644 index 0000000..bde15bf --- /dev/null +++ b/.github/workflows/qodana_code_quality.yml @@ -0,0 +1,40 @@ +#-------------------------------------------------------------------------------# +# Discover all capabilities of Qodana in our documentation # +# https://www.jetbrains.com/help/qodana/about-qodana.html # +#-------------------------------------------------------------------------------# + +name: Qodana +on: + workflow_dispatch: + pull_request: + push: + branches: + - develop + - master + +jobs: + qodana: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + checks: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + - name: 'Qodana Scan' + uses: JetBrains/qodana-action@v2025.3 + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} + with: + # When pr-mode is set to true, Qodana analyzes only the files that have been changed + pr-mode: false + use-caches: true + post-pr-comment: true + use-annotations: true + # Upload Qodana results (SARIF, other artifacts, logs) as an artifact to the job + upload-result: false + # quick-fixes available in Ultimate and Ultimate Plus plans + push-fixes: 'none' \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a8cc64e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +name: Release and Package + +on: + push: + branches: + - master + +jobs: + build-and-release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn -B clean package -Dquarkus.package.jar.type=uber-jar + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.run_number }} + release_name: Release ${{ github.run_number }} + body: | + New release based on commit ${{ github.sha }} + draft: false + prerelease: false + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./target/java-nomad-example-runner.jar + asset_name: java-nomad-example-runner.jar + asset_content_type: application/java-archive \ No newline at end of file diff --git a/README.md b/README.md index b1b526a..ea2a2d7 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,84 @@ # java-nomad-example -This project uses Quarkus, the Supersonic Subatomic Java Framework. +Este es un ejemplo de cómo ejecutar el proyecto con Nomad con Java: -If you want to learn more about Quarkus, please visit its website: . +* Descargando un compilado (que está en GitHub) +* Ejecutando desde local (que está en la carpeta `target`) -## Running the application in dev mode +## Descargando un compilado -You can run your application in dev mode that enables live coding using: +Se puede ejecutar el comando nomad con el task `java`, pero tiene la restricción que solo puede ejecutar archivos que sean descargados, no desde local: -```shell script -./mvnw quarkus:dev +```hcl +task "api" { + driver = "java" +#.... ``` -> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at . +Por ello, se hizo un "[GH Actions](.github/workflows/release.yml)" que publica el .jar compilado en [GitHub](https://github.com/apuntesdejava/java-nomad-example/releases). -## Packaging and running the application +Finalmente, el nomad para ser ejecutado es este: [from-github.nomad](from-github.nomad), y comando es: -The application can be packaged using: - -```shell script -./mvnw package +```shell +nomad run from-github.nomad ``` -It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory. -Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory. +## Ejecutando desde local -The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`. +Para ejecutar desde local, no se ejecuta el task `java` sino `raw_exec`. -If you want to build an _über-jar_, execute the following command: +1. Compilar el proyecto como uber-jar: -```shell script -./mvnw package -Dquarkus.package.jar.type=uber-jar +Bash: +```shell +./mvnw clean package -Dquarkus.package.type=uber-jar ``` -The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. +Powershell: +```powershell +.\mwnw clean package "-Dquarkus.package.jar.type=uber-jar" +``` -## Creating a native executable -You can create a native executable using: -```shell script -./mvnw package -Dnative -``` -Or, if you don't have GraalVM installed, you can run the native executable build in a container using: +2. Con eso ya se tiene el .jar compilado, ahora, ejecutamos el nomad, pero para ello necesitamos pasar la posición del jar. + Por ello, el archivo [`from-local.nomad`](from-local.nomad) tiene la definición de un parámetro de entrada + +```hcl +variable "jar_path" { + type = string + description = "Ruta absoluta al JAR en la máquina host" +} -```shell script -./mvnw package -Dnative -Dquarkus.native.container-build=true ``` -You can then execute your native executable with: `./target/java-nomad-example-1.0-SNAPSHOT-runner` +Y en la parte donde va el .jar, se indica esa variable: + +```hcl + task "api" { + driver = "raw_exec" + config { + command = "java" + args = [ + "-jar", + var.jar_path # Aquí va la variable + ] + } + } +``` -If you want to learn more about building native executables, please consult . +Finalmente, para ser ejecutado, se hace de la siguiente manera: -## Related Guides +Bash (Linux/macOS): + +```shell +nomad job run -var="jar_path=$(pwd)/target/java-nomad-example-runner.jar" from-local.nomad +``` + +Powershell (Windows) +```powershell +nomad job run -var="jar_path=$(Get-Location)\target\java-nomad-example-runner.jar" .\from-local.nomad +``` -- REST JSON-B ([guide](https://quarkus.io/guides/rest#json-serialisation)): JSON-B serialization support for Quarkus - REST. This extension is not compatible with the quarkus-resteasy extension, or any of the extensions that depend on - it. +La variable `$(pwd)` en bash y la variable `$(Get-Location)` en PowerShell dan la ruta absoluta desde donde se está ejecutando el comando. Por ello se está concatenando la parte de `target` y el jar generado, a fin de no colocar un hardcode de la ruta absoluta. \ No newline at end of file diff --git a/from-github.nomad b/from-github.nomad new file mode 100644 index 0000000..1f46a60 --- /dev/null +++ b/from-github.nomad @@ -0,0 +1,23 @@ +job "from-github" { + datacenters = ["dc1"] + group "backend" { + count = 1 + network { + port "http" { + static = 8080 + } + } + task "api" { + driver = "java" + artifact { + source = "https://github.com/apuntesdejava/java-nomad-example/releases/download/2/java-nomad-example-runner.jar" + destination = "local" + } + config { + jar_path = "local/java-nomad-example-runner.jar" + } + + } + } + +} diff --git a/from-local.nomad b/from-local.nomad new file mode 100644 index 0000000..8e8827f --- /dev/null +++ b/from-local.nomad @@ -0,0 +1,29 @@ +variable "jar_path" { + type = string + description = "Ruta absoluta al JAR en la máquina host" +} + +job "from-local" { + datacenters = ["dc1"] + + + group "backend" { + count = 1 + network { + port "http" { + static = 8080 + } + } + task "api" { + driver = "raw_exec" + config { + command = "java" + args = [ + "-jar", + var.jar_path + ] + } + } + } + +} diff --git a/pom.xml b/pom.xml index 823c620..2b966e7 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,7 @@ + java-nomad-example ${quarkus.platform.group-id} diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 0000000..1c544ad --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,49 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# + +################################################################################# +# WARNING: Do not store sensitive information in this file, # +# as its contents will be included in the Qodana report. # +################################################################################# +version: "1.0" + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +projectJDK: "21" #(Applied in CI/CD pipeline) + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +# Quality gate. Will fail the CI/CD pipeline if any condition is not met +# severityThresholds - configures maximum thresholds for different problem severities +# testCoverageThresholds - configures minimum code coverage on a whole project and newly added code +# Code Coverage is available in Ultimate and Ultimate Plus plans +#failureConditions: +# severityThresholds: +# any: 15 +# critical: 5 +# testCoverageThresholds: +# fresh: 70 +# total: 50 + +#Qodana supports other languages, for example, Python, JavaScript, TypeScript, Go, C#, PHP +#For all supported languages see https://www.jetbrains.com/help/qodana/linters.html +linter: jetbrains/qodana-jvm-community:2025.3 diff --git a/src/main/resources/application-nomad.properties b/src/main/resources/application-nomad.properties deleted file mode 100644 index cf894e2..0000000 --- a/src/main/resources/application-nomad.properties +++ /dev/null @@ -1 +0,0 @@ -quarkus.package.jar.type=uber-jar \ No newline at end of file