forked from N-Usha/java-on-aks-piggymetrics
-
Notifications
You must be signed in to change notification settings - Fork 9
/
azure-pipelines.yml
133 lines (110 loc) · 4.95 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Build and Deploy piggymetrics to Azure Kubernetes Service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
CONTAINER_REGISTRY: 'javademosregistry'
CONFIG_PORT: '8888'
REGISTRY_PORT: '8761'
GATEWAY_PORT: '4000'
ACCOUNT_SERVICE_PORT: '6000'
AUTH_SERVICE_PORT: '5000'
STATISTICS_SERVICE_PORT: '7000'
NOTIFICATION_SERVICE_PORT: '8000'
vmImageName: 'ubuntu-latest'
IMAGE_TAG: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build and Push Container Images
pool:
vmImage: $(vmImageName)
steps:
- task: AzureKeyVault@1
displayName: Fetch secrets from Azure Key vault
inputs:
azureSubscription: 'Java Demos 2'
KeyVaultName: 'piggymetrics'
SecretsFilter: '*'
- task: Bash@3
displayName: Build container images for each service
inputs:
targetType: 'inline'
script: |
export CONTAINER_REGISTRY=$(CONTAINER_REGISTRY)
export IMAGE_TAG=$(IMAGE_TAG)
echo 'Install ACR AAD credential helper and login'
curl -L https://aka.ms/acr/installaad/bash | /bin/bash
az acr login -n $(CONTAINER_REGISTRY)
docker login -u $(AZURE-REGISTRY-USERNAME) -p $(AZURE-REGISTRY-PASSWORD) $(CONTAINER_REGISTRY).azurecr.io
echo 'Start Build'
cd config
mvn compile jib:build \
-Djib.container.environment=CONFIG_SERVICE_PASSWORD=$(CONFIG-SERVICE-PASSWORD)
cd ../registry
mvn compile jib:build
cd ../gateway
mvn compile jib:build
cd ../auth-service
mvn compile jib:build
cd ../account-service
mvn compile jib:build \
-Djib.container.environment=ACCOUNT_SERVICE_PASSWORD=$(ACCOUNT-SERVICE-PASSWORD)
cd ../statistics-service
mvn compile jib:build \
-Djib.container.environment=STATISTICS_SERVICE_PASSWORD=$(STATISTICS-SERVICE-PASSWORD)
cd ../notification-service
mvn compile jib:build \
-Djib.container.environment=NOTIFICATION_SERVICE_PASSWORD=$(NOTIFICATION-SERVICE-PASSWORD)
echo 'Build complete'
- publish: kubernetes
artifact: kubernetes
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy to AKS
pool:
vmImage: $(vmImageName)
environment: 'Piggymetrics.piggymetrics-azp'
strategy:
runOnce:
deploy:
steps:
- task: AzureKeyVault@1
displayName: Fetch secrets from Azure Key vault
inputs:
azureSubscription: 'Java Demos 2'
KeyVaultName: 'piggymetrics'
SecretsFilter: '*'
- task: replacetokens@3
displayName: Replace CONTAINER_REGISTRY & IMAGE_TAG in all the manifest files
inputs:
targetFiles: '$(Pipeline.Workspace)/kubernetes/*.yaml'
tokenPrefix: '${'
tokenSuffix: '}'
- task: KubernetesManifest@0
displayName: Create generic secrets to be available on pods
inputs:
action: 'createSecret'
secretType: 'generic'
secretName: 'piggymetrics'
secretArguments: '--from-literal=config_service_password=$(CONFIG-SERVICE-PASSWORD) --from-literal=notification_service_password=$(NOTIFICATION-SERVICE-PASSWORD) --from-literal=statistics_service_password=$(STATISTICS-SERVICE-PASSWORD) --from-literal=account_service_password=$(ACCOUNT-SERVICE-PASSWORD) --from-literal=rabbitmq_password=$(RABBITMQ-PASSWORD) --from-literal=mongodb_uri=$(MONGODB-URI) --from-literal=mongodb_database=$(MONGODB-DATABASE) --from-literal=rabbitmq_username=$(RABBITMQ-USERNAME) --from-literal=rabbitmq_host=$(RABBITMQ-HOST) --from-literal=rabbitmq_port=$(RABBITMQ-PORT) --from-literal=notification_email_user=$(SMTP-USER) --from-literal=notification_email_pass=$(SMTP-PASSWORD) --from-literal=notification_email_host=$(NOTIFICATION-EMAIL-HOST) --from-literal=notification_email_port=$(NOTIFICATION-EMAIL-PORT)'
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
manifests: |
$(Pipeline.Workspace)/kubernetes/1-config.yaml
$(Pipeline.Workspace)/kubernetes/2-registry.yaml
$(Pipeline.Workspace)/kubernetes/3-gateway.yaml
$(Pipeline.Workspace)/kubernetes/4-auth-service.yaml
$(Pipeline.Workspace)/kubernetes/5-account-service.yaml
$(Pipeline.Workspace)/kubernetes/6-statistics-service.yaml
$(Pipeline.Workspace)/kubernetes/7-notification-service.yaml