Skip to content

Commit

Permalink
[PPD-243] Helm, Dockefile and CD Pipeline (#2)
Browse files Browse the repository at this point in the history
* lint

* pipeline

* pipeline danger CI

* Update code-review-pipelines.yml for Azure Pipelines

* fix pipeline danger CI

* check input

* fix

* try

* openapi.json

* [PPD-243] helm, Dockerfile added

* [PPD-243] fix pipeline

* Bump version to 1.0.1 [skip ci]

* fix

* fix

* [PPD-243] deploy pipeline

* Update deploy-pipelines.yml for Azure Pipelines

* Bump version to 1.0.2-0 [skip ci]

* fix pipeline

* [PPD-243] fix deploy pipeline

* Bump version to 1.0.2-1 [skip ci]

* [PPD-243] fix deploy pipeline

* Bump version to 1.0.2-2 [skip ci]

* [PPD-243] fix deploy pipeline

* [PPD-243] fix deploy pipeline

* [PPD-243] fix deploy pipeline

* fix

* [PPD-243] fix deploy pipeline

* [PPD-243] fix deploy pipeline

* fix

* Bump version to 1.0.2-3 [skip ci]

Co-authored-by: pagopa-github-bot <>
  • Loading branch information
jacopocarlini authored Jul 25, 2022
1 parent f989e3d commit b8c0bad
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 4 deletions.
77 changes: 77 additions & 0 deletions .devops/azure-templates/node-versioning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Node Github Relase steps
# Mark a release on the project repository, with version bump and tag,
# and publish a release on Github

parameters:

# Versioning parameters
- name: 'semver'
type: string
values:
- major
- minor
- patch
- prerelease
- skip

# This is the branch in which we will push the release tag.
# It'll be master, but it can be overridden
# Basically, this variable is used to enforce the fact that we use the very same branch in different steps
- name: 'release_branch'
type: string
default: master

# Github parameters
- name: 'gitUsername'
type: string
- name: 'gitEmail'
type: string
- name: 'gitHubConnection'
type: string


steps:
- ${{ if ne(parameters.semver, 'skip') }}:
# setup git author
- script: |
git config --global user.email "${{ parameters.gitEmail }}" && git config --global user.name "${{ parameters.gitUsername }}"
displayName: 'Git setup'
# Without this step, changes would be applied to a detached head
- script: |
git checkout ${{ parameters.release_branch }}
displayName: 'Checkout release branch'
# bump version
- script: |
npm version ${{ parameters.semver }} -m "Bump version to %s [skip ci]"
NEXT_VERSION=$(node -p "require('./package.json').version")
RELEASE_TAG="v$NEXT_VERSION-RELEASE"
git tag $RELEASE_TAG
displayName: 'Version bump and tag'
- script: |
NEXT_VERSION=$(node -p "require('./package.json').version")
HEAD_SHA=$(git rev-parse HEAD)
TITLE="Release $NEXT_VERSION"
TAG="v$NEXT_VERSION-RELEASE"
echo "##vso[task.setvariable variable=title]$TITLE"
echo "##vso[task.setvariable variable=sha]$HEAD_SHA"
echo "##vso[task.setvariable variable=tag]$TAG"
displayName: 'Set release variables'
# push new version
- script: |
git push origin ${{ parameters.release_branch }} && git push --tags
displayName: 'Push to the release branch'
# create new releae
- task: GitHubRelease@0
inputs:
gitHubConnection: ${{ parameters.gitHubConnection }}
repositoryName: $(Build.Repository.Name)
action: create
target: $(sha)
tagSource: manual
tag: $(tag)
title: $(title)
addChangelog: true
194 changes: 194 additions & 0 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
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
- prerelease
- skip
default: skip
- name: TEST
displayName: Run tests
type: boolean
default: false

variables:
NODE_VERSION: '14.19.0'
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn

${{ if eq(parameters['ENV'], 'dev') }}:
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY)
kubernetesServiceConnection: '$(DEV_KUBERNETES_SERVICE_CONN)'
${{ if eq(parameters['ENV'], 'uat') }}:
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY)
kubernetesServiceConnection: '$(UAT_KUBERNETES_SERVICE_CONN)'
${{ if eq(parameters['ENV'], 'prod') }}:
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY)
kubernetesServiceConnection: '$(PROD_KUBERNETES_SERVICE_CONN)'

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

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

title: ""
sha: ""
tag: ""
version: ""

# Only manual triggers
trigger: none
pr: none

pool:
vmImage: ubuntu-latest

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

stages:

# Create a release on GitHub
- stage: release_service
# bump version if SEMVER is not 'skip'
condition: ne('${{ parameters.SEMVER }}', 'skip')
pool:
vmImage: "ubuntu-latest"
jobs:
- job: releaseService
steps:
- template: templates/node-job-setup/template.yaml@pagopaCommons
parameters:
persistCredentials: true
gitReference: $(SOURCE_BRANCH)

- template: azure-templates/node-versioning.yml
parameters:
semver: '${{ parameters.SEMVER }}'
release_branch: $(SOURCE_BRANCH)
gitEmail: $(GIT_EMAIL)
gitUsername: $(GIT_USERNAME)
gitHubConnection: $(GITHUB_CONNECTION)

- script: |
echo $(tag)
echo $(title)
echo $(sha)
# Prepare Artifact with application bundle
- stage: prepare_artifact
condition: not(failed('release_service'))
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: 'make_build'
steps:
# Build application
- template: templates/node-job-setup/template.yaml@pagopaCommons
parameters:
# On the assumption that this stage is executed only when Release stage is,
# with this parameter we set the reference the deploy script must pull changes from.
# The branch/tag name is calculated from the source branch
# ex: Build.SourceBranch=refs/heads/master --> master
# ex: Build.SourceBranch=refs/tags/v1.2.3-RELEASE --> v1.2.3-RELEASE
gitReference: ${{ replace(replace(variables['Build.SourceBranch'], 'refs/tags/', ''), 'refs/heads/', '') }}

- script: yarn test
displayName: 'Test'

- script: yarn build
displayName: 'Build'

- script: |
VERSION=$(node -p "require('./package.json').version")
echo "##vso[task.setvariable variable=version]VERSION"
displayName: 'Get Version'
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(IMAGE_REPOSITORY)'
command: 'buildAndPush'
tags: |
$(Build.BuildId)
latest
$(version)
# Deploy on K8s with Helm
- stage: 'Serving_helm'
displayName: 'Serving_Helm'
condition: not(failed('prepare_artifact'))
jobs:
- job: Serving_helm
displayName: Serving_helm
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 }}'
condition: not(failed('Serving_helm'))
jobs:
- deployment: 'Deploy_to_${{ parameters.ENV }}'
displayName: 'Deploy_to_${{ parameters.ENV }}'
environment: '${{ parameters.ENV }}'
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 }}.yaml"
install: true
waitForExecution: true
arguments: "--timeout 5m0s"
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:14.19.0

WORKDIR /src/node-function-app

COPY ./ ./

RUN npm i -g azure-functions-core-tools@3 --unsafe-perm true
RUN yarn install

ENV AzureWebJobsScriptRoot=./ \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

EXPOSE 7071

ENTRYPOINT ["yarn", "start"]
1 change: 1 addition & 0 deletions Donation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const httpTrigger: AzureFunction = async (
req: HttpRequest
): Promise<void> => {
context.log("HTTP trigger function processed a request.", req.body);
context.log(process.env);

const input = Input.decode(req.body);

Expand Down
19 changes: 19 additions & 0 deletions Info/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/Info/index.js"
}
20 changes: 20 additions & 0 deletions Info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
const httpTrigger: AzureFunction = async function(
context: Context,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
req: HttpRequest
): Promise<void> {
context.log("HTTP Info trigger function processed a request.");

const responseMessage = { status: "OK" };

// eslint-disable-next-line functional/immutable-data
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
};

export default httpTrigger;
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.2"

services:
donation:
container_name: 'gps-donation-service'
ports:
- "7071:7071"
build:
context: ./
dockerfile: Dockerfile


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/
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-gps-donation-service
description: Microservice to handle Donations for GPS
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 b8c0bad

Please sign in to comment.