Skip to content

Commit

Permalink
Merge pull request #8 from pagopa/PPD-206-CRUD-GPS
Browse files Browse the repository at this point in the history
BDD
  • Loading branch information
jacopocarlini authored Jul 6, 2022
2 parents 863d06c + 5fe94e9 commit 4ce1f5c
Show file tree
Hide file tree
Showing 15 changed files with 638 additions and 161 deletions.
346 changes: 263 additions & 83 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,95 +6,275 @@ pool:
vmImage: 'ubuntu-20.04'

parameters:
- name: environment
- name: ENV
displayName: Target Environment
type: string
default: uat
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: TEST
displayName: Run tests
type: boolean
default: false

variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
BUILD_NUMBER: $(Build.BuildNumber)
imageRepository: 'cgn-onboarding-portal-backend'
${{ if eq(parameters['environment'], 'uat') }}:
${{ if eq(parameters['ENV'], 'dev') }}:
AZURE_SUBSCRIPTION: $(DEV_AZURE_SUBSCRIPTION)
RESOURCE_GROUP: $(DEV_WEB_APP_RESOURCE_GROUP_NAME)
APP_NAME: $(DEV_WEB_APP_NAME)
STAGE: "d"
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY)
dockerNamespace: $(DEV_CONTAINER_NAMESPACE)
${{ if eq(parameters['ENV'], 'uat') }}:
AZURE_SUBSCRIPTION: $(UAT_AZURE_SUBSCRIPTION)
RESOURCE_GROUP: $(UAT_WEB_APP_RESOURCE_GROUP_NAME)
APP_NAME: $(UAT_WEB_APP_NAME)
STAGE: "u"
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY)
dockerNamespace: microserviceuarc.azurecr.io
connectedServiceName: $(UAT_AZURE_SUBSCRIPTION)
webAppName: $(UAT_WEB_APP_NAME)
${{ if eq(parameters['environment'], 'prod') }}:
dockerNamespace: $(UAT_CONTAINER_NAMESPACE)
${{ if eq(parameters['ENV'], 'prod') }}:
AZURE_SUBSCRIPTION: $(PROD_AZURE_SUBSCRIPTION)
RESOURCE_GROUP: $(PROD_WEB_APP_RESOURCE_GROUP_NAME)
APP_NAME: $(PROD_WEB_APP_NAME)
STAGE: "p"
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY)
dockerNamespace: microserviceparc.azurecr.io
connectedServiceName: $(PROD_AZURE_SUBSCRIPTION)
webAppName: $(PROD_WEB_APP_NAME)
steps:
- task: Bash@3
displayName: Check Version and Branch
inputs:
targetType: 'inline'
script: |
version=$(cat pom.xml | grep '^.*<version>' | sed -n 2p | awk -F'[><]' '{print $3}')
branch="$(Build.SourceBranch)"
if [[ "$branch" != "refs/heads/master" && ! "$branch" =~ "refs/tags/.*" && "${{ parameters.environment }}" == "prod" ]]; then
echo "Deploy branch $branch is not allowed."
exit 1
fi
if [[ "$version" == *SNAPSHOT && "${{ parameters.environment }}" == "prod" ]]; then
echo "Version $version is not allowed."
exit 1
fi
failOnStderr: true

- 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: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
sonarQubeRunAnalysis: false

- task: Bash@3
displayName: Get POM version
name: getpomversion
inputs:
targetType: 'inline'
script: |
version=$(cat pom.xml | grep '^.*<version>' | sed -n 2p | awk -F'[><]' '{print $3}')
echo "##vso[task.setvariable variable=outputpomversion;isOutput=true]$version"
failOnStderr: true

- task: Docker@2
displayName: Build and push an image to container registry
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'buildAndPush'
tags: |
$(Build.BuildId)
latest
$(getpomversion.outputpomversion)
- task: AzureRMWebAppDeployment@4
displayName: Azure App Service Deploy
inputs:
appType: webAppContainer
ConnectedServiceName: '$(connectedServiceName)'
WebAppName: '$(webAppName)'
DockerNamespace: '$(dockerNamespace)'
DockerRepository: '$(imageRepository)'
DockerImageTag: '$(Build.BuildId)'
dockerNamespace: $(PROD_CONTAINER_NAMESPACE)
${{ if eq(variables['Build.SourceBranchName'], 'merge') }}:
SOURCE_BRANCH: "main" # force to main branch
${{ if ne(variables['Build.SourceBranchName'], 'merge') }}:
SOURCE_BRANCH: ${{ variables['Build.SourceBranchName'] }}



MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: "-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)"
title: ""
sha: ""
tag: ""

stages:

# Create a release on GitHub
- stage: release_service
condition: ne('${{ parameters.SEMVER }}', 'skip')
pool:
vmImage: "ubuntu-latest"
jobs:
- job: releaseService
steps:
- checkout: self
clean: true
persistCredentials: true

- script: |
git checkout $(SOURCE_BRANCH)
- script: |
git config --global user.name "$(GIT_USERNAME)"
git config --global user.email "$(GIT_EMAIL)"
- template: azure-templates/maven-versioning.yml
parameters:
semver: "${{ parameters.SEMVER }}"

