Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: P4PADEV-244 create structure new microservice arc #1

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
47e10ad
P4PADEV-244 First commit
Giuseppe-LaManna May 2, 2024
675fc00
P4PADEV-244 added helm
Giuseppe-LaManna May 2, 2024
e50392e
P4PADEV-244 added new dependencies and updated application.yml
Giuseppe-LaManna May 2, 2024
c0368d0
P4PADEV-244 added common SwaggerConfig
Giuseppe-LaManna May 2, 2024
e95cf7d
P4PADEV-244 added Dockerfile
Giuseppe-LaManna May 2, 2024
5dad657
P4PADEV-244 fix directory
Giuseppe-LaManna May 2, 2024
befd704
P4PADEV-244 update dependencies and dockerfile and added file templat…
Giuseppe-LaManna May 3, 2024
dc43aa5
Merge branch 'develop' into P4ADEV-244-create-structure-new-microserv…
Giuseppe-LaManna May 3, 2024
c62f299
P4PADEV-244 update deploy-pipelines.yml and main class
Giuseppe-LaManna May 3, 2024
cb903f9
P4PADEV-244 added values
Giuseppe-LaManna May 3, 2024
c8e06ab
P4PADEV-244 update code-review-pipelines.yml
Giuseppe-LaManna May 3, 2024
465f413
P4PADEV-244 update Dockerfile and values
Giuseppe-LaManna May 3, 2024
54b8eb8
P4PADEV-244 update Dockerfile, values and code-review and deploy-pipe…
Giuseppe-LaManna May 3, 2024
577ab33
P4PADEV-244 update Dockerfile
Giuseppe-LaManna May 3, 2024
8bef0b7
P4PADEV-244 added jacoco
Giuseppe-LaManna May 3, 2024
256775d
P4PADEV-244 added sonarqube
Giuseppe-LaManna May 3, 2024
cbca3e6
P4PADEV-244 update dependencies
Giuseppe-LaManna May 6, 2024
93c1714
P4PADEV-244 added test dependencies
Giuseppe-LaManna May 6, 2024
9189120
P4PADEV-244 updated dependencies
Giuseppe-LaManna May 6, 2024
698ec9a
P4PADEV-244 added keyvault
Giuseppe-LaManna May 6, 2024
f4496a5
P4PADEV-244 added chart lock
Giuseppe-LaManna May 8, 2024
7103f97
P4PADEV-244 updated gradle plugins
Giuseppe-LaManna May 8, 2024
3bdb780
P4PADEV-244 updated values
Giuseppe-LaManna May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .devops/code-review-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pr:
- dev
- develop
- uat
- main

Expand All @@ -22,6 +22,32 @@ steps:
sonar.projectName=$(SONARCLOUD_PROJECT_NAME)
sonar.exclusions='**/enums/**, **/model/**, **/dto/**, **/*Constant*, **/*Config.java, **/*Scheduler.java, **/*Application.java, **/src/test/**, **/Dummy*.java'

- task: Gradle@3
inputs:
workingDirectory: './'
gradleWrapperFile: './gradlew'
tasks: 'clean build jacocoTestReport'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
sonarQubeRunAnalysis: false

- bash: xmlReportPaths=$(find "$(pwd)" -path '*jacoco.xml' | sed 's/.*/&/' | tr '\n' ','); echo "##vso[task.setvariable variable=xmlReportPaths]$xmlReportPaths"
displayName: finding jacoco.xml

- task: Gradle@3
inputs:
workingDirectory: './'
gradleWrapperFile: './gradlew'
tasks: "sonar"
options: '-Dsonar.coverage.jacoco.xmlReportPaths=$(xmlReportPaths) -Dorg.gradle.jvmargs=-Xmx4096M'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
sonarQubeRunAnalysis: false
sqGradlePluginVersionChoice: 'build'

- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'
148 changes: 145 additions & 3 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

parameters:
- name: 'executeBuild'
displayName: 'Launch docker build'
type: boolean
default: true

trigger:
branches:
include:
Expand All @@ -7,12 +16,145 @@ trigger:
paths:
include:
- src/*
- build.gradle
- build.gradle.kts
- helm/*
- Dockerfile
- settings.gradle
- settings.gradle.kts

pr: none

resources:
- repo: self
- repo: self

variables:

# vmImageNameDefault: 'ubuntu-latest'
vmImageNameDefault: ubuntu-22.04

imageRepository: '$(K8S_IMAGE_REPOSITORY_NAME)'
deployNamespace: '$(DEPLOY_NAMESPACE)'
helmReleaseName : '$(HELM_RELEASE_NAME)'
canDeploy: true

${{ if eq(variables['Build.SourceBranch'], 'refs/heads/uat') }}:
environment: 'UAT'
dockerRegistryName: '$(UAT_CONTAINER_REGISTRY_NAME)'
dockerRegistryServiceConnection: '$(UAT_CONTAINER_REGISTRY_SERVICE_CONN)'
kubernetesServiceConnection: '$(UAT_KUBERNETES_SERVICE_CONN)'
containerRegistry: '$(UAT_CONTAINER_REGISTRY_NAME)'
selfHostedAgentPool: $(UAT_AGENT_POOL)

${{ elseif eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
environment: 'PROD'
dockerRegistryName: '$(PROD_CONTAINER_REGISTRY_NAME)'
dockerRegistryServiceConnection: '$(PROD_CONTAINER_REGISTRY_SERVICE_CONN)'
kubernetesServiceConnection: '$(PROD_KUBERNETES_SERVICE_CONN)'
containerRegistry: '$(PROD_CONTAINER_REGISTRY_NAME)'
selfHostedAgentPool: $(PROD_AGENT_POOL)

${{ else }}:
environment: 'DEV'
dockerRegistryName: '$(DEV_CONTAINER_REGISTRY_NAME)'
dockerRegistryServiceConnection: '$(DEV_CONTAINER_REGISTRY_SERVICE_CONN)'
kubernetesServiceConnection: '$(DEV_KUBERNETES_SERVICE_CONN)'
containerRegistry: '$(DEV_CONTAINER_REGISTRY_NAME)'
selfHostedAgentPool: $(DEV_AGENT_POOL)

stages:
- stage: 'stage_build'
condition: eq(variables.canDeploy, true)
displayName: 'Build and publish image to ${{ variables.environment }} registry'
jobs:
- job: job_build
displayName: Build
pool:
vmImage: $(vmImageNameDefault)
steps:
- task: Bash@3
displayName: Get app version
name: getAppVersion
condition: and(succeeded(), eq(variables.canDeploy, true))
inputs:
targetType: 'inline'
script: |
version=$(cat build.gradle.kts | grep "version = '.*'" | cut -d"'" -f2)
echo "Building $version version"
echo "##vso[task.setvariable variable=appVersion;isOutput=true]$version"
failOnStderr: true

- task: Docker@2
condition: and(succeeded(), ${{ parameters.executeBuild }})
displayName: 'Build and publish $(imageRepository) image'
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'buildAndPush'
tags: |
latest
$(Build.SourceVersion)
$(getAppVersion.appVersion)

- task: PublishPipelineArtifact@1
displayName: 'Publish manifests into pipeline artifacts'
condition: succeeded()
inputs:
targetPath: '$(Build.Repository.LocalPath)/helm'
artifact: 'helm'
publishLocation: 'pipeline'

- stage: stage_deploy
displayName: 'Deploy to ${{ variables.environment }} K8S'
dependsOn: ['stage_build']
variables:
appVersion: $[ stageDependencies.stage_build.job_build.outputs['getAppVersion.appVersion'] ]
condition: and(succeeded(), eq(variables.canDeploy, true))
jobs:
- deployment: job_deploy
displayName: 'Deploy'
pool:
name: $(selfHostedAgentPool)
environment: '$(environment)'
strategy:
runOnce:
deploy:
steps:
- download: none
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'helm'
targetPath: '$(Pipeline.Workspace)/helm'
- task: KubectlInstaller@0
- task: Bash@3
name: helm_dependency_build
displayName: Helm dependency build
inputs:
workingDirectory: '$(Pipeline.Workspace)/helm'
targetType: 'inline'
script: |
helm repo add pagopa-microservice https://pagopa.github.io/aks-microservice-chart-blueprint
helm dep build
failOnStderr: true
- bash: |
echo 'microservice-chart:
podAnnotations:
"build/buildNumber": "$(Build.BuildNumber)"
"build/appVersion": "$(appVersion)"
"build/sourceVersion": "$(Build.SourceVersion)"' > buildMetadata.yaml
displayName: Writing build metadata

- task: HelmDeploy@0
displayName: Helm upgrade
inputs:
kubernetesServiceEndpoint: ${{ variables.kubernetesServiceConnection }}
namespace: '$(deployNamespace)'
command: upgrade
chartType: filepath
chartPath: $(Pipeline.Workspace)/helm
chartName: ${{ variables.helmReleaseName }}
releaseName: ${{ variables.helmReleaseName }}
valueFile: "$(Pipeline.Workspace)/helm/values-${{ lower(variables.environment) }}.yaml"
install: true
waitForExecution: true
arguments: --timeout 5m0s
--values buildMetadata.yaml
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Build
#
FROM amazoncorretto:17-alpine3.19@sha256:2122cb140fa94053abce343fb854d24f4c62ba3c1ac701882dce12980396b477 AS buildtime

WORKDIR /build
COPY . .

RUN chmod +x ./gradlew
RUN ./gradlew bootJar

#
# Docker RUNTIME
#
FROM amazoncorretto:17-alpine3.19@sha256:2122cb140fa94053abce343fb854d24f4c62ba3c1ac701882dce12980396b477 AS runtime

VOLUME /tmp
WORKDIR /app

COPY --from=buildtime /build/build/libs/*.jar /app/app.jar
# The agent is enabled at runtime via JAVA_TOOL_OPTIONS.
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.5.2/applicationinsights-agent-3.5.2.jar /app/applicationinsights-agent.jar

RUN chown -R nobody:nobody /app

EXPOSE 8080
antonioT90 marked this conversation as resolved.
Show resolved Hide resolved

USER 65534 # user nobody

ENTRYPOINT ["java","-jar","/app/app.jar"]
52 changes: 52 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
plugins {
java
id("org.springframework.boot") version "3.2.5"
id("io.spring.dependency-management") version "1.1.4"
}

group = "it.gov.pagopa"
version = "0.0.1"

java {
sourceCompatibility = JavaVersion.VERSION_17
}

configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0")
implementation("org.codehaus.janino:janino:3.1.12")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")

antonioT90 marked this conversation as resolved.
Show resolved Hide resolved
}

tasks.withType<Test> {
useJUnitPlatform()
}


val projectInfo = mapOf(
"artifactId" to project.name,
"version" to project.version
)

tasks {
val processResources by getting(ProcessResources::class) {
filesMatching("**/application.yml") {
expand(projectInfo)
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading