gopalswami commited on
Commit
137a70f
·
1 Parent(s): b7782a9

Add azure pipeline

Browse files
Files changed (1) hide show
  1. azure-pipelines.yml +177 -0
azure-pipelines.yml ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ trigger:
2
+ - develop
3
+ - staging
4
+ - main
5
+
6
+ pool:
7
+ vmImage: 'ubuntu-latest'
8
+
9
+ variables:
10
+ - name: DOCKER_REGISTRY
11
+ value: sifars.azurecr.io
12
+ - name: DOCKER_COMPOSE_PROJECT_NAME
13
+ value: fb-api
14
+
15
+ stages:
16
+ - stage: BuildAndPublish
17
+ displayName: Build and publish container images
18
+ jobs:
19
+ - job: BuildAndPushContainerImage
20
+ displayName: Build and push container image
21
+ steps:
22
+ - checkout: git://$(System.TeamProject)/$(Build.Repository.Name)@$(Build.SourceBranchName)
23
+ clean: "true"
24
+ fetchDepth: "1"
25
+ persistCredentials: "true"
26
+
27
+ - task: Docker@2
28
+ displayName: Login Container Registry
29
+ inputs:
30
+ command: login
31
+ containerRegistry: $(DOCKER_REGISTRY)
32
+
33
+ - task: DownloadSecureFile@1
34
+ displayName: Download secure file to override build env vars
35
+ name: env_build_override
36
+ inputs:
37
+ secureFile: .env.build.$(Build.Repository.Name).$(Build.SourceBranchName).override
38
+ continueOnError: true
39
+
40
+ - task: Bash@3
41
+ displayName: Setup build env vars
42
+ inputs:
43
+ targetType: 'inline'
44
+ script: mv .env.build.$(Build.SourceBranchName) .env
45
+ workingDirectory: $(Build.SourcesDirectory)
46
+
47
+ - task: Bash@3
48
+ displayName: add trailing empty line to prevent scenario of variable concatination
49
+ inputs:
50
+ targetType: 'inline'
51
+ script: echo >> .env
52
+ workingDirectory: $(Build.SourcesDirectory)
53
+
54
+ - task: Bash@3
55
+ displayName: Override build env vars with secure file
56
+ inputs:
57
+ targetType: 'inline'
58
+ script: cat $(env_build_override.secureFilePath) >> .env
59
+ workingDirectory: $(Build.SourcesDirectory)
60
+
61
+ - task: DockerCompose@1
62
+ displayName: Build services
63
+ inputs:
64
+ action: Build services
65
+ containerregistrytype: Container Registry
66
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
67
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
68
+ additionalDockerComposeFiles: $(Build.SourcesDirectory)/docker-compose.override.yml
69
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
70
+ qualifyImageNames: true
71
+ includeSourceTags: true
72
+ additionalImageTags: |
73
+ $(Build.BuildNumber)
74
+ $(Build.SourceBranchName)
75
+ arguments: |
76
+ --pull --build-arg BUILDKIT_INLINE_CACHE=1
77
+ dockerComposeFileArgs: |
78
+ DOCKER_BUILDKIT=1
79
+ COMPOSE_DOCKER_CLI_BUILD=1
80
+
81
+ - task: DockerCompose@1
82
+ displayName: Push services
83
+ inputs:
84
+ action: Push services
85
+ containerregistrytype: Container Registry
86
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
87
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
88
+ additionalDockerComposeFiles: $(Build.SourcesDirectory)/docker-compose.override.yml
89
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
90
+ qualifyImageNames: false
91
+ additionalImageTags: |
92
+ $(Build.BuildNumber)
93
+ $(Build.SourceBranchName)
94
+
95
+ - task: DockerCompose@1
96
+ displayName: Write service image digests
97
+ inputs:
98
+ action: Write service image digests
99
+ imageDigestComposeFile: $(Build.SourcesDirectory)/docker-compose.images.yml
100
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
101
+ containerregistrytype: Container Registry
102
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
103
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
104
+ qualifyImageNames: true
105
+
106
+ - task: PublishBuildArtifacts@1
107
+ displayName: Publish docker-compose.yml
108
+ inputs:
109
+ ArtifactName: 'release'
110
+ publishLocation: 'Container'
111
+ PathtoPublish: $(Build.SourcesDirectory)/docker-compose.yml
112
+
113
+ # This step is used to carry the runtime environment variables to the deployment step
114
+ # This can be skipped for the scenarios where we don't want to use runtime environment vars
115
+ - task: PublishBuildArtifacts@1
116
+ displayName: Publish docker-compose.yml
117
+ inputs:
118
+ ArtifactName: 'release'
119
+ publishLocation: 'Container'
120
+ PathtoPublish: $(Build.SourcesDirectory)/.env
121
+
122
+ - task: PublishBuildArtifacts@1
123
+ displayName: Publish docker-compose.images.yml
124
+ inputs:
125
+ ArtifactName: 'release'
126
+ publishLocation: 'Container'
127
+ PathtoPublish: $(Build.SourcesDirectory)/docker-compose.images.yml
128
+
129
+ - task: Docker@2
130
+ displayName: Logout of ACR
131
+ inputs:
132
+ command: logout
133
+ containerRegistry: $(DOCKER_REGISTRY)
134
+
135
+ - stage: Deployment
136
+ jobs:
137
+ - job: PrepareArtifacts
138
+ steps:
139
+ - task: DownloadPipelineArtifact@2
140
+ displayName: Download pipeline artifact
141
+ inputs:
142
+ buildType: 'current'
143
+ artifactName: 'release'
144
+ targetPath: $(Build.SourcesDirectory)
145
+
146
+ - task: DockerCompose@1
147
+ displayName: Lock services for new release
148
+ inputs:
149
+ action: Lock services
150
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
151
+ qualifyImageNames: true
152
+ containerregistrytype: Container Registry
153
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
154
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
155
+ imageDigestComposeFile: $(Build.SourcesDirectory)/docker-compose.images.yml
156
+ outputDockerComposeFile: $(Build.SourcesDirectory)/docker-compose.release.yml
157
+
158
+ - task: PublishBuildArtifacts@1
159
+ displayName: Publish docker-compose.release.yml for new release
160
+ inputs:
161
+ PathtoPublish: $(Build.SourcesDirectory)/docker-compose.release.yml
162
+ ArtifactName: 'release'
163
+ publishLocation: 'Container'
164
+
165
+ - task: DockerCompose@1
166
+ displayName: Deploy resources with docker compose
167
+ inputs:
168
+ action: Run services
169
+ buildImages: false
170
+ containerregistrytype: Container Registry
171
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
172
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.release.yml
173
+ dockerHostEndpoint: docker-host-$(Build.SourceBranchName)
174
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
175
+ detached: true
176
+ workingDirectory: $(Build.SourcesDirectory)
177
+