- task: Bash@3
name: pomversion
inputs:
targetType: "inline"
script: |
version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "##vso[task.setvariable variable=next;isOutput=true]$version"
failOnStderr: true

- script: |
git add pom.xml
git commit -m "Bump version [skip ci]"
git push origin $(SOURCE_BRANCH)
- script: |
HEAD_SHA=$(git rev-parse HEAD)
TAG="$(pomversion.next)"
TITLE="Release $(pomversion.next)"
echo "##vso[task.setvariable variable=title]$TITLE"
echo "##vso[task.setvariable variable=sha]$HEAD_SHA"
echo "##vso[task.setvariable variable=tag]$TAG"
- script: |
echo $(tag)
echo $(title)
echo $(sha)
# create new release
- task: GitHubRelease@0
inputs:
gitHubConnection: $(GITHUB_CONNECTION)
repositoryName: $(Build.Repository.Name)
action: create
target: $(sha)
tagSource: manual
tag: $(tag)
title: $(title)
addChangelog: true

# Deploy on Azure
- stage: deploy
condition: not(failed('releaseService'))
pool:
vmImage: "ubuntu-latest"
jobs:
- job: deployJava
steps:
- task: Bash@3
displayName: Check Version and Branch
inputs:
targetType: 'inline'
script: |
version=$(cat pom.xml | grep '^.*<version>' | sed -n 2p | awk -F'[><]' '{print $3}')
branch="$(Build.SourceBranch)"
if [[ "$branch" != "refs/heads/master" && ! "$branch" =~ "refs/tags/.*" && "${{ parameters.environment }}" == "prod" ]]; then
echo "Deploy branch $branch is not allowed."
exit 1
fi
if [[ "$version" == *SNAPSHOT && "${{ parameters.environment }}" == "prod" ]]; then
echo "Version $version is not allowed."
exit 1
fi
failOnStderr: true

- 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: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
sonarQubeRunAnalysis: false

- task: Bash@3
displayName: Get POM version
name: getpomversion
inputs:
targetType: 'inline'
script: |
version=$(cat pom.xml | grep '^.*<version>' | sed -n 2p | awk -F'[><]' '{print $3}')
echo "##vso[task.setvariable variable=outputpomversion;isOutput=true]$version"
failOnStderr: true

- task: Docker@2
displayName: Build and push an image to container registry
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'buildAndPush'
tags: |
$(Build.BuildId)
latest
$(getpomversion.outputpomversion)
- task: AzureRMWebAppDeployment@4
displayName: Azure App Service Deploy
inputs:
appType: webAppContainer
ConnectedServiceName: '$(connectedServiceName)'
WebAppName: '$(webAppName)'
DockerNamespace: '$(dockerNamespace)'
DockerRepository: '$(imageRepository)'
DockerImageTag: '$(Build.BuildId)'


# Run test
- stage: test
# run this stage only if 'test' is enabled
condition: and(not(failed('deployJava')), eq('${{ parameters.TEST }}', 'true'))
pool:
vmImage: "ubuntu-latest"
jobs:
# is needed to wait for startup of application
- job: waitStartup
pool: Server
steps:
- task: Delay@1
inputs:
delayForMinutes: '10'

- job: integrationTests
dependsOn: waitStartup
steps:
- script: |
git checkout $(SOURCE_BRANCH)
cd integration-test
yarn install
yarn test
displayName: 'integration test'
- task: PublishTestResults@2
condition: always()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/*-TEST.xml'
searchFolder: '$(System.DefaultWorkingDirectory)'

- job: deployUAT
dependsOn: integrationTests
variables:
version: $[ stageDependencies.deploy.deployJava.outputs['dockerTag.version'] ]
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenVersionOption: 'Default'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false

- task: Docker@2
displayName: Build and push an image to UAT container registry
inputs:
containerRegistry: '$(UAT_CONTAINER_REGISTRY)'
repository: '$(IMAGE_REPOSITORY)'
command: 'buildAndPush'
tags: |
$(Build.BuildId)
latest
$(version)
- task: AzureRMWebAppDeployment@4
displayName: Azure App Service Deploy in UAT
inputs:
appType: webAppContainer
ConnectedServiceName: '$(UAT_AZURE_SUBSCRIPTION)'
WebAppName: '$(UAT_WEB_APP_NAME)'
DockerNamespace: '$(UAT_CONTAINER_NAMESPACE)'
DockerRepository: '$(UAT_AZURE_SUBSCRIPTION)'
DockerImageTag: '$(Build.BuildId)'

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ target/**/*
/.idea/
emulatorcert.crt
.env
**/*paDemandPaymentNoticeRequest.xml
**/*paDemandPaymentNoticeRequest.xml
**/package-lock.json
**/node_modules/
**/yarn.lock
15 changes: 0 additions & 15 deletions api-test/Spontaneous Payments - Local.postman_environment.json

This file was deleted.

Loading

0 comments on commit 4ce1f5c

Please sign in to comment.