Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang authored Apr 5, 2023
0 parents commit 82f2bbe
Show file tree
Hide file tree
Showing 30 changed files with 1,638 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .devops/code-review-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java

# Automatically triggered on PR
# https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#pr-trigger
trigger:
- main
pr:
- main

pool:
vmImage: 'ubuntu-18.04'

variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'

steps:
- task: Cache@2
inputs:
key: 'maven | "$(Agent.OS)" | pom.xml'
restoreKeys: |
maven | "$(Agent.OS)"
maven
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo

- task: SonarCloudPrepare@1
displayName: 'Prepare SonarCloud analysis configuration'
inputs:
SonarCloud: '$(SONARCLOUD_SERVICE_CONN)'
organization: '$(SONARCLOUD_ORG)'
scannerMode: Other
extraProperties: |
sonar.projectKey=$(SONARCLOUD_PROJECT_KEY)
sonar.projectName=$(SONARCLOUD_PROJECT_NAME)
sonar.coverage.exclusions=**/config/*,**/*Mock*,**/model/**,**/entity/*
sonar.cpd.exclusions=**/model/**,**/entity/*
- task: Maven@3
displayName: 'Run Junit Test'
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean verify'
sonarQubeRunAnalysis: true
codeCoverageToolOption: 'JaCoCo'
effectivePomSkip: false
isJacocoCoverageReportXML: true
sqMavenPluginVersionChoice: 'latest'

- task: SonarCloudPublish@1
displayName: 'Publish SonarCloud results on build summary'
inputs:
pollingTimeoutSec: '300'
223 changes: 223 additions & 0 deletions .devops/deploy-pipelines-aks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# Only manual triggers
trigger: none
pr: none

pool:
vmImage: 'ubuntu-22.04'

parameters:
- name: ENV
displayName: Target Environment
type: string
default: dev
values:
- dev
- uat
- prod
- name: SEMVER
displayName: "When packing a release, define the version bump to apply. Use only buildNumber or skip for manual deployment"
type: string
values:
- major
- minor
- patch
- buildNumber
- skip
default: skip
- name: "FORCE_REPLACE_DOCKER_IMAGE"
displayName: "Force the existing docker image to be replaced"
type: boolean
default: False
values:
- False
- True
- name: TEST
displayName: Run integration/smoke tests
type: boolean
default: true

variables:
imageRepository: '$(IMAGE_REPOSITORY_NAME)'
nameSpace: '$(K8S_NAMESPACE)'

${{ if eq(parameters['ENV'], 'dev') }}:
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY_SERVICE_CONN)
dockerRegistryFqdn: $(DEV_CONTAINER_NAMESPACE)
kubernetesServiceConnection: '$(DEV_KUBERNETES_SERVICE_CONN)'
poolImage: 'pagopa-dev-linux'
appInsightsServiceConn: "$(TF_APPINSIGHTS_SERVICE_CONN_DEV)"
appInsightsResourceId: "$(TF_APPINSIGHTS_RESOURCE_ID_DEV)"
${{ if eq(parameters['ENV'], 'uat') }}:
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY_SERVICE_CONN)
dockerRegistryFqdn: $(UAT_CONTAINER_NAMESPACE)
kubernetesServiceConnection: '$(UAT_KUBERNETES_SERVICE_CONN)'
poolImage: 'pagopa-uat-linux'
appInsightsServiceConn: "$(TF_APPINSIGHTS_SERVICE_CONN_UAT)"
appInsightsResourceId: "$(TF_APPINSIGHTS_RESOURCE_ID_UAT)"
${{ if eq(parameters['ENV'], 'prod') }}:
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY_SERVICE_CONN)
dockerRegistryFqdn: $(PROD_CONTAINER_NAMESPACE)
kubernetesServiceConnection: '$(PROD_KUBERNETES_SERVICE_CONN)'
poolImage: 'pagopa-prod-linux'
appInsightsServiceConn: "$(TF_APPINSIGHTS_SERVICE_CONN_PROD)"
appInsightsResourceId: "$(TF_APPINSIGHTS_RESOURCE_ID_PROD)"

${{ if eq(variables['Build.SourceBranchName'], 'merge') }}:
sourceBranch: "main" # force to main branch
${{ if ne(variables['Build.SourceBranchName'], 'merge') }}:
sourceBranch: ${{ variables['Build.SourceBranchName'] }}



resources:
repositories:
- repository: pagopaCommons
type: github
name: pagopa/azure-pipeline-templates
ref: refs/tags/v2.10.1
endpoint: 'io-azure-devops-github-ro'

stages:

# Create a release on GitHub
- stage: Release
jobs:
- job: make_release
steps:
- checkout: self
clean: true
persistCredentials: true

- ${{ if ne(parameters.SEMVER, 'skip') }}:
- template: templates/maven-github-release/template.yaml@pagopaCommons
parameters:
release_branch: $(sourceBranch)
gitEmail: $(GIT_EMAIL)
gitUsername: $(GIT_USERNAME)
gitHubConnection: $(GITHUB_CONNECTION)
${{ if ne(parameters.SEMVER, 'skip') }}:
semver: '${{ parameters.SEMVER }}'
${{ if eq(parameters.SEMVER, 'skip') }}:
semver: 'buildNumber' # this case is impossible due to main condition, but it is necessary to work property

- template: templates/maven-github-current-version/template.yaml@pagopaCommons

# Build and Push Docker Image
- stage: Build
dependsOn: Release
variables:
current_version: $[ stageDependencies.Release.make_release.outputs['current_version.value'] ]
jobs:
- job: "build"
steps:
- checkout: self
persistCredentials: true

- script: |
git checkout $(sourceBranch)
displayName: Checkout and update branch
- template: templates/docker-release/template.yaml@pagopaCommons
parameters:
CONTAINER_REGISTRY_SERVICE_CONN: $(dockerRegistryServiceConnection)
CONTAINER_REGISTRY_FQDN: $(dockerRegistryFqdn)
DOCKER_IMAGE_NAME: $(imageRepository)
DOCKER_IMAGE_TAG: $(current_version)
FORCE_REPLACE_DOCKER_IMAGE: ${{ parameters.FORCE_REPLACE_DOCKER_IMAGE }}

# # Testing the docker image
# - stage: Smoke_Test
# dependsOn:
# - Build
# condition: and(succeeded(), eq('${{ parameters.TEST }}', 'true'))
# jobs:
# - job: smoke_tests
# steps:
# - checkout: self
# persistCredentials: true
#
# - script: |
# git checkout $(sourceBranch)
# displayName: Checkout and update branch
#
# - task: Docker@2
# displayName: "Docker login"
# inputs:
# containerRegistry: "$(dockerRegistryServiceConnection)"
# command: "login"
#
# - task: Bash@3
# displayName: 'Run Smoke Tests'
# inputs:
# targetType: 'inline'
# script: |
# cd ./integration-test
# sh run_integration_test.sh
# env:
# containerRegistry: $(dockerRegistryFqdn)

# Deploy on K8s with Helm
- stage: Deploy
# condition: not(failed('Smoke_Test'))
dependsOn:
- Release
- Build
# - Smoke_Test
variables:
deploy_version: $[ stageDependencies.Release.make_release.outputs['current_version.value'] ]
jobs:
- deployment: "deploy"
pool:
name: $(poolImage)
environment: ${{ parameters['ENV'] }}
strategy:
runOnce:
deploy:
steps:
- checkout: self
persistCredentials: true

- script: |
git checkout $(sourceBranch)
displayName: Checkout and update branch
- template: templates/helm-microservice-chart-setup/template.yaml@pagopaCommons
parameters:
DEPLOY_VERSION: $(deploy_version)

- template: templates/helm-microservice-chart-deploy/template.yaml@pagopaCommons
parameters:
DO_DEPLOY: true
ENV: ${{ parameters['ENV'] }}
KUBERNETES_SERVICE_CONN: ${{ variables.kubernetesServiceConnection }}
NAMESPACE: $(nameSpace)
APP_NAME: $(imageRepository)
VALUE_FILE: "helm/values-${{ parameters['ENV'] }}.yaml"
DEPLOY_VERSION: $(deploy_version)
APPINSIGHTS_SERVICE_CONN: ${{ variables.appInsightsServiceConn }}
APPINSIGHTS_RESOURCE_ID: ${{ variables.appInsightsResourceId }}


# Run Tests
# - stage: Integration_Test
# dependsOn:
# - Deploy
# condition: and(succeeded(), eq('${{ parameters.TEST }}', 'true'))
# jobs:
# - job: integration_tests
# steps:
# - checkout: self
# persistCredentials: true
#
# - script: |
# git checkout $(sourceBranch)
# displayName: Checkout and update branch
#
# - task: Bash@3
# displayName: 'Run Integration Tests'
# inputs:
# targetType: 'inline'
# script: |
# cd ./integration-test/src
# yarn install
# yarn test:${{ parameters.ENV }}
Loading

0 comments on commit 82f2bbe

Please sign in to comment.