Skip to content

Commit a3e2a21

Browse files
Vitolo-Andreadiegolagospagopastedelia
authored
feat: Implementation emd-message-core microservice [MMC-12] (#1)
Co-authored-by: diegoitaliait <[email protected]> Co-authored-by: stefanodel <[email protected]>
1 parent 4405831 commit a3e2a21

File tree

103 files changed

+4386
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4386
-27
lines changed

.devops/code-review-pipelines.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Build your Java project and run tests with Apache Maven.
2+
# Add steps that analyze code, save build artifacts, deploy, and more:
3+
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
4+
5+
trigger:
6+
- main
7+
8+
pool:
9+
#vmImage: 'ubuntu-latest'
10+
vmImage: ubuntu-22.04
11+
12+
#variables:
13+
# MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
14+
# MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
15+
16+
steps:
17+
# - task: Cache@2
18+
# inputs:
19+
# key: 'maven | "$(Agent.OS)" | pom.xml'
20+
# restoreKeys: |
21+
# maven | "$(Agent.OS)"
22+
# maven
23+
# path: $(MAVEN_CACHE_FOLDER)
24+
# displayName: Cache Maven local repo
25+
26+
- task: SonarCloudPrepare@1
27+
displayName: 'Prepare SonarCloud analysis configuration'
28+
inputs:
29+
SonarCloud: '$(SONARCLOUD_SERVICE_CONN)'
30+
organization: '$(SONARCLOUD_ORG)'
31+
scannerMode: Other
32+
extraProperties: |
33+
sonar.projectKey=$(SONARCLOUD_PROJECT_KEY)
34+
sonar.projectName=$(SONARCLOUD_PROJECT_NAME)
35+
sonar.exclusions='**/enums/**, **/model/**, **/dto/**, **/*Constant*, **/*Config.java, **/*Scheduler.java, **/*Application.java, **/src/test/**, **/Dummy*.java'
36+
37+
# - task: DownloadSecureFile@1
38+
# displayName: 'download settings.xml for Maven'
39+
# name: settingsxml
40+
# inputs:
41+
# secureFile: '$(SETTINGS_XML_RO_SECURE_FILE_NAME)'
42+
# retryCount: '2'
43+
44+
# options: '-B -s $(settingsxml.secureFilePath)'
45+
- task: Maven@3
46+
inputs:
47+
mavenPomFile: 'pom.xml'
48+
goals: 'clean org.jacoco:jacoco-maven-plugin:0.8.8:prepare-agent verify org.jacoco:jacoco-maven-plugin:0.8.8:report org.jacoco:jacoco-maven-plugin:0.8.8:report-aggregate '
49+
options: '-B'
50+
publishJUnitResults: true
51+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
52+
javaHomeOption: 'JDKVersion'
53+
jdkVersionOption: '1.17'
54+
mavenVersionOption: 'Default'
55+
mavenAuthenticateFeed: false
56+
effectivePomSkip: false
57+
sonarQubeRunAnalysis: false
58+
- bash: xmlReportPaths=$(find "$(pwd)" -path '*jacoco.xml' | sed 's/.*/&/' | tr '\n' ','); echo "##vso[task.setvariable variable=xmlReportPaths]$xmlReportPaths"
59+
displayName: finding jacoco.xml
60+
61+
# options: '-B -s $(settingsxml.secureFilePath) -Dsonar.coverage.jacoco.xmlReportPaths=$(xmlReportPaths)'
62+
63+
- task: Maven@3
64+
inputs:
65+
mavenPomFile: 'pom.xml'
66+
goals: 'sonar:sonar'
67+
options: '-B -Dsonar.coverage.jacoco.xmlReportPaths=$(xmlReportPaths)'
68+
publishJUnitResults: false
69+
javaHomeOption: 'JDKVersion'
70+
jdkVersionOption: '1.17'
71+
mavenVersionOption: 'Default'
72+
mavenAuthenticateFeed: false
73+
effectivePomSkip: false
74+
sonarQubeRunAnalysis: true
75+
isJacocoCoverageReportXML: false
76+
sqMavenPluginVersionChoice: 'latest'
77+
- task: SonarCloudPublish@1
78+
inputs:
79+
pollingTimeoutSec: '300'

.devops/deploy-pipelines.yml

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
2+
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
3+
4+
parameters:
5+
- name: 'executeBuild'
6+
displayName: 'Launch maven and docker build'
7+
type: boolean
8+
default: true
9+
10+
trigger:
11+
branches:
12+
include:
13+
- release-*
14+
- main
15+
paths:
16+
include:
17+
- src/*
18+
- helm/*
19+
- pom.xml
20+
- Dockerfile
21+
22+
pr: none
23+
24+
resources:
25+
- repo: self
26+
27+
variables:
28+
29+
# vmImageNameDefault: 'ubuntu-latest'
30+
vmImageNameDefault: ubuntu-22.04
31+
32+
imageRepository: '$(K8S_IMAGE_REPOSITORY_NAME)'
33+
deployNamespace: '$(DEPLOY_NAMESPACE)'
34+
helmReleaseName : '$(HELM_RELEASE_NAME)'
35+
settingsXmlROsecureFileName: '$(SETTINGS_XML_RO_SECURE_FILE_NAME)'
36+
settingsXmlSecureFileName: '$(SETTINGS_XML_RO_SECURE_FILE_NAME)'
37+
canDeploy: true
38+
39+
# If the branch is develop or a feature branch starting with CEN, deploy in DEV environment
40+
${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/release-dev') }}:
41+
environment: 'DEV'
42+
dockerRegistryServiceConnection: '$(DEV_CONTAINER_REGISTRY_SERVICE_CONN)'
43+
kubernetesServiceConnection: '$(DEV_KUBERNETES_SERVICE_CONN)'
44+
containerRegistry: '$(DEV_CONTAINER_REGISTRY_NAME)'
45+
selfHostedAgentPool: $(DEV_AGENT_POOL)
46+
47+
${{ elseif startsWith(variables['Build.SourceBranch'], 'refs/heads/release-uat') }}:
48+
environment: 'UAT'
49+
dockerRegistryServiceConnection: '$(UAT_CONTAINER_REGISTRY_SERVICE_CONN)'
50+
kubernetesServiceConnection: '$(UAT_KUBERNETES_SERVICE_CONN)'
51+
containerRegistry: '$(UAT_CONTAINER_REGISTRY_NAME)'
52+
selfHostedAgentPool: $(UAT_AGENT_POOL)
53+
54+
${{ elseif or(eq(variables['Build.SourceBranch'], 'refs/heads/main'),eq(variables['Build.SourceBranch'], 'refs/heads/release-prod')) }}:
55+
environment: 'PROD'
56+
dockerRegistryServiceConnection: '$(PROD_CONTAINER_REGISTRY_SERVICE_CONN)'
57+
kubernetesServiceConnection: '$(PROD_KUBERNETES_SERVICE_CONN)'
58+
containerRegistry: '$(PROD_CONTAINER_REGISTRY_NAME)'
59+
selfHostedAgentPool: $(PROD_AGENT_POOL)
60+
61+
${{ else }}:
62+
environment: 'DEV'
63+
dockerRegistryServiceConnection: '$(DEV_CONTAINER_REGISTRY_SERVICE_CONN)'
64+
kubernetesServiceConnection: '$(DEV_KUBERNETES_SERVICE_CONN)'
65+
containerRegistry: '$(DEV_CONTAINER_REGISTRY_NAME)'
66+
selfHostedAgentPool: $(DEV_AGENT_POOL)
67+
68+
stages:
69+
- stage: 'pom_version'
70+
displayName: Release
71+
condition: eq(variables.canDeploy, true)
72+
jobs:
73+
- job: POM
74+
displayName: POM
75+
pool:
76+
vmImage: $(vmImageNameDefault)
77+
steps:
78+
- task: Bash@3
79+
displayName: Get POM version
80+
name: getpomversion
81+
condition: and(succeeded(), eq(variables.canDeploy, true))
82+
inputs:
83+
targetType: 'inline'
84+
script: |
85+
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
86+
echo "##vso[task.setvariable variable=outputpomversion;isOutput=true]$version"
87+
failOnStderr: true
88+
89+
- stage: 'build'
90+
displayName: 'Build_and_Publish_to_${{ variables.environment }}'
91+
dependsOn: 'pom_version'
92+
variables:
93+
pomversion: $[ stageDependencies.Release.POM.outputs['getpomversion.outputpomversion'] ]
94+
jobs:
95+
- job: Build
96+
displayName: Build
97+
pool:
98+
vmImage: $(vmImageNameDefault)
99+
steps:
100+
- task: Docker@2
101+
condition: and(succeeded(), ${{ parameters.executeBuild }})
102+
displayName: 'Publish_image_to_${{ variables.environment }}'
103+
inputs:
104+
containerRegistry: '$(dockerRegistryServiceConnection)'
105+
repository: '$(imageRepository)'
106+
command: 'buildAndPush'
107+
tags: |
108+
$(Build.BuildId)
109+
latest
110+
$(pomversion)
111+
# - task: PublishPipelineArtifact@1
112+
# displayName: 'Publish Artifact manifests'
113+
# condition: and(succeeded(), eq(variables.canDeploy, true))
114+
# inputs:
115+
# targetPath: '$(Build.Repository.LocalPath)/manifests'
116+
# artifact: 'manifests'
117+
# publishLocation: 'pipeline'
118+
119+
- stage: 'publish_artifact_helm'
120+
displayName: 'Publish_artifact_Helm'
121+
dependsOn: ['build']
122+
jobs:
123+
- job: Publish_artifact_helm
124+
displayName: Publish_artifact_helm
125+
pool:
126+
vmImage: $(vmImageNameDefault)
127+
steps:
128+
- task: PublishPipelineArtifact@1
129+
displayName: 'Publish Artifact manifests'
130+
condition: succeeded()
131+
inputs:
132+
targetPath: '$(Build.Repository.LocalPath)/helm'
133+
artifact: 'helm'
134+
publishLocation: 'pipeline'
135+
136+
- stage: 'deploy'
137+
displayName: 'Deploy to ${{ variables.environment }} K8S'
138+
dependsOn: ['publish_artifact_helm']
139+
condition: and(succeeded(), eq(variables.canDeploy, true))
140+
variables:
141+
pomversion: $[ stageDependencies.Release.POM.outputs['getpomversion.outputpomversion'] ]
142+
jobs:
143+
- deployment: 'Deploy_to_${{ variables.environment }}'
144+
displayName: 'Deploy to ${{ variables.environment }} K8S'
145+
pool:
146+
name: $(selfHostedAgentPool)
147+
environment: '$(environment)'
148+
strategy:
149+
runOnce:
150+
deploy:
151+
steps:
152+
- download: none
153+
- task: DownloadPipelineArtifact@2
154+
inputs:
155+
buildType: 'current'
156+
artifactName: 'helm'
157+
targetPath: '$(Pipeline.Workspace)/helm'
158+
- task: KubectlInstaller@0
159+
- task: Bash@3
160+
name: helm_dependency_build
161+
displayName: Helm dependency build
162+
inputs:
163+
workingDirectory: '$(Pipeline.Workspace)/helm'
164+
targetType: 'inline'
165+
script: |
166+
helm repo add pagopa-microservice https://pagopa.github.io/aks-microservice-chart-blueprint
167+
helm dep build
168+
failOnStderr: true
169+
- task: HelmDeploy@0
170+
displayName: Helm upgrade
171+
inputs:
172+
kubernetesServiceEndpoint: ${{ variables.kubernetesServiceConnection }}
173+
namespace: '$(deployNamespace)'
174+
command: upgrade
175+
chartType: filepath
176+
chartPath: $(Pipeline.Workspace)/helm
177+
chartName: ${{ variables.helmReleaseName }}
178+
releaseName: ${{ variables.helmReleaseName }}
179+
valueFile: "$(Pipeline.Workspace)/helm/values-${{ lower(variables.environment) }}.yaml"
180+
install: true
181+
waitForExecution: true
182+
arguments: "--timeout 5m0s --debug"
183+
- task: KubernetesManifest@0
184+
displayName: Patch
185+
inputs:
186+
kubernetesServiceConnection: ${{ variables.kubernetesServiceConnection }}
187+
namespace: '$(deployNamespace)'
188+
action: patch
189+
kind: deployment
190+
name: '$(helmReleaseName)-microservice-chart'
191+
mergeStrategy: strategic
192+
patch: '{"spec":{"template":{"metadata":{"annotations":{"buildNumber":"$(Build.BuildNumber)"}}}}}'

.github/workflows/pr-title.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
requireScope: false
3232
# Configure additional validation for the subject based on a regex.
3333
# This example ensures the subject starts with an uppercase character.
34-
subjectPattern: ^[A-Z].+$
34+
subjectPattern: ^.+$
3535
# If `subjectPattern` is configured, you can use this property to override
3636
# the default error message that is shown when the pattern doesn't match.
3737
# The variables `subject` and `title` can be used within the message.
@@ -53,4 +53,4 @@ jobs:
5353
validateSingleCommit: false
5454
# Related to `validateSingleCommit` you can opt-in to validate that the PR
5555
# title matches a single commit to avoid confusion.
56-
validateSingleCommitMatchesPrTitle: false
56+
validateSingleCommitMatchesPrTitle: false

.gitignore

+34-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
# Compiled class file
2-
*.class
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
/.mvn/wrapper/maven-wrapper.properties
5+
!**/src/main/**/target/
6+
!**/src/test/**/target/
7+
/src/test/resources/secrets/*
8+
/mvnw
9+
/mvnw.cmd
310

4-
# Log file
5-
*.log
11+
### STS ###
12+
.apt_generated
13+
.classpath
14+
.factorypath
15+
.project
16+
.settings
17+
.springBeans
18+
.sts4-cache
619

7-
# BlueJ files
8-
*.ctxt
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
925

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
26+
### NetBeans ###
27+
/nbproject/private/
28+
/nbbuild/
29+
/dist/
30+
/nbdist/
31+
/.nb-gradle/
32+
build/
33+
!**/src/main/**/build/
34+
!**/src/test/**/build/
35+
36+
### VS Code ###
37+
.vscode/
1238

13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
2139

22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
24-
replay_pid*

Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Build
3+
#
4+
FROM maven:3.9.6-amazoncorretto-17-al2023@sha256:459be099faa25a32c06cd45ed1ef2bc9dbbf8a5414da4e72349459a1bb4d6166 AS buildtime
5+
6+
WORKDIR /build
7+
8+
COPY pom.xml .
9+
COPY src ./src
10+
11+
RUN mvn clean package -DskipTests
12+
13+
#
14+
# Docker RUNTIME
15+
#
16+
FROM amazoncorretto:17-alpine3.19@sha256:539a0a188ce5a2bed985aa311e9a26d473c6c3f37d08d4fc8b6cf6c18075b9ab AS runtime
17+
18+
RUN apk add --no-cache shadow vim curl net-tools bind-tools netcat-openbsd wget
19+
20+
RUN useradd --uid 10000 runner
21+
22+
WORKDIR /app
23+
24+
COPY --from=buildtime /build/target/*.jar /app/app.jar
25+
# The agent is enabled at runtime via JAVA_TOOL_OPTIONS.
26+
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.19/applicationinsights-agent-3.4.19.jar /app/applicationinsights-agent.jar
27+
28+
RUN chown -R runner:runner /app
29+
30+
USER 10000
31+
32+
ENTRYPOINT ["java","-jar","/app/app.jar"]

0 commit comments

Comments
 (0)