forked from City-of-Helsinki/hauki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
151 lines (147 loc) · 5.1 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
# https://dev.to/n3wt0n/container-image-promotion-across-environments-yaml-1ca6
trigger:
batch: true
resources:
- repo: self
variables:
tag: '$(Build.SourceVersion)'
branch: '$(Build.SourceBranchName)'
ImageName: 'hauki'
azureSubscription: HKI-kanslia-standalone
appName: hauki
containerRegistry: registry.hub.docker.com
tag_postfix: 'apm'
${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
tags: |
$(tag)
$(tag)_$(tag_postfix)
$(branch)_latest
$(branch)_latest_$(tag_postfix)
${{ if eq(variables['Build.SourceBranchName'], 'master') }}:
tags: |
$(tag)
$(tag)_$(tag_postfix)
latest
latest_$(tag_postfix)
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build the images
jobs:
- job: Build
displayName: Build
steps:
- script: |
echo 'Running in workspace $(Pipeline.Workspace)'
echo 'Build.SourceBranchName: $(branch)'
echo 'Build.SourceVersion: $(tag)'
echo 'Build.SourcesDirectory: $(Build.SourcesDirectory)'
echo 'Build.ArtifactStagingDirectory: $(build.artifactstagingdirectory)'
echo 'Tags: $(tags)'
- task: DockerCompose@0
displayName: Build images
inputs:
dockerComposeCommand: build
dockerComposeFile: '$(Build.SourcesDirectory)/docker-compose.yml'
- task: Docker@2
displayName: Build APM enhanced image
inputs:
repository: '$(ImageName)'
command: build
tags: 'apm'
Dockerfile: deploy/elastic_apm_injection/Dockerfile
arguments: --build-arg BASE_IMAGE=$(ImageName)
- script: |
docker tag hauki_dev:latest hauki:dev_latest
docker rmi hauki_dev
displayName:
- task: Docker@2
displayName: Save hauki image repository to TAR
inputs:
repository: '$(ImageName)'
command: save
arguments: '--output $(build.artifactstagingdirectory)/$(ImageName).image.tar $(ImageName)'
addPipelineData: false
- publish: $(build.artifactstagingdirectory)
artifact: ContainerImages
- stage: Test
displayName: Test
jobs:
- job: Test
displayName: Test the dev image
steps:
- task: DownloadPipelineArtifact@2
displayName: Download hauki repository TAR
inputs:
artifact: ContainerImages
- task: Docker@2
displayName: Load hauki repository from TAR
inputs:
command: load
arguments: '--input $(Pipeline.Workspace)/$(ImageName).image.tar'
- script: |
docker tag hauki:dev_latest hauki_dev:latest
displayName: Add hauki_dev name back to image for docker-compose
- task: DockerCompose@0
displayName: Run tests
inputs:
dockerComposeCommand: run dev test
dockerComposeFile: '$(Build.SourcesDirectory)/docker-compose.yml'
- stage: Push
displayName: Push
jobs:
- job: Push
displayName: Push deploy image to registry
steps:
- task: DownloadPipelineArtifact@2
displayName: Download image repo TAR
inputs:
artifact: ContainerImages
- task: Docker@2
displayName: Load image repository from TAR
inputs:
command: load
arguments: '--input $(Pipeline.Workspace)/$(ImageName).image.tar'
- script: |
docker tag $(ImageName):latest helsinki/$(ImageName):$(tag)
docker tag $(ImageName):apm helsinki/$(ImageName):$(tag)_$(tag_postfix)
displayName: Retag image for Helsinki repo with commit hash
- script: |
docker tag $(ImageName):latest helsinki/$(ImageName):latest
docker tag $(ImageName):apm helsinki/$(ImageName):latest_$(tag_postfix)
displayName: Retag image for Helsinki repo with latest
condition: eq(variables['branch'], 'master')
- script: |
docker tag $(ImageName):latest helsinki/$(ImageName):$(branch)_latest
docker tag $(ImageName):apm helsinki/$(ImageName):$(branch)_latest_$(tag_postfix)
displayName: Retag image for Helsinki repo with branch name
condition: ne(variables['branch'], 'master')
- task: Docker@2
displayName: Push image to Docker hub
inputs:
containerRegistry: Docker hub upload-hauki
repository: helsinki/$(ImageName)
command: push
tags: $(tags)
- stage: Deploy
displayName: Deploy to Openshift
jobs:
- job: Update
displayName: Update OC Imagestream
steps:
- task: oc-cmd@2
displayName: Add OC tag to PR image
inputs:
openshiftService: Azure OpenShift-hauki
cmd: 'tag docker.io/helsinki/hauki:$(tag)_$(tag_postfix) hauki-backend:HAUKI-91-models_latest'
condition: eq(variables['branch'], 'HAUKI-91-models')
- task: oc-cmd@2
displayName: Add OC tag to latest image
inputs:
openshiftService: Azure OpenShift-hauki
cmd: 'tag docker.io/helsinki/hauki:$(tag)_$(tag_postfix) hauki-backend:latest'
condition: eq(variables['branch'], 'master')