Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PPD-243] Helm, Dockefile and CD Pipeline #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
27fa773
lint
jacopocarlini Jul 18, 2022
3bbd1e7
pipeline
jacopocarlini Jul 18, 2022
d8a2534
pipeline danger CI
jacopocarlini Jul 18, 2022
43b3d88
Update code-review-pipelines.yml for Azure Pipelines
jacopocarlini Jul 18, 2022
e68f753
fix pipeline danger CI
jacopocarlini Jul 18, 2022
3b0b110
check input
jacopocarlini Jul 19, 2022
3abf261
fix
jacopocarlini Jul 19, 2022
4f47ad6
try
jacopocarlini Jul 19, 2022
473f9e2
openapi.json
jacopocarlini Jul 20, 2022
aa96330
[PPD-243] helm, Dockerfile added
jacopocarlini Jul 21, 2022
cae5456
[PPD-243] fix pipeline
jacopocarlini Jul 21, 2022
fd06cbd
Bump version to 1.0.1 [skip ci]
Jul 21, 2022
e93f75f
fix
jacopocarlini Jul 21, 2022
dcee53a
Merge remote-tracking branch 'origin/PPD-243-creazione-infra-microser…
jacopocarlini Jul 21, 2022
b67db17
fix
jacopocarlini Jul 21, 2022
4cda291
[PPD-243] deploy pipeline
jacopocarlini Jul 22, 2022
aa908b4
Update deploy-pipelines.yml for Azure Pipelines
jacopocarlini Jul 22, 2022
82063fe
Bump version to 1.0.2-0 [skip ci]
Jul 22, 2022
dcf2408
fix pipeline
jacopocarlini Jul 22, 2022
383a4eb
[PPD-243] fix deploy pipeline
jacopocarlini Jul 22, 2022
b80a36f
Bump version to 1.0.2-1 [skip ci]
Jul 22, 2022
0929528
[PPD-243] fix deploy pipeline
jacopocarlini Jul 22, 2022
e6540cb
Merge remote-tracking branch 'origin/PPD-243-creazione-infra-microser…
jacopocarlini Jul 22, 2022
a212aa2
Bump version to 1.0.2-2 [skip ci]
Jul 22, 2022
eb94184
Merge branch 'main' into PPD-243-creazione-infra-microservizio-donazi…
jacopocarlini Jul 22, 2022
66f4893
Merge remote-tracking branch 'origin/PPD-243-creazione-infra-microser…
jacopocarlini Jul 22, 2022
55982af
[PPD-243] fix deploy pipeline
jacopocarlini Jul 22, 2022
db628db
[PPD-243] fix deploy pipeline
jacopocarlini Jul 22, 2022
b88f976
[PPD-243] fix deploy pipeline
jacopocarlini Jul 22, 2022
3d556a4
fix
jacopocarlini Jul 22, 2022
cf85eae
[PPD-243] fix deploy pipeline
jacopocarlini Jul 22, 2022
6d9962c
[PPD-243] fix deploy pipeline
jacopocarlini Jul 22, 2022
5be71f2
fix
jacopocarlini Jul 22, 2022
5a17355
Bump version to 1.0.2-3 [skip ci]
Jul 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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