forked from Azure/azch-captureorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
99 lines (84 loc) · 3.52 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
variables:
- group: captureorder-variables # Variable Group containing 'teamName', 'mongoHost', 'mongoUser' and the secret 'mongoPassword'
- name: dockerRegistryServiceConnection
value: 'containerRegistryConnection' # replace with container registry service connection name established during pipeline creation
- name: imageRepository
value: 'captureorder' # replace with your own image name to match the name in the deployment.yaml
- name: tag
value: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build job
pool:
vmImage: ubuntu-latest
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: '**/Dockerfile'
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'manifests'
targetPath: 'manifests'
- stage: DeployDev
displayName: Deploy to dev stage
dependsOn: Build
variables:
- name: k8sNamespace # Kubernetes Namespace to deploy to. This variable is scoped to the DeployDev stage.
value: 'dev'
jobs:
- deployment: DeployDev
displayName: Deploy to dev job
pool:
vmImage: ubuntu-latest
environment: 'aksworkshop.dev' # name of the environment to target [env name.namespace]. This will pull in the Kubernetes service connection automatically
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@1
inputs:
artifactName: 'manifests'
downloadPath: '$(System.ArtifactsDirectory)/manifests'
- task: KubernetesManifest@0
displayName: Create imagePullSecret from dockerRegistryServiceConnection
inputs:
action: createSecret
secretName: acr-auth # we're going to inject this as an imagePullSecret in the deployment below
namespace: $(k8sNamespace)
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Create secret for MongoDB
inputs:
action: createSecret
secretName: mongodb
secretType: generic
namespace: $(k8sNamespace)
secretArguments: --from-literal=mongoHost=$(mongoHost) --from-literal=mongoUser=$(mongoUser) --from-literal=mongoPassword=$(mongoPassword)
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
namespace: $(k8sNamespace)
manifests: $(System.ArtifactsDirectory)/manifests/*
imagePullSecrets: | # this automatically injects the imagePullSecret into your Kubernetes deployment configuration
acr-auth
containers: |
$(imageRepository):$(tag)
- task: KubernetesManifest@0
displayName: Patch the deployment environment variables
inputs:
action: patch
resourceToPatch: name
name: $(imageRepository)
kind: Deployment
namespace: $(k8sNamespace)
patch: '{"spec": {"template": {"spec":{"containers":[{"name":"$(imageRepository)","env":[{"name":"TEAMNAME","value":"$(teamName)"}]}]}}}}' # replacing TEAMNAME with the value specified in the variables