gopalswami commited on
Commit
8dc9e85
·
1 Parent(s): 9b0a6de

Add Azure Pipelines configuration and Docker Compose files for backend service deployment

Browse files
azure-pipelines.yml ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ trigger:
2
+ - develop
3
+
4
+ pool:
5
+ vmImage: "ubuntu-24.04"
6
+
7
+ parameters:
8
+ - name: dockerRegistry
9
+ displayName: Docker Registry
10
+ type: string
11
+ default: "sifars.azurecr.io"
12
+ - name: projectName
13
+ displayName: Docker Compose Project Name
14
+ type: string
15
+ default: "proposal-evaluation-backend"
16
+
17
+ variables:
18
+ - name: DOCKER_REGISTRY
19
+ value: ${{ parameters.dockerRegistry }}
20
+ - name: DOCKER_COMPOSE_PROJECT_NAME
21
+ value: ${{ parameters.projectName }}
22
+
23
+ stages:
24
+ - stage: Build
25
+ displayName: "Build and Publish"
26
+ jobs:
27
+ - job: BuildImages
28
+ displayName: "Build and Push Container Images"
29
+ steps:
30
+ # Source code checkout
31
+ - checkout: self
32
+ clean: true
33
+ fetchDepth: 1
34
+ persistCredentials: true
35
+
36
+ # Container registry login
37
+ - task: Docker@2
38
+ displayName: "Login to Container Registry"
39
+ inputs:
40
+ command: login
41
+ containerRegistry: $(DOCKER_REGISTRY)
42
+
43
+ # Environment setup
44
+ - task: DownloadSecureFile@1
45
+ displayName: "Download Environment Override File"
46
+ name: env_build_override
47
+ inputs:
48
+ secureFile: .env.build.$(Build.Repository.Name).$(Build.SourceBranchName).override
49
+ continueOnError: true
50
+
51
+ - task: Bash@3
52
+ displayName: "Setup Build Environment Variables"
53
+ inputs:
54
+ targetType: "inline"
55
+ script: mv .env.build.$(Build.SourceBranchName) .env
56
+ workingDirectory: $(Build.SourcesDirectory)
57
+
58
+ - task: Bash@3
59
+ displayName: "Add Trailing Empty Line"
60
+ inputs:
61
+ targetType: "inline"
62
+ script: echo >> .env
63
+ workingDirectory: $(Build.SourcesDirectory)
64
+
65
+ - task: Bash@3
66
+ displayName: "Override Environment Variables"
67
+ condition: succeededOrFailed()
68
+ inputs:
69
+ targetType: "inline"
70
+ script: cat $(env_build_override.secureFilePath) >> .env
71
+ workingDirectory: $(Build.SourcesDirectory)
72
+
73
+ # Build services
74
+ - task: DockerCompose@1
75
+ displayName: "Build Services"
76
+ inputs:
77
+ action: Build services
78
+ containerregistrytype: Container Registry
79
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
80
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
81
+ additionalDockerComposeFiles: $(Build.SourcesDirectory)/docker-compose.override.yml
82
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
83
+ qualifyImageNames: true
84
+ includeSourceTags: true
85
+ arguments: |
86
+ --pull --build-arg BUILDKIT_INLINE_CACHE=1
87
+ dockerComposeFileArgs: |
88
+ DOCKER_BUILDKIT=1
89
+ COMPOSE_DOCKER_CLI_BUILD=1
90
+
91
+ # Push services
92
+ - task: DockerCompose@1
93
+ displayName: "Push Services"
94
+ inputs:
95
+ action: Push services
96
+ containerregistrytype: Container Registry
97
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
98
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
99
+ additionalDockerComposeFiles: $(Build.SourcesDirectory)/docker-compose.override.yml
100
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
101
+ qualifyImageNames: false
102
+
103
+ # Create image digests
104
+ - task: DockerCompose@1
105
+ displayName: "Write Service Image Digests"
106
+ inputs:
107
+ action: Write service image digests
108
+ imageDigestComposeFile: $(Build.SourcesDirectory)/docker-compose.images.yml
109
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
110
+ containerregistrytype: Container Registry
111
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
112
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
113
+ qualifyImageNames: true
114
+
115
+ # Publish artifacts
116
+ - task: PublishBuildArtifacts@1
117
+ displayName: "Publish Docker Compose File"
118
+ inputs:
119
+ PathtoPublish: $(Build.SourcesDirectory)/docker-compose.yml
120
+ ArtifactName: "release"
121
+ publishLocation: Container
122
+
123
+ - task: PublishBuildArtifacts@1
124
+ displayName: "Publish Environment File"
125
+ inputs:
126
+ PathtoPublish: $(Build.SourcesDirectory)/.env
127
+ ArtifactName: "release"
128
+ publishLocation: Container
129
+
130
+ - task: PublishBuildArtifacts@1
131
+ displayName: "Publish Images Digest File"
132
+ inputs:
133
+ PathtoPublish: $(Build.SourcesDirectory)/docker-compose.images.yml
134
+ ArtifactName: "release"
135
+ publishLocation: Container
136
+
137
+ # Logout from registry
138
+ - task: Docker@2
139
+ displayName: "Logout from Container Registry"
140
+ condition: always()
141
+ inputs:
142
+ command: logout
143
+ containerRegistry: $(DOCKER_REGISTRY)
144
+
145
+ - stage: Deploy
146
+ displayName: "Deployment"
147
+ dependsOn: Build
148
+ condition: succeeded()
149
+ jobs:
150
+ - job: DeployServices
151
+ displayName: "Deploy Services"
152
+ steps:
153
+ # Download artifacts
154
+ - task: DownloadPipelineArtifact@2
155
+ displayName: "Download Pipeline Artifacts"
156
+ inputs:
157
+ buildType: current
158
+ artifactName: release
159
+ targetPath: $(Build.SourcesDirectory)
160
+
161
+ # Lock services for deployment
162
+ - task: DockerCompose@1
163
+ displayName: "Lock Services for Deployment"
164
+ inputs:
165
+ action: Lock services
166
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
167
+ qualifyImageNames: true
168
+ containerregistrytype: Container Registry
169
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
170
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.yml
171
+ imageDigestComposeFile: $(Build.SourcesDirectory)/docker-compose.images.yml
172
+ outputDockerComposeFile: $(Build.SourcesDirectory)/docker-compose.release.yml
173
+
174
+ # Publish locked compose file
175
+ - task: PublishBuildArtifacts@1
176
+ displayName: "Publish Release Compose File"
177
+ inputs:
178
+ PathtoPublish: $(Build.SourcesDirectory)/docker-compose.release.yml
179
+ ArtifactName: release
180
+ publishLocation: Container
181
+
182
+ # Deploy services
183
+ - task: DockerCompose@1
184
+ displayName: "Deploy Services"
185
+ inputs:
186
+ action: Run services
187
+ buildImages: false
188
+ containerregistrytype: Container Registry
189
+ dockerRegistryEndpoint: $(DOCKER_REGISTRY)
190
+ dockerComposeFile: $(Build.SourcesDirectory)/docker-compose.release.yml
191
+ dockerHostEndpoint: docker-host-$(Build.SourceBranchName)
192
+ projectName: $(DOCKER_COMPOSE_PROJECT_NAME)
193
+ detached: true
194
+ workingDirectory: $(Build.SourcesDirectory)
docker-compose.override.yml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ services:
2
+ backend:
3
+ build:
4
+ context: .
5
+ dockerfile: Dockerfile
docker-compose.yml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ services:
2
+ backend:
3
+ image: sifars.azurecr.io/ipns-pocs/proposal-evaluation-backend:${BUILD_BUILDNUMBER:-latest}
4
+ ports:
5
+ - "7860:7860"
6
+ env_file:
7
+ - .env