Skip to content

Commit

Permalink
draft helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
pasqualespica committed Jul 11, 2022
1 parent 4ce1f5c commit 5a52a20
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 80 deletions.
222 changes: 142 additions & 80 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,49 @@ parameters:
displayName: Run tests
type: boolean
default: false
- name: 'skipBuild'
displayName: 'Check this flag to skip build and proceed to deploy a docker image previously built'
type: boolean
default: false

variables:
${{ 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"
# RESOURCE_GROUP: $(DEV_WEB_APP_RESOURCE_GROUP_NAME)
# APP_NAME: $(DEV_WEB_APP_NAME)
# STAGE: "d"
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY)
dockerNamespace: $(DEV_CONTAINER_NAMESPACE)
# 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"
# RESOURCE_GROUP: $(UAT_WEB_APP_RESOURCE_GROUP_NAME)
# APP_NAME: $(UAT_WEB_APP_NAME)
# STAGE: "u"
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY)
dockerNamespace: $(UAT_CONTAINER_NAMESPACE)
# 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"
# RESOURCE_GROUP: $(PROD_WEB_APP_RESOURCE_GROUP_NAME)
# APP_NAME: $(PROD_WEB_APP_NAME)
# STAGE: "p"
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY)
dockerNamespace: $(PROD_CONTAINER_NAMESPACE)
# 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'] }}



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

# Image Repository Name
imageRepository: '$(IMAGE_REPOSITORY_NAME)'
nameSpace : '$(K8S_NAMESPACE)'

stages:

# Create a release on GitHub
Expand Down Expand Up @@ -130,8 +137,9 @@ stages:
title: $(title)
addChangelog: true

# Deploy on Azure
- stage: deploy
# Deploy on Azure ACR
- stage: 'Build'
displayName: 'Build_and_Publish_to_${{ parameters.ENV }}'
condition: not(failed('releaseService'))
pool:
vmImage: "ubuntu-latest"
Expand All @@ -143,6 +151,8 @@ stages:
inputs:
targetType: 'inline'
script: |
echo "${{ parameters.environment }}"
echo "${{ parameters.ENV }}
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
Expand Down Expand Up @@ -197,17 +207,69 @@ stages:
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)'

# Deploy on K8s with Helm
- stage: 'Serving_helm'
displayName: 'Serving_Helm'
dependsOn: Build
condition: or(succeeded(), ${{ parameters.skipBuild }} )
jobs:
- job: Serving_helm
displayName: Serving_helm
pool:
vmImage: $(vmImageNameDefault)
steps:
- task: PublishPipelineArtifact@1
displayName: 'Publish Artifact manifests'
condition: succeeded()
inputs:
targetPath: '$(Build.Repository.LocalPath)/helm'
artifact: 'helm'
publishLocation: 'pipeline'
- stage: 'Deploy'
displayName: 'Deploy_to_${{ parameters.ENV }}'
dependsOn: "Serving_helm"
condition: or(succeeded(), ${{ parameters.skipBuild }} )
jobs:
- deployment: 'Deploy_to_${{ parameters.ENV }}'
displayName: 'Deploy_to_${{ parameters.ENV }}'
pool:
vmImage: $(vmImageNameDefault)
environment: '$(environment)'
strategy:
runOnce:
deploy:
steps:
- download: none
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'helm'
targetPath: '$(Pipeline.Workspace)/helm'
- 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
- task: HelmDeploy@0
displayName: Helm upgrade
inputs:
kubernetesServiceEndpoint: ${{ variables.kubernetesServiceConnection }}
namespace: '$(nameSpace)'
command: upgrade
chartType: filepath
chartPath: $(Pipeline.Workspace)/helm
chartName: $(imageRepository)
releaseName: $(imageRepository)
valueFile: "$(Pipeline.Workspace)/helm/values-${{ parameters.ENV }}"
install: true
waitForExecution: true
arguments: "--timeout 5m0s"
# Run test
- stage: test
# run this stage only if 'test' is enabled
Expand All @@ -223,58 +285,58 @@ stages:
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)'
# - 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)'

23 changes: 23 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions helm/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: microservice-chart
repository: https://pagopa.github.io/aks-microservice-chart-blueprint
version: 1.17.0
digest: sha256:1b482d1bc27ff2248747daf12797aed90c5b40466cb9df98e7583a56c640a5d0
generated: "2022-06-15T19:27:00.74204+02:00"
10 changes: 10 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v2
name: pagopa-spontaneous-payments-service
description: Microservice that handles spontaneous payments for pagoPA
type: application
version: 1.0.0
appVersion: 1.0.0
dependencies:
- name: microservice-chart
version: 1.19.0
repository: "https://pagopa.github.io/aks-microservice-chart-blueprint"
Loading

0 comments on commit 5a52a20

Please sign in to comment.