diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..666e0c2 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,38 @@ +#### Description + + + + + +#### List of Changes + + +#### Motivation and Context + + +#### How Has This Been Tested? + + + +- Pre-Deploy Test + - [ ] Unit + - [ ] Integration (Narrow) +- Post-Deploy Test + - [ ] Isolated Microservice + - [ ] Broader Integration + - [ ] Acceptance + - [ ] Performance & Load + +#### Types of changes + + +- [ ] PATCH - Bug fix (backwards compatible bug fixes) +- [ ] MINOR - New feature (add functionality in a backwards compatible manner) +- [ ] MAJOR - Breaking change (fix or feature that would cause existing functionality to not work as expected) + +#### Checklist: + + + +- [ ] My change requires a change to the documentation. +- [ ] I have updated the documentation accordingly. diff --git a/.github/workflows/build-n-push-main.yml b/.github/workflows/build-n-push-main.yml new file mode 100644 index 0000000..4210bc8 --- /dev/null +++ b/.github/workflows/build-n-push-main.yml @@ -0,0 +1,67 @@ +name: Build, push and update + +on: + workflow_dispatch: +# inputs: +# skip-unit-test: +# type: boolean +# required: true +# description: Skip unit-test + +jobs: + build_push_update: + runs-on: ubuntu-22.04 + + environment: cstar-d-weu-rtp + + permissions: + id-token: write + packages: write + + steps: + # + # Checkout the source code. + # + - name: Checkout the source code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 + + # + # Build and push native container image. + # + - name: Log in to the Container registry + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + registry: https://ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 + + - name: Build the app image + uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0 + with: + push: true + context: . + file: src/main/docker/Dockerfile + platforms: linux/amd64 + tags: ghcr.io/${{ github.repository }}:latest, ghcr.io/${{ github.repository }}:${{ steps.semantic.outputs.new_release_version }}-RC + secrets: | + "gh_token=${{ secrets.GIT_PAT }}" + + # + # Update Container App. + # + - name: Update Container App + shell: bash + working-directory: src/main/terraform + env: + ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}" + ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}" + ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}" + run: | + terraform init -backend-config="env/dev/backend.tfvars" -reconfigure + terraform apply -var-file="env/dev/terraform.tfvars" -var="rtp_activator_image=${{ steps.build_image.outputs.image }}" -auto-approve -lock-timeout=300s diff --git a/.github/workflows/post-merge.yml b/.github/workflows/post-merge.yml new file mode 100644 index 0000000..5c49799 --- /dev/null +++ b/.github/workflows/post-merge.yml @@ -0,0 +1,266 @@ +name: Post-merge/release workflow + +on: + workflow_dispatch: + pull_request: + types: + - closed + branches: + - main + +jobs: + post_merge: + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + + runs-on: ubuntu-22.04 + + environment: cstar-d-weu-rtp + + permissions: + id-token: write # Get OIDC token to authenticate to Azure. + packages: write # Push container imaged to GHCR. + contents: write # Create a new release. + + outputs: + new_release_published: ${{ steps.semantic.outputs.new_release_published }} + image: ${{ steps.stable_image.outputs.image }} + + steps: + # + # Checkout the source code. + # + - name: Checkout the source code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 + with: + token: ${{ secrets.GIT_PAT }} + fetch-depth: 0 + + # + # Install Node. + # + - name: Install Node + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c + with: + node-version: "20.18.0" + + # + # Calculate of the new version (dry-run). + # + - name: Calculate of the new version (dry-run) + uses: cycjimmy/semantic-release-action@b1b432f13acb7768e0c8efdec416d363a57546f2 # 4.1.1 + id: semantic + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + semantic_version: 21.1.1 + branch: main + extra_plugins: | + @semantic-release/release-notes-generator@14.0.1 # 44c780c6f9c1bf2643fe48b6718bd9a84b820132 + @semantic-release/git@10.0.1 # 3e934d45f97fd07a63617c0fc098c9ed3e67d97a + dry_run: true + + # + # Setup Java + # + - name: Setup Java + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 + with: + distribution: ‘corretto’ + java-version: ‘21’ + cache: ‘gradle’ + + # + # RELEASE CANDIDATE - Update of pom.xml and openapi.yaml with the RC new version. + # + - name: RELEASE CANDIDATE - Update of pom.xml and openapi.yaml with the new version + if: steps.semantic.outputs.new_release_published == 'true' + run: | + yq -i ".info.version = \"${{ steps.semantic.outputs.new_release_version }}-RC\"" "src/main/resources/META-INF/openapi.yaml" + sed -i -e "s/version=.*/version=${{ steps.semantic.outputs.new_release_version }}-RC/g" gradle.properties + +# todo sonar + # + # RELEASE CANDIDATE - Build and push native container image. + # + - name: Log in to the Container registry + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + registry: https://ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 + + - name: Build the app image + uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0 + with: + push: true + context: . + file: src/main/docker/Dockerfile + platforms: linux/amd64 + tags: ghcr.io/${{ github.repository }}:latest, ghcr.io/${{ github.repository }}:${{ steps.semantic.outputs.new_release_version }}-RC + secrets: | + "gh_token=${{ secrets.GIT_PAT }}" + + # + # Setup Terraform + # + - name: Setup Terraform + if: steps.semantic.outputs.new_release_published == 'true' + uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2 + with: + terraform_version: 1.9.7 + + # + # RELEASE CANDIDATE - Update Container App. + # + - name: RELEASE CANDIDATE - Update Container App + if: steps.semantic.outputs.new_release_published == 'true' + shell: bash + working-directory: src/main/terraform + env: + ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}" + ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}" + ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}" + run: | + terraform init -backend-config="env/dev/backend.tfvars" -reconfigure + terraform apply -var-file="env/dev/terraform.tfvars" -var="rtp_activator_image=${{ steps.rc_image.outputs.image }}" -auto-approve -lock-timeout=300s + +# # +# # Install Newman. +# # +# - name: Install Newman +# if: steps.semantic.outputs.new_release_published == 'true' +# run: npm install -g newman +# +# # +# # Run Postman collection. +# # +# - name: Run Postman collection +# if: steps.semantic.outputs.new_release_published == 'true' +# run: | +# newman run src/test/postman/mil-auth.postman_collection.json \ +# -e src/test/postman/dev.postman_environment.json \ +# --env-var "correctPassword=${{ secrets.NEWMAN_IT__CORRECTPASSWORD }}" \ +# --env-var "correctClientSecret=${{ secrets.NEWMAN_IT__CORRECTCLIENTSECRET }}" \ +# --env-var "correctClientSecretForVasLayer=${{ secrets.NEWMAN_IT__CORRECTCLIENTSECRETFORVASLAYER }}" \ +# --env-var "clientSecretForMilDebtPosition=${{ secrets.NEWMAN_IT__CLIENTSECRETFORMILDEBTPOSITION }}" + + # + # STABLE - Update of pom.xml and openapi.yaml with the new version. + # + - name: STABLE - Update of pom.xml and openapi.yaml with the new version + if: steps.semantic.outputs.new_release_published == 'true' + run: | + ${{ runner.temp }}/maven/bin/mvn versions:set -DnewVersion=${{ steps.semantic.outputs.new_release_version }} -s ${{ runner.temp }}/settings.xml --no-transfer-progress + yq -i ".info.version = \"${{ steps.semantic.outputs.new_release_version }}\"" "src/main/resources/META-INF/openapi.yaml" + git config user.name "GitHub Workflow" + git config user.email "<>" + git add pom.xml + git add src/main/resources/META-INF/openapi.yaml + git commit -m "Updated with new version ${{ steps.semantic.outputs.new_release_version }}" + git push origin main + + # + # Calculation of the new version (again) with tagging + releasing + etc. + # + - name: Calculation of the new version (w/o dry_run) and put tag + if: steps.semantic.outputs.new_release_published == 'true' + uses: cycjimmy/semantic-release-action@b1b432f13acb7768e0c8efdec416d363a57546f2 # 4.1.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + semantic_version: 21.1.1 + branch: main + extra_plugins: | + @semantic-release/release-notes-generator@14.0.1 # 44c780c6f9c1bf2643fe48b6718bd9a84b820132 + @semantic-release/git@10.0.1 # 3e934d45f97fd07a63617c0fc098c9ed3e67d97a + dry_run: false + + # + # STABLE - Build and push native container image. + # + - name: Log in to the Container registry + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + registry: https://ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 + + - name: Build the app image + uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0 + with: + push: true + context: . + file: src/main/docker/Dockerfile + platforms: linux/amd64 + tags: ghcr.io/${{ github.repository }}:latest, ghcr.io/${{ github.repository }}:${{ steps.semantic.outputs.new_release_version }}-RC + secrets: | + "gh_token=${{ secrets.GIT_PAT }}" + + # + # STABLE - Update Container App. + # + - name: STABLE - Update Container App + if: steps.semantic.outputs.new_release_published == 'true' + shell: bash + working-directory: src/main/terraform + env: + ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}" + ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}" + ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}" + run: | + terraform init -backend-config="env/dev/backend.tfvars" -reconfigure + terraform apply -var-file="env/dev/terraform.tfvars" -var="rtp_activator_image=${{ steps.stable_image.outputs.image }}" -auto-approve -lock-timeout=300s + + + uat_deployment: + needs: post_merge + + if: needs.post_merge.outputs.new_release_published == 'true' + + runs-on: ubuntu-22.04 + + environment: cstar-u-weu-rtp + + permissions: + id-token: write + + steps: + # + # Checkout the source code. + # + - name: Checkout the source code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 + + # + # Setup Terraform + # + - name: Setup Terraform + uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2 + with: + terraform_version: 1.9.7 + + # + # Update Container App. + # + - name: STABLE - Update Container App + shell: bash + working-directory: src/main/terraform + env: + ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}" + ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}" + ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}" + run: | + terraform init -backend-config="env/uat/backend.tfvars" -reconfigure + terraform apply -var-file="env/uat/terraform.tfvars" -var="rtp_activator_image=${{ needs.post_merge.outputs.image }}" -auto-approve -lock-timeout=300s \ No newline at end of file diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml new file mode 100644 index 0000000..a08c30a --- /dev/null +++ b/.github/workflows/pr-validation.yml @@ -0,0 +1,38 @@ +name: Pull request validation + +on: + pull_request: + branches: + - main + types: + - opened + - edited + - synchronize + +jobs: + pr-validation: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout the source code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 + + - name: PR title validation + uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # 5.5.3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + types: | + docs + refactor + chore + fix + feat + breaking + requireScope: false + subjectPattern: '\[SRTP(-[0-9]{2,4})?\] .+' + subjectPatternError: | + The subject "{subject}" found in the pull request title "{title}" + doesn't match the configured pattern. Please ensure that the subject + starts with an uppercase character. + wip: false diff --git a/.gitignore b/.gitignore index 524f096..2fe54cc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,80 @@ # Mobile Tools for Java (J2ME) .mtj.tmp/ -# Package Files # +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +###################### +# Project Specific +###################### +/sonar-report/** +**/sonar-report/** + +###################### +# Eclipse +###################### +*.pydevproject +.project +.metadata +tmp/ +tmp/**/* +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath +.factorypath +/src/main/resources/rebel.xml + +# External tool builders +.externalToolBuilders/** + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + +# STS-specific +/.sts4-cache/* +###################### +# Intellij +###################### +.idea/ +*.iml +*.iws +*.ipr +*.ids +*.orig +classes/ +out/ + +###################### +# Visual Studio Code +###################### +.vscode/ + +###################### +# Maven +###################### +/log/ +/target/** +**/target/** +###################### +# Gradle +###################### +.gradle/ +/build/ + +###################### +# Package Files +###################### *.jar *.war *.nar @@ -19,6 +92,64 @@ *.tar.gz *.rar -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* +###################### +# Windows +###################### +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + +###################### +# Mac OSX +###################### +.DS_Store +.svn + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +###################### +# Directories +###################### +/bin/ +/deploy/ + +###################### +# Logs +###################### +*.log* + +###################### +# Others +###################### +*.*~ +*~ +.merge_file* + +###################### +# Gradle Wrapper +###################### +!gradle/wrapper/gradle-wrapper.jar + +###################### +# Maven Wrapper +###################### +!.mvn/wrapper/maven-wrapper.jar + +###################### +# ESLint +###################### +.eslintcache + +# +# Terraform +# +src/main/terraform/identity/.terraform/ +src/main/terraform/.terraform/ +.terraform.lock.hcl diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..486d887 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,3 @@ +# see https://help.github.com/en/articles/about-code-owners#example-of-a-codeowners-file + +* @pagopa/rtp-team-admin @pagopa/rtp-team \ No newline at end of file diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..e83eb6e --- /dev/null +++ b/HELP.md @@ -0,0 +1,87 @@ +# Read Me First +The following was discovered as part of building this project: + +* The original package name 'it.pagopa.rtp-activator' is invalid and this project uses 'it.pagopa.rtp_activator' instead. + +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.5/gradle-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.3.5/gradle-plugin/packaging-oci-image.html) +* [GraalVM Native Image Support](https://docs.spring.io/spring-boot/3.3.5/reference/packaging/native-image/introducing-graalvm-native-images.html) +* [Azure Actuator](https://aka.ms/spring/docs/actuator) +* [Spring Reactive Web](https://docs.spring.io/spring-boot/3.3.5/reference/web/reactive.html) +* [Azure Cosmos DB](https://microsoft.github.io/spring-cloud-azure/current/reference/html/index.html#spring-data-support) +* [Spring Boot Actuator](https://docs.spring.io/spring-boot/3.3.5/reference/actuator/index.html) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a Reactive RESTful Web Service](https://spring.io/guides/gs/reactive-rest-service/) +* [How to use Spring Boot Starter with Azure Cosmos DB SQL API](https://aka.ms/spring/msdocs/cosmos) +* [Building a RESTful Web Service with Spring Boot Actuator](https://spring.io/guides/gs/actuator-service/) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) +* [Configure AOT settings in Build Plugin](https://docs.spring.io/spring-boot/3.3.5/how-to/aot.html) +* [Azure Cosmos DB Sample](https://aka.ms/spring/samples/latest/cosmos) + +## GraalVM Native Support + +This project has been configured to let you generate either a lightweight container or a native executable. +It is also possible to run your tests in a native image. + +### Lightweight Container with Cloud Native Buildpacks +If you're already familiar with Spring Boot container images support, this is the easiest way to get started. +Docker should be installed and configured on your machine prior to creating the image. + +To create the image, run the following goal: + +``` +$ ./gradlew bootBuildImage +``` + +Then, you can run the app like any other container: + +``` +$ docker run --rm rtp-activator:0.0.1-SNAPSHOT +``` + +### Executable with Native Build Tools +Use this option if you want to explore more options such as running your tests in a native image. +The GraalVM `native-image` compiler should be installed and configured on your machine. + +NOTE: GraalVM 22.3+ is required. + +To create the executable, run the following goal: + +``` +$ ./gradlew nativeCompile +``` + +Then, you can run the app as follows: +``` +$ build/native/nativeCompile/rtp-activator +``` + +You can also run your existing tests suite in a native image. +This is an efficient way to validate the compatibility of your application. + +To run your existing tests in a native image, run the following goal: + +``` +$ ./gradlew nativeTest +``` + +### Gradle Toolchain support + +There are some limitations regarding Native Build Tools and Gradle toolchains. +Native Build Tools disable toolchain support by default. +Effectively, native image compilation is done with the JDK used to execute Gradle. +You can read more about [toolchain support in the Native Build Tools here](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html#configuration-toolchains). + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..90c9256 --- /dev/null +++ b/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.5' + id 'io.spring.dependency-management' version '1.1.6' + id 'org.graalvm.buildtools.native' version '0.10.3' +} + +group = 'it.gov.pagopa' +version = project.version + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +repositories { + mavenCentral() +} + +//ext { +// set('springCloudAzureVersion', "5.18.0") +//} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.boot:spring-boot-starter-webflux' +// implementation 'com.azure.spring:spring-cloud-azure-starter-actuator' +// implementation 'com.azure.spring:spring-cloud-azure-starter-data-cosmos' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'io.projectreactor:reactor-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +dependencyManagement { + imports { +// mavenBom "com.azure.spring:spring-cloud-azure-dependencies:${springCloudAzureVersion}" + } +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..16a4327 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +version = '0.0.1' \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a4b76b9 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..df97d72 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..f5feea6 --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..9d21a21 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..6e5c1a8 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'rtp-activator' diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile new file mode 100644 index 0000000..f02f2a1 --- /dev/null +++ b/src/main/docker/Dockerfile @@ -0,0 +1,24 @@ +FROM ghcr.io/graalvm/graalvm-community:21.0.2-ol9-20240116@sha256:6e46c711c90bdbc24e23ccdb6e3fba837d660e68dd4ffeb87abbd3d08e115653 AS builder + +WORKDIR /code +COPY . . + +RUN chmod +x ./gradlew && ./gradlew :nativeCompile + +FROM ubuntu:noble-20241011@sha256:99c35190e22d294cdace2783ac55effc69d32896daaa265f0bbedbcde4fbe3e5 AS cve +COPY --from=builder /build/target/rtd-ms-file-register*.jar . + +FROM ubuntu:noble-20241011@sha256:99c35190e22d294cdace2783ac55effc69d32896daaa265f0bbedbcde4fbe3e5 AS runtime + +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --from=builder --chown=1001:root --chmod=0755 /code/build/*-runner /work/application + +RUN useradd --uid 10000 runner +USER 10000 + +EXPOSE 8080 + +ENTRYPOINT ["./application"] diff --git a/src/main/java/it/gov/pagopa/rtp/activator/RtpActivatorApplication.java b/src/main/java/it/gov/pagopa/rtp/activator/RtpActivatorApplication.java new file mode 100644 index 0000000..d258f9d --- /dev/null +++ b/src/main/java/it/gov/pagopa/rtp/activator/RtpActivatorApplication.java @@ -0,0 +1,13 @@ +package it.gov.pagopa.rtp.activator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RtpActivatorApplication { + + public static void main(String[] args) { + SpringApplication.run(RtpActivatorApplication.class, args); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..cc8af0e --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=rtp-activator diff --git a/src/main/terraform/container_app.tf b/src/main/terraform/container_app.tf new file mode 100644 index 0000000..55a4337 --- /dev/null +++ b/src/main/terraform/container_app.tf @@ -0,0 +1,60 @@ +# ------------------------------------------------------------------------------ +# Container app. +# ------------------------------------------------------------------------------ +resource "azurerm_container_app" "rtp-activator" { + name = "${local.project}-auth-ca" + container_app_environment_id = data.azurerm_container_app_environment.rtp-cae.id + resource_group_name = data.azurerm_container_app_environment.rtp-cae.resource_group_name + revision_mode = "Single" + + template { + container { + name = "rtp-activator" + image = var.rtp_activator_image + cpu = var.rtp_activator_cpu + memory = var.rtp_activator_memory + + env { + name = "TZ" + value = "Europe/Rome" + } + + env { + name = "auth.app-log-level" + value = var.rtp_activator_app_log_level + } + + env { + name = "IDENTITY_CLIENT_ID" + secret_name = "identity-client-id" + } + } + + max_replicas = var.rtp_activator_max_replicas + min_replicas = var.rtp_activator_min_replicas + } + + secret { + name = "identity-client-id" + value = "${data.azurerm_user_assigned_identity.rtp-activator.client_id}" + } + + identity { + type = "UserAssigned" + identity_ids = [data.azurerm_user_assigned_identity.rtp-activator.id] + } + + ingress { + external_enabled = true + target_port = 8080 + transport = "http" + + traffic_weight { + latest_revision = true + percentage = 100 + #revision_suffix = formatdate("YYYYMMDDhhmmssZZZZ", timestamp()) + } + } + + tags = var.tags +} \ No newline at end of file diff --git a/src/main/terraform/data.tf b/src/main/terraform/data.tf new file mode 100644 index 0000000..b11a715 --- /dev/null +++ b/src/main/terraform/data.tf @@ -0,0 +1,15 @@ +# ------------------------------------------------------------------------------ +# Container Apps Environment. +# ------------------------------------------------------------------------------ +data "azurerm_container_app_environment" "rtp-cae" { + name = var.cae_name + resource_group_name = var.cae_resource_group_name +} + +# ------------------------------------------------------------------------------ +# Identity for this Container App. +# ------------------------------------------------------------------------------ +data "azurerm_user_assigned_identity" "rtp-activator" { + name = var.id_name + resource_group_name = var.id_resource_group_name +} diff --git a/src/main/terraform/env/dev/backend.ini b/src/main/terraform/env/dev/backend.ini new file mode 100644 index 0000000..5d2d018 --- /dev/null +++ b/src/main/terraform/env/dev/backend.ini @@ -0,0 +1 @@ +subscription=DEV-CSTAR \ No newline at end of file diff --git a/src/main/terraform/env/dev/backend.tfvars b/src/main/terraform/env/dev/backend.tfvars new file mode 100644 index 0000000..2c9b70d --- /dev/null +++ b/src/main/terraform/env/dev/backend.tfvars @@ -0,0 +1,4 @@ +resource_group_name = "terraform-state-rg" +storage_account_name = "tfappdevcstar" +container_name = "terraform-state" +key = "rtp-activator.tfstate" \ No newline at end of file diff --git a/src/main/terraform/env/dev/terraform.tfvars b/src/main/terraform/env/dev/terraform.tfvars new file mode 100644 index 0000000..86443b0 --- /dev/null +++ b/src/main/terraform/env/dev/terraform.tfvars @@ -0,0 +1,42 @@ +# ------------------------------------------------------------------------------ +# General variables. +# ------------------------------------------------------------------------------ +prefix = "cstar" +env_short = "d" +env = "dev" +location = "westeurope" # this will be "italynorth" +location_short = "weu" # this will be "itn" +domain = "rtp" + +tags = { + CreatedBy = "Terraform" + Environment = "dev" + Owner = "cstar" + Source = "https://github.com/pagopa/rtp-activator/tree/main/src/main/terraform" + CostCenter = "TS310 - PAGAMENTI & SERVIZI" + Domain = "rtp" +} + +# ------------------------------------------------------------------------------ +# External resources. +# ------------------------------------------------------------------------------ +cae_name = "cstar-d-tier-0-cae" +cae_resource_group_name = "cstar-d-tier-0-app-rg" +id_name = "cstar-d-tier-0-auth-id" +id_resource_group_name = "cstar-d-tier-0-identity-rg" + +# ------------------------------------------------------------------------------ +# Names of key vault secrets. +# ------------------------------------------------------------------------------ + + +# ------------------------------------------------------------------------------ +# Configuration of the microservice. +# ------------------------------------------------------------------------------ +rtp_activator_app_log_level = "DEBUG" +rtp_activator_image = "ghcr.io/pagopa/rtp-activator:latest" +rtp_activator_cpu = 0.25 +rtp_activator_memory = "0.5Gi" +rtp_activator_max_replicas = 5 +rtp_activator_min_replicas = 1 +rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp-activator" \ No newline at end of file diff --git a/src/main/terraform/env/prod/backend.ini b/src/main/terraform/env/prod/backend.ini new file mode 100644 index 0000000..18b0a97 --- /dev/null +++ b/src/main/terraform/env/prod/backend.ini @@ -0,0 +1 @@ +subscription=PROD-CSTAR \ No newline at end of file diff --git a/src/main/terraform/env/prod/backend.tfvars b/src/main/terraform/env/prod/backend.tfvars new file mode 100644 index 0000000..17e13ee --- /dev/null +++ b/src/main/terraform/env/prod/backend.tfvars @@ -0,0 +1,4 @@ +resource_group_name = "terraform-state-rg" +storage_account_name = "tfappprodcstar" +container_name = "terraform-state" +key = "rtp-activator.tfstate" \ No newline at end of file diff --git a/src/main/terraform/env/prod/terraform.tfvars b/src/main/terraform/env/prod/terraform.tfvars new file mode 100644 index 0000000..b3e1949 --- /dev/null +++ b/src/main/terraform/env/prod/terraform.tfvars @@ -0,0 +1,42 @@ +# ------------------------------------------------------------------------------ +# General variables. +# ------------------------------------------------------------------------------ +prefix = "cstar" +env_short = "p" +env = "prod" +location = "westeurope" # this will be "italynorth" +location_short = "weu" # this will be "itn" +domain = "rtp" + +tags = { + CreatedBy = "Terraform" + Environment = "prod" + Owner = "cstar" + Source = "https://github.com/pagopa/rtp_activator/tree/main/src/main/terraform" + CostCenter = "TS310 - PAGAMENTI & SERVIZI" + Domain = "rtp" +} + +# ------------------------------------------------------------------------------ +# External resources. +# ------------------------------------------------------------------------------ +cae_name = "cstar-p-tier-0-cae" +cae_resource_group_name = "cstar-p-tier-0-app-rg" +id_name = "cstar-p-tier-0-auth-id" +id_resource_group_name = "cstar-p-tier-0-identity-rg" + +# ------------------------------------------------------------------------------ +# Names of key vault secrets. +# ------------------------------------------------------------------------------ + + +# ------------------------------------------------------------------------------ +# Configuration of the microservice. +# ------------------------------------------------------------------------------ +rtp_activator_app_log_level = "DEBUG" +rtp_activator_image = "ghcr.io/pagopa/rtp-activator:latest" +rtp_activator_cpu = 0.25 +rtp_activator_memory = "0.5Gi" +rtp_activator_max_replicas = 5 +rtp_activator_min_replicas = 1 +rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp_activator" \ No newline at end of file diff --git a/src/main/terraform/env/uat/backend.ini b/src/main/terraform/env/uat/backend.ini new file mode 100644 index 0000000..4ec6fba --- /dev/null +++ b/src/main/terraform/env/uat/backend.ini @@ -0,0 +1 @@ +subscription=UAT-CSTAR \ No newline at end of file diff --git a/src/main/terraform/env/uat/backend.tfvars b/src/main/terraform/env/uat/backend.tfvars new file mode 100644 index 0000000..74e2edd --- /dev/null +++ b/src/main/terraform/env/uat/backend.tfvars @@ -0,0 +1,4 @@ +resource_group_name = "terraform-state-rg" +storage_account_name = "tfappuatcstar" +container_name = "terraform-state" +key = "rtp-activator.tfstate" \ No newline at end of file diff --git a/src/main/terraform/env/uat/terraform.tfvars b/src/main/terraform/env/uat/terraform.tfvars new file mode 100644 index 0000000..c8545ad --- /dev/null +++ b/src/main/terraform/env/uat/terraform.tfvars @@ -0,0 +1,42 @@ +# ------------------------------------------------------------------------------ +# General variables. +# ------------------------------------------------------------------------------ +prefix = "cstar" +env_short = "u" +env = "uat" +location = "westeurope" # this will be "italynorth" +location_short = "weu" # this will be "itn" +domain = "rtp" + +tags = { + CreatedBy = "Terraform" + Environment = "uat" + Owner = "cstar" + Source = "https://github.com/pagopa/rtp-activator/tree/main/src/main/terraform" + CostCenter = "TS310 - PAGAMENTI & SERVIZI" + Domain = "rtp" +} + +# ------------------------------------------------------------------------------ +# External resources. +# ------------------------------------------------------------------------------ +cae_name = "cstar-u-tier-0-cae" +cae_resource_group_name = "cstar-u-tier-0-app-rg" +id_name = "cstar-u-tier-0-auth-id" +id_resource_group_name = "cstar-u-tier-0-identity-rg" + +# ------------------------------------------------------------------------------ +# Names of key vault secrets. +# ------------------------------------------------------------------------------ + + +# ------------------------------------------------------------------------------ +# Configuration of the microservice. +# ------------------------------------------------------------------------------ +rtp_activator_app_log_level = "DEBUG" +rtp_activator_image = "ghcr.io/pagopa/rtp-activator:latest" +rtp_activator_cpu = 0.25 +rtp_activator_memory = "0.5Gi" +rtp_activator_max_replicas = 5 +rtp_activator_min_replicas = 1 +rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp-activator" diff --git a/src/main/terraform/locals.tf b/src/main/terraform/locals.tf new file mode 100644 index 0000000..dea9445 --- /dev/null +++ b/src/main/terraform/locals.tf @@ -0,0 +1,6 @@ +locals { + # + # Project label. + # + project = var.domain == "" ? "${var.prefix}-${var.env_short}" : "${var.prefix}-${var.env_short}-${var.domain}" +} \ No newline at end of file diff --git a/src/main/terraform/main.tf b/src/main/terraform/main.tf new file mode 100644 index 0000000..e26dfb6 --- /dev/null +++ b/src/main/terraform/main.tf @@ -0,0 +1,30 @@ +terraform { + required_version = ">= 1.3.5" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "= 3.99.0" + } + } + + backend "azurerm" { + use_oidc = true + } +} + +provider "azurerm" { + features { + key_vault { + purge_soft_delete_on_destroy = false + } + resource_group { + prevent_deletion_if_contains_resources = false + } + } + + use_oidc = true +} + +data "azurerm_subscription" "current" {} + +data "azurerm_client_config" "current" {} \ No newline at end of file diff --git a/src/main/terraform/terraform.sh b/src/main/terraform/terraform.sh new file mode 100755 index 0000000..55ffc26 --- /dev/null +++ b/src/main/terraform/terraform.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +action=$1 +env=$2 + +if [ -z "$action" ]; then + echo "Usage: ./terraform.sh ACTION ENV [PARAMS]" + echo "Missed action: init, apply, plan" + exit 0 +fi + +if [ -z "$env" ]; then + echo "Usage: ./terraform.sh ACTION ENV [PARAMS]" + echo "env should be: dev, uat or prod." + exit 0 +fi + +shift 2 +other=$@ + +source "./env/$env/backend.ini" +az account set -s "${subscription}" + +if echo "init plan apply refresh import output state taint destroy console" | grep -w $action > /dev/null; then + if [ $action = "init" ]; then + terraform init -reconfigure -backend-config="./env/$env/backend.tfvars" + # terraform $action -backend-config="./env/$env/backend.tfvars" $other + elif [ $action = "output" ] || [ $action = "state" ] || [ $action = "taint" ]; then + # init terraform backend + terraform init -reconfigure -backend-config="./env/$env/backend.tfvars" + terraform $action $other + else + # init terraform backend + terraform init -reconfigure -backend-config="./env/$env/backend.tfvars" + terraform $action -var-file="./env/$env/terraform.tfvars" $other + fi +else + echo "Action not allowed." + exit 1 +fi \ No newline at end of file diff --git a/src/main/terraform/variables.tf b/src/main/terraform/variables.tf new file mode 100644 index 0000000..14caa68 --- /dev/null +++ b/src/main/terraform/variables.tf @@ -0,0 +1,109 @@ +# ------------------------------------------------------------------------------ +# Generic variables definition. +# ------------------------------------------------------------------------------ +variable "prefix" { + type = string + validation { + condition = ( + length(var.prefix) <= 6 + ) + error_message = "Max length is 6 chars." + } +} + +variable "env" { + type = string + validation { + condition = ( + length(var.env) <= 4 + ) + error_message = "Max length is 4 chars." + } +} + +variable "env_short" { + type = string + validation { + condition = ( + length(var.env_short) <= 1 + ) + error_message = "Max length is 1 chars." + } +} + +variable "location" { + type = string + default = "westeurope" +} + +variable "location_short" { + type = string + description = "Location short like eg: neu, weu." +} + +variable "tags" { + type = map(any) +} + +variable "domain" { + type = string + default = "" +} + +# ------------------------------------------------------------------------------ +# Container Apps Environment. +# ------------------------------------------------------------------------------ +variable "cae_name" { + type = string +} + +variable "cae_resource_group_name" { + type = string +} + +# ------------------------------------------------------------------------------ +# Identity for this Container App. +# ------------------------------------------------------------------------------ +variable "id_name" { + type = string +} + +variable "id_resource_group_name" { + type = string +} + +# ------------------------------------------------------------------------------ +# Specific to rtp-activator microservice. +# ------------------------------------------------------------------------------ +variable "rtp_activator_app_log_level" { + type = string + default = "DEBUG" +} + +variable "rtp_activator_max_replicas" { + type = number + default = 10 +} + +variable "rtp_activator_min_replicas" { + type = number + default = 1 +} + +variable "rtp_activator_base_url" { + type = string +} + +variable "rtp_activator_cpu" { + type = number + default = 1 +} + +variable "rtp_activator_memory" { + type = string + default = "1Gi" +} + +variable "rtp_activator_image" { + type = string +} diff --git a/src/test/java/it/gov/pagopa/rtp/activator/RtpActivatorApplicationTests.java b/src/test/java/it/gov/pagopa/rtp/activator/RtpActivatorApplicationTests.java new file mode 100644 index 0000000..3d0b211 --- /dev/null +++ b/src/test/java/it/gov/pagopa/rtp/activator/RtpActivatorApplicationTests.java @@ -0,0 +1,13 @@ +package it.gov.pagopa.rtp.activator; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class RtpActivatorApplicationTests { + + @Test + void contextLoads() { + } + +}