Commit 7e124d52 authored by Stanislav Doruc's avatar Stanislav Doruc
Browse files

clone azure

parent 8b6df354
# MDliveryBackend
# Introduction
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
MDliveryBackend
\ No newline at end of file
# Getting Started
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
1. Installation process
2. Software dependencies
3. Latest releases
4. API references
# Build and Test
TODO: Describe and show how to build your code and run the tests.
# Contribute
TODO: Explain how other users and developers can contribute to make your code better.
If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
- [ASP.NET Core](https://github.com/aspnet/Home)
- [Visual Studio Code](https://github.com/Microsoft/vscode)
- [Chakra Core](https://github.com/Microsoft/ChakraCore)
\ No newline at end of file
name: '$(Date:yyMM).$(DayOfMonth)$(Rev:.r)'
trigger:
batch: true
branches:
include:
- dev
variables:
DOCKER_VERSION: "20.10.1"
containerRegistry: harbor.staging.egov.md
containerProject: esempla
backendContainerRepository: $(containerProject)/mdelivery/backend
jobsContainerRepository: $(containerProject)/mdelivery/jobs
containerTag: "dev"
solutionPath: src
backendProjectPath: $(solutionPath)/Backend
jobsProjectPath: $(solutionPath)/Jobs
artifactsEndpoint: https://pkgs.dev.azure.com/egalab/_packaging/Repository/nuget/v3/index.json
stages:
- stage: BuildContainers
displayName: Build Containers
pool:
vmImage: 'ubuntu-latest'
variables:
DOCKER_BUILDKIT: 0
backendDockerFilePath: $(backendProjectPath)/Dockerfile
jobsDockerFilePath: $(jobsProjectPath)/Dockerfile
buildConfiguration: Release
jobs:
- job: BuildContainers
workspace:
clean: resources
steps:
- task: DockerInstaller@0
displayName: Install Docker CLI
inputs:
dockerVersion: $(DOCKER_VERSION)
- task: Docker@2
displayName: Build Backend Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
dockerfile: $(backendDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Backend Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
- task: Docker@2
displayName: Build Jobs Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
dockerfile: $(jobsDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Jobs Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
name: '$(Date:yyMM).$(DayOfMonth)$(Rev:.r)'
trigger:
batch: true
branches:
include:
- dev
variables:
DOCKER_VERSION: "20.10.1"
devK8sService: Dev-mdelivery-1607421334727
containerRegistry: harbor.staging.egov.md
containerProject: esempla
backendContainerRepository: $(containerProject)/mdelivery/backend
jobsContainerRepository: $(containerProject)/mdelivery/jobs
containerTag: "dev"
solutionPath: src
backendProjectPath: $(solutionPath)/Backend
jobsProjectPath: $(solutionPath)/Jobs
artifactsEndpoint: https://pkgs.dev.azure.com/egalab/_packaging/Repository/nuget/v3/index.json
stages:
- stage: BuildContainers
displayName: Build Containers
pool:
vmImage: 'ubuntu-latest'
variables:
DOCKER_BUILDKIT: 0
backendDockerFilePath: $(backendProjectPath)/Dockerfile
jobsDockerFilePath: $(jobsProjectPath)/Dockerfile
buildConfiguration: Release
jobs:
- job: BuildContainers
workspace:
clean: resources
steps:
- task: DockerInstaller@0
displayName: Install Docker CLI
inputs:
dockerVersion: $(DOCKER_VERSION)
- task: Docker@2
displayName: Build Backend Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
dockerfile: $(backendDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Backend Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
- task: Docker@2
displayName: Build Jobs Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
dockerfile: $(jobsDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Jobs Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
- publish: deploy
artifact: deploy
displayName: Publish Helm Chart
- stage: DeployDev
displayName: Deploy to Dev
pool:
vmImage: 'ubuntu-latest'
variables:
k8sNamespace: mdelivery
k8sReleaseName: dev
jobs:
- deployment: DeployDev
environment: Dev
workspace:
clean: all
strategy:
runOnce:
deploy:
steps:
- task: DownloadSecureFile@1
displayName: Download Data Protection Key
inputs:
secureFile: DataProtectionKey.Dev.xml
- task: DownloadSecureFile@1
displayName: Download MPass Certificate
inputs:
secureFile: mpass.staging.egov.md.cer
- task: Kubernetes@1
displayName: Login to Kubernetes
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(devK8sService)
command: login
- task: HelmInstaller@1
displayName: Install Helm CLI
- bash: >
helm upgrade $(k8sReleaseName) $(Pipeline.Workspace)/deploy/chart
--install --atomic --namespace $(k8sNamespace) --values $(Pipeline.Workspace)/deploy/values.dev.yaml
--set-string backend.image.tag="$(containerTag)"
--set-string jobs.image.tag="$(containerTag)"
--set-string secret.connections.strings.database="$(dev-connection-string)"
--set-file secret.data-protection.strings."dataProtectionKey\.xml"=$(Agent.TempDirectory)/DataProtectionKey.Dev.xml
--set-file configMap.trusted-certificates.binaries."mpass\.cer"=$(Agent.TempDirectory)/mpass.staging.egov.md.cer
--set jobs.migration.enabled=$(migrate-database)
displayName: Deploy Helm Chart
- task: Kubernetes@1
displayName: Logout from Kubernetes
inputs:
command: logout
\ No newline at end of file
name: '$(Date:yyMM).$(DayOfMonth)$(Rev:.r)'
trigger:
batch: true
branches:
include:
- staging
variables:
DOCKER_VERSION: "20.10.1"
containerRegistry: harbor.staging.egov.md
containerProject: esempla
backendContainerRepository: $(containerProject)/mdelivery/backend
jobsContainerRepository: $(containerProject)/mdelivery/jobs
containerTag: staging
solutionPath: src
backendProjectPath: $(solutionPath)/Backend
jobsProjectPath: $(solutionPath)/Jobs
artifactsEndpoint: https://pkgs.dev.azure.com/egalab/_packaging/Repository/nuget/v3/index.json
stages:
- stage: BuildContainers
displayName: Build Containers
pool:
vmImage: 'ubuntu-latest'
variables:
DOCKER_BUILDKIT: 0
backendDockerFilePath: $(backendProjectPath)/Dockerfile
jobsDockerFilePath: $(jobsProjectPath)/Dockerfile
buildConfiguration: Release
jobs:
- job: BuildContainers
workspace:
clean: resources
steps:
- task: DockerInstaller@0
displayName: Install Docker CLI
inputs:
dockerVersion: $(DOCKER_VERSION)
- task: Docker@2
displayName: Build Backend Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
dockerfile: $(backendDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Backend Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
- task: Docker@2
displayName: Build Jobs Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
dockerfile: $(jobsDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Jobs Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
name: '$(Date:yyMM).$(DayOfMonth)$(Rev:.r)'
trigger:
batch: true
branches:
include:
- master
variables:
DOCKER_VERSION: "20.10.2"
stagingK8sService: Staging-mdelivery-1607421729877
containerRegistry: harbor.staging.egov.md
containerProject: esempla
backendContainerRepository: $(containerProject)/mdelivery-backend
jobsContainerRepository: $(containerProject)/mdelivery-jobs
containerTag: "1.$(Build.BuildNumber)"
solutionPath: src
backendProjectPath: $(solutionPath)/Backend
jobsProjectPath: $(solutionPath)/Jobs
artifactsEndpoint: https://pkgs.dev.azure.com/egalab/_packaging/Repository/nuget/v3/index.json
stages:
- stage: BuildContainers
displayName: Build Containers
pool:
vmImage: 'ubuntu-latest'
variables:
DOCKER_BUILDKIT: 0
backendDockerFilePath: $(backendProjectPath)/Dockerfile
jobsDockerFilePath: $(jobsProjectPath)/Dockerfile
buildConfiguration: Release
jobs:
- job: BuildContainers
workspace:
clean: resources
steps:
- task: DockerInstaller@0
displayName: Install Docker CLI
inputs:
dockerVersion: $(DOCKER_VERSION)
- task: VersionDotNetCoreAssemblies@2
displayName: Version Projects
inputs:
Path: '$(solutionPath)'
VersionNumber: '$(containerTag)'
AddDefault: true
- task: Docker@2
displayName: Build Backend Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
dockerfile: $(backendDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Backend Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(backendContainerRepository)
tags: $(containerTag)
- task: Docker@2
displayName: Build Jobs Image
inputs:
command: build
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
dockerfile: $(jobsDockerFilePath)
buildContext: $(solutionPath)
arguments: --progress=plain --build-arg BUILD_CONFIGURATION=$(buildConfiguration) --build-arg ARTIFACTS_ENDPOINT=$(artifactsEndpoint) --build-arg ARTIFACTS_TOKEN=$(System.AccessToken)
- task: Docker@2
displayName: Push Jobs Image
inputs:
command: push
containerRegistry: $(containerRegistry)
repository: $(jobsContainerRepository)
tags: $(containerTag)
- publish: deploy
artifact: deploy
displayName: Publish Helm Chart
- stage: DeployStaging
displayName: Deploy to Staging
pool:
vmImage: 'ubuntu-latest'
variables:
k8sNamespace: mdelivery
k8sReleaseName: staging
jobs:
- deployment: DeployStaging
environment: Staging
workspace:
clean: all
strategy:
runOnce:
deploy:
steps:
- task: DownloadSecureFile@1
displayName: Download Data Protection Key
inputs:
secureFile: DataProtectionKey.Staging.xml
- task: DownloadSecureFile@1
displayName: Download MPass Certificate
inputs:
secureFile: mpass.staging.egov.md.cer
- task: Kubernetes@1
displayName: Login to Kubernetes
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(stagingK8sService)
command: login
- task: HelmInstaller@1
displayName: Install Helm CLI
- bash: >
helm upgrade $(k8sReleaseName) $(Pipeline.Workspace)/deploy/chart
--install --atomic --namespace $(k8sNamespace) --values $(Pipeline.Workspace)/deploy/values.staging.yaml
--set-string backend.image.tag="$(containerTag)"
--set-string jobs.image.tag="$(containerTag)"
--set-string secret.connections.strings.database="$(staging-connection-string)"
--set-file secret.data-protection.strings."dataProtectionKey\.xml"=$(Agent.TempDirectory)/DataProtectionKey.Staging.xml
--set-file configMap.trusted-certificates.binaries."mpass\.cer"=$(Agent.TempDirectory)/mpass.staging.egov.md.cer
--set jobs.migration.enabled=$(migrate-database)
displayName: Deploy Helm Chart
- task: Kubernetes@1
displayName: Logout from Kubernetes
inputs:
command: logout
\ No newline at end of file
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for MDelivery
name: mdelivery
version: 1.0.0
{
"AllowedHosts": "*",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"MPassSamlOptions": {
"SamlRequestIssuer": "{{ .Values.settings.mpass.samlRequestIssuer }}",
"ServiceCertificatePath": "Files/Certificates/Service",
"IdentityProviderCertificatePath": "Files/Certificates/Trusted/mpass.cer",
"SamlMessageTimeout": "00:10:00",
"SamlLoginDestination": "{{ .Values.settings.mpass.samlLoginDestination }}",
"SamlLogoutDestination": "{{ .Values.settings.mpass.samlLogoutDestination }}",
"ServiceRootUrl": "{{ .Values.settings.serviceRootUrl }}"
},
"MPay": {
"ServiceCertificatePath": "Files/Certificates/Service",
"MPayCertificatePath": "Files/Certificates/Trusted/mpass.cer",
"ServiceRootUrl": "{{ .Values.settings.serviceRootUrl }}",
"MPayRootUrl": "https://testmpay.gov.md"
},
"MDelivery": {
"DataProtectionKeysPath": "Files/DataProtectionKeys"
}
}
\ No newline at end of file
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"System": "Warning"
}
}
}
\ No newline at end of file
1. Get the application URL by running these commands:
{{- if .Values.ingress.backend.enabled }}
{{- range .Values.ingress.backend.paths }}
http{{ if $.Values.ingress.backend.tls.enabled }}s{{ end }}://{{ $.Values.ingress.backend.host }}{{ .path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.backend.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "app.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.backend.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "app.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "app.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.backend.port }}
{{- else if contains "ClusterIP" .Values.service.backend.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "app.name" . }},app.kubernetes.io/component=api,app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "app.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "app.labels" -}}
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "app.chart" . }}
{{- end -}}
{{/*
Prometheus labels
*/}}
{{- define "app.prometheusLabels" -}}
app: {{ include "app.name" . }}
instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
version: {{ .Chart.AppVersion | quote }}
{{- end }}
{{- end -}}
{{/*
Pod selector labels
*/}}
{{- define "app.selector" -}}
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{/*
Create image pull secret if used.
*/}}
{{- define "app.imagePullSecret" -}}
{{- if .Values.imagePullSecret.create -}}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imagePullSecret.registry (printf "%s:%s" .Values.imagePullSecret.username .Values.imagePullSecret.password | b64enc) | b64enc }}
{{- end -}}
{{- end -}}
\ No newline at end of file
{{- $fullName := include "app.fullname" . -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullName }}-backend
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.backend.replicas }}
selector:
matchLabels:
{{- include "app.selector" . | nindent 6 }}
app.kubernetes.io/component: backend
template:
metadata:
labels:
{{- include "app.selector" . | nindent 8 }}