-
Notifications
You must be signed in to change notification settings - Fork 4
/
azure-pipelines.yml
175 lines (146 loc) · 6.97 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
pool:
vmImage: ubuntu-18.04
trigger:
branches:
include:
- '*'
variables:
imageTag: v$(Build.BuildId)
# define four more variables imageName, DOCKER_HUB_REPO in the build pipeline in UI
CUCUMBER_PROFILE: continuous_integration
SELENIUM_PROFILE: selenium
APP_URL: http://school-experience:3000
jobs:
- job: BuildAndTesting
steps:
- script: echo $(Build.Reason)
displayName: Build trigger
- script: |
DEPENDENCY_TAG=`cat Dockerfile .dockerignore Gemfile Gemfile.lock package.json yarn.lock | shasum | cut -d ' ' -f 1`
echo "##vso[task.setvariable variable=buildCacheTag]${DEPENDENCY_TAG}"
displayName: Calculate build cache tag
- script: echo "dependencies tag is $(buildCacheTag)"
displayName: Show build cache tag
- script: |
docker pull $(DOCKER_HUB_REPO):$(buildCacheTag) || true
docker build -f Dockerfile --cache-from=$(DOCKER_HUB_REPO):$(buildCacheTag) -t $(DOCKER_HUB_REPO):$(imageTag) .
displayName: Build Docker Image using Cache
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master')
- script: docker build -f Dockerfile -t $(DOCKER_HUB_REPO):$(imageTag) .
displayName: Build Docker Image without Cache
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
- script: docker run --rm $(DOCKER_HUB_REPO):$(imageTag) brakeman --no-pager
displayName: Run the Brakeman security scan
- script: docker run --rm $(DOCKER_HUB_REPO):$(imageTag) rubocop app config lib features spec
displayName: Run the GovUK Lint check
- script: docker tag $(DOCKER_HUB_REPO):$(imageTag) $(DOCKER_HUB_REPO):$(buildCacheTag)
displayName: Tag build cache image
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/development')))
- task: Docker@2
displayName: 'Upload build cache image to DockerHub'
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/development')))
inputs:
containerRegistry: $(DOCKER_HUB_CONNECTION_NAME)
repository: $(DOCKER_HUB_REPO)
command: push
tags: $(buildCacheTag)
- script: docker tag $(DOCKER_HUB_REPO):$(imageTag) school-experience:latest
displayName: Tag built image as latest
- script: |
docker compose up -d
WAIT_COUNT=0
until docker compose ps | grep -m 1 "db-tasks" | grep -m 1 "Exit 0" || [ $WAIT_COUNT -eq 12 ]; do echo "WAIT COUNT $(( WAIT_COUNT++ ))" && sleep 5 ; done
displayName: bring up postgres, redis and create database (for the web app) and spin up application
- script: docker compose run --rm db-tasks rspec --format progress --format RspecJunitFormatter --out /ci_build/rspec_results.xml
displayName: Run the Specs
- task: PublishTestResults@2
# condition: failed()
displayName: Upload RSpec results
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: rspec_results.xml
testRunTitle: RSpec results
- script: docker compose run --rm -e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true db-tasks cucumber --profile=$(CUCUMBER_PROFILE) --format junit --out /ci_build/junit
displayName: Run the Cucumber features
- task: PublishTestResults@2
# condition: failed()
displayName: Upload Cucumber results
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'junit/TEST-*.xml'
testRunTitle: Cucumber results
- script: |
docker compose -f docker-compose.yml -f docker-compose-chrome.yml up -d
WAIT_COUNT=0
until docker compose ps | grep -m 1 "db-tasks" | grep -m 1 "Exit 0" || [ $WAIT_COUNT -eq 12 ]; do echo "WAIT COUNT $(( WAIT_COUNT++ ))" && sleep 5 ; done
docker compose -f docker-compose.yml -f docker-compose-chrome.yml run --rm \
-e RAILS_ENV=test \
-e SELENIUM_HUB_HOSTNAME=selenium-chrome \
-e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true \
-e APP_URL \
-e CUC_DRIVER=chrome \
--no-deps \
school-experience cucumber -t @javascript --profile=$(SELENIUM_PROFILE) --format junit --out /ci_build/junit
displayName: Run Javascript Cucumber Tests with Chrome
- task: PublishTestResults@2
displayName: Upload Javascript Cucumber results
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'junit/TEST-*.xml'
testRunTitle: Javascript Cucumber results
- script: |
docker tag $(DOCKER_HUB_REPO):$(imageTag) $(DOCKER_HUB_REPO):latest
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: 'Tag Docker image (built from master)'
- script: |
docker tag $(DOCKER_HUB_REPO):$(imageTag) $(DOCKER_HUB_REPO):$(imageTag)-debug
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/debug'))
displayName: 'Tag Docker image (built from debug)'
- script: |
docker tag $(DOCKER_HUB_REPO):$(imageTag) $(DOCKER_HUB_REPO):$(imageTag)-review
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: 'Tag Docker image (built from Review)'
- task: Docker@2
displayName: 'Push tagged image to DockerHub'
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/debug')))
inputs:
containerRegistry: $(DOCKER_HUB_CONNECTION_NAME)
repository: $(DOCKER_HUB_REPO)
command: push
tags: $(imageTag)
- task: Docker@2
displayName: 'Push :latest to DockerHub'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
containerRegistry: $(DOCKER_HUB_CONNECTION_NAME)
repository: $(DOCKER_HUB_REPO)
command: push
tags: latest
- task: Docker@2
displayName: 'Push :Review to DockerHub'
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
containerRegistry: $(DOCKER_HUB_CONNECTION_NAME)
repository: $(DOCKER_HUB_REPO)
command: push
tags: $(imageTag)-review
- task: Docker@2
displayName: 'Push :debug to DockerHub'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/debug'))
inputs:
containerRegistry: $(DOCKER_HUB_CONNECTION_NAME)
repository: $(DOCKER_HUB_REPO)
command: push
tags: $(imageTag)-debug
- script: |
echo '{' > ${PIPELINE_WORKSPACE}/build_info.json
echo '"PullRequestId" :' "\"${SYSTEM_PULLREQUEST_PULLREQUESTID}\"," >> ${PIPELINE_WORKSPACE}/build_info.json
echo '"PullRequestNumber":' "\"${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}\" " >> ${PIPELINE_WORKSPACE}/build_info.json
echo '}' >> ${PIPELINE_WORKSPACE}/build_info.json
displayName: 'Produce Build Information File'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)/build_info.json'
artifact: 'build_info'
publishLocation: 'pipeline'
displayName: 'Publish Build Information Artifact